SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 27/11/2016, 11:44 AM   #1
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,447
Reputation: 356
Default zlang - GVar per player lang system

zlang

About
GVar per player lang system.

Requirements
- GVar plugin
- foreach - not necessary but recommended

Libraries compatible with zlang
- mdialog - new look for Dialog_Open, Dialog_Message and Dialog_MessageEx functions.

Defines
List of all defines here (no table tag on this forum): https://github.com/Open-GTO/zlang#defines

Functions
Add language
PHP Code:
Lang:Lang_Add(code[], name[]) 
Remove language
PHP Code:
Lang_Remove(Lang:lang
Load language file
PHP Code:
Lang_LoadFile(Lang:langfilename[]) 
Unload language file
PHP Code:
Lang_UnloadFile(Lang:langfilename[] = ""fid INVALID_LANG_FILE_ID
Reload all language files
PHP Code:
Lang_Reload(Lang:lang
Get language id by *code* or *name*
PHP Code:
Lang:Lang_Get(code[] = ""name[] = ""
Set language name
PHP Code:
Lang_SetName(Lang:langname[]) 
Get language name
PHP Code:
Lang_GetName(Lang:langname[], const size sizeof(name)) 
Get language name and return it
PHP Code:
Lang_ReturnName(Lang:lang
Set language code
PHP Code:
Lang_SetCode(Lang:langcode[]) 
Get language code
PHP Code:
Lang_GetCode(Lang:langcode[], const size sizeof(code)) 
Get language code and return it
PHP Code:
Lang_ReturnCode(Lang:lang
Get language codes string
PHP Code:
Lang_GetCodes(result[], const size sizeof(result), const separator '/', const bool:isuppercase false
Get language codes string and return it
PHP Code:
Lang_ReturnCodes(const separator '/', const bool:isuppercase false
Check language on valid
PHP Code:
Lang_IsValid(Lang:lang
Get languages count
PHP Code:
Lang_GetCount() 
Set player language
PHP Code:
Lang_SetPlayerLang(playeridLang:lang
Get player language
PHP Code:
Lang:Lang_GetPlayerLang(playerid
Set player language by code
PHP Code:
Lang:Lang_SetPlayerLangByCode(playeridcode[]) 
Set player language by name
PHP Code:
Lang:Lang_SetPlayerLangByName(playeridname[]) 
Set default server language
PHP Code:
Lang_SetDefaultLang(Lang:lang
Get default server language
PHP Code:
Lang_GetDefaultLang() 
Get language text
PHP Code:
Lang_GetText(Lang:lang, var[], text[], const size sizeof(text), {Float_}:...) 
Get player language text
PHP Code:
Lang_GetPlayerText(playerid, var[], text[], const size sizeof(text), {Float_}:...) 
Get default language text
PHP Code:
Lang_GetDefaultText(var[], text[], const size sizeof(text), {Float_}:...) 
Remove language text
PHP Code:
Lang_RemoveText(Lang:lang, var[]) 
Is language text exists
PHP Code:
Lang_IsTextExists(Lang:lang, var[]) 
Language printf function with default language
PHP Code:
Lang_printf(var[], {Float_}:...) 
Language printf function with specific language
PHP Code:
Lang_printfex(Lang:lang, var[], {Float_}:...) 
Language print function with default language
PHP Code:
Lang_print(var[], {Float_}:...) 
Language print function with specific language
PHP Code:
Lang_printex(Lang:lang, var[]) 
Send language text to player
PHP Code:
Lang_SendText(playerid, var[], {Float_}:...) 
Send language text to all players
PHP Code:
Lang_SendTextToAll(var[], {Float_}:...) 
Send language text to all players in array
PHP Code:
Lang_SendTextToPlayers(players[], var[], {Float_}:...) 
Show language dialog to player
PHP Code:
Lang_ShowDialog(playeriddialogidstylevar_caption[], var_info[], var_button1[], var_button2[], {Float_}:...) 
Show language game text to player
PHP Code:
Lang_GameText(playeridtimestyle, var[], {Float_}:...) 
Show language game text to all players
PHP Code:
Lang_GameTextForAll(timestyle, var[], {Float_}:...) 
Create player TextDraw with language var
PHP Code:
Lang_CreatePlayerTextDraw(playeridFloat:xFloat:y, var[], {Float_}:...) 
Sets the language text to the player TextDraw
PHP Code:
Lang_PlayerTextDrawSetString(playeridPlayerText:text, var[], {Float_}:...) 
Language file format
Language file format is a standard INI file format (without sections). It supports a variety of special characters, such as \n, \t, \%, \s, \\, \<value>, \x<hex>.

Variables
You can use variables in your text files. This supports any nesting level.
PHP Code:
HELLO_MSG Hello
COLOR_RED 
= {FF0000}
COLOR_GREEN = {00FF00}
COLOR_WHITE = {FFFFFF}
NAME_ONE = \v(COLOR_RED)Alex\v(COLOR_WHITE)
NAME_TWO = \v(COLOR_GREEN)Peter\v(COLOR_WHITE)
MESSAGE_HELLO = \v(COLOR_WHITE)\v(HELLO_MSG) \v(NAME_ONE) and \v(NAME_TWO
Example
PHP Code:
#include <a_samp>
#include <gvar>
#include <zlang>

enum e_LANG_INFO {
    
Lang:e_LANG_EN,
    
Lang:e_LANG_RU,
}

static
    
gLang[e_LANG_INFO];

main() {}

public 
OnGameModeInit()
{
    
// load languages
    
gLang[e_LANG_RU] = Lang_Add("ru""Russian");
    
gLang[e_LANG_EN] = Lang_Add("en""English");

    
Lang_LoadFile(gLang[e_LANG_RU], "ru.ini");
    
Lang_LoadFile(gLang[e_LANG_EN], "en.ini");

    
// set english as the default language
    
Lang_SetDefaultLang(gLang[e_LANG_EN]);
    return 
1;
}

public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp(cmdtext"/ru"true3) == 0) {
        
Lang_SetPlayerLang(playeridgLang[e_LANG_RU]);
        
Lang_SendText(playerid"LANGUAGE_CHANGED");
        return 
1;
    }

    if (
strcmp(cmdtext"/en"true3) == 0) {
        
Lang_SetPlayerLang(playeridgLang[e_LANG_EN]);
        
Lang_SendText(playerid"LANGUAGE_CHANGED");
        return 
1;
    }

    if (
strcmp(cmdtext"/help"true5) == 0) {
        
Lang_SendText(playerid"HELLO_MSG");
        
Lang_SendText(playerid"COMMANDS_LIST");
        return 
1;
    }

    if (
strcmp(cmdtext"/help330"true5) == 0) {
        
Lang_SendText(playerid"Hello, World!");
        
Lang_SendText(playerid"Commands: /help, /en, /ru");
        return 
1;
    }

    return 
0;

scriptfiles/en.ini:
PHP Code:
COLOR_GRAY = {CCCCCC}
LANGUAGE_CHANGED = \v(COLOR_GRAY)Now you are using english language.
HELLO_MSG Hello, {00FF00}World!
COMMANDS_LIST Commands: /help, /en, /ru 
scriptfiles/ru.ini:
PHP Code:
COLOR_GRAY = {CCCCCC}
LANGUAGE_CHANGED = \v(COLOR_GRAY)Теперь вы используете русский язык.
HELLO_MSG Привет, {00FF00}Мир!
COMMANDS_LIST Команды: /help, /en, /ru
# in zlang 3.3.0
HelloWorld! = \v(HELLO_MSG)
Commands: /help, /en, /ru = \v(COMMANDS_LIST
Download
- GitHub download page: https://github.com/Open-GTO/zlang/releases

Last edited by ZiGGi; 25/11/2017 at 03:01 PM.
ZiGGi is offline   Reply With Quote
Old 25/11/2017, 02:54 PM   #2
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,447
Reputation: 356
Default Re: zlang - GVar per player lang system

zlang v3.3.0 is available!

Now you can use variables in text files and using strings like a keys!

PHP Code:
if (strcmp(cmdtext"/help330"true5) == 0) {
    
Lang_SendText(playerid"Hello, World!");
    
Lang_SendText(playerid"Commands: /help, /en, /ru");
    return 
1;

PHP Code:
COLOR_GRAY = {CCCCCC}
LANGUAGE_CHANGED = \v(COLOR_GRAY)Теперь вы используете русский язык.
HELLO_MSG Привет, {00FF00}Мир!
COMMANDS_LIST Команды: /help, /en, /ru
# in zlang 3.3.0
HelloWorld! = \v(HELLO_MSG)
Commands: /help, /en, /ru = \v(COMMANDS_LIST
ZiGGi is offline   Reply With Quote
Old 25/11/2017, 02:56 PM   #3
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,337
Reputation: 824
Default Re: zlang - GVar per player lang system

Woah, weird that this include went unnoticed.

Very nice tho.
Kaperstone is offline   Reply With Quote
Old 25/11/2017, 02:56 PM   #4
ToiletDuck
Huge Clucker
 
ToiletDuck's Avatar
 
Join Date: Apr 2012
Location: Philippines, Lucena City
Posts: 436
Reputation: 43
Default Re: zlang - GVar per player lang system

Woow Great, Is this include will automatically converts or translate? I haven't read the whole thread yet lol.

EDIT: oh it's manual, Thanks for this I might use this
__________________

ToiletDuck is offline   Reply With Quote
Old 15/01/2018, 07:13 PM   #5
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,337
Reputation: 824
Default Re: zlang - GVar per player lang system

GVar is slow compared to regular variables, why use it?
Kaperstone is offline   Reply With Quote
Old 16/01/2018, 05:26 AM   #6
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,447
Reputation: 356
Default Re: zlang - GVar per player lang system

Quote:
Originally Posted by Kaperstone View Post
GVar is slow compared to regular variables, why use it?
Nope. Any existed algorithm for search by string keys on Pawn is slower than existed in GVar. I was made some tests compared to y_languages and GVar's is much faster.
ZiGGi is offline   Reply With Quote
Old 16/01/2018, 06:29 AM   #7
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,337
Reputation: 824
Default Re: zlang - GVar per player lang system

Quote:
Originally Posted by ZiGGi View Post
Nope. Any existed algorithm for search by string keys on Pawn is slower than existed in GVar. I was made some tests compared to y_languages and GVar's is much faster.
Maybe faster than y_lang, that'd be even great if you could add them to the thread to see some comparison (if possible with source), but regular variables definitely are faster than gvar.
http://forum.sa-mp.com/showpost.php?...3&postcount=11
http://forum.sa-mp.com/showpost.php?...2&postcount=14

I'd say language is definitely a time critical because text is used everywhere.
Kaperstone is offline   Reply With Quote
Old 16/01/2018, 06:53 AM   #8
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,447
Reputation: 356
Default Re: zlang - GVar per player lang system

Quote:
Originally Posted by Kaperstone View Post
Maybe faster than y_lang, that'd be even great if you could add them to the thread to see some comparison (if possible with source), but regular variables definitely are faster than gvar.
http://forum.sa-mp.com/showpost.php?...3&postcount=11
http://forum.sa-mp.com/showpost.php?...2&postcount=14

I'd say language is definitely a time critical because text is used everywhere.
I know what they are faster, but they didn't provide similar functionality, like string keys. Languages can be realized with regular arrays, but code with arrays will be not too clear and functional. Also if someone wan to get maximum performance, tthey shouldn't use even arrays just pure strings with tons of if's.

Upd: i will add some tests with other language libraries later
ZiGGi is offline   Reply With Quote
Old 16/01/2018, 07:22 AM   #9
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,337
Reputation: 824
Default Re: zlang - GVar per player lang system

Quote:
Originally Posted by ZiGGi View Post
Upd: i will add some tests with other language libraries later
Great, would love to see that.


By the way, I wanted to know whether I'll need to use Russifikatsia of the compiler to send/display text in Russian with Cyrillic alphabet?
Kaperstone is offline   Reply With Quote
Old 16/01/2018, 07:37 AM   #10
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,447
Reputation: 356
Default Re: zlang - GVar per player lang system

Quote:
Originally Posted by Kaperstone View Post
Great, would love to see that.


By the way, I wanted to know whether I'll need to use Russifikatsia of the compiler to send/display text in Russian with Cyrillic alphabet?
Nope, you can use default or zeex compiler. If you want to see the text in the game, you should run the game with Russian windows-1251 encoding (default in Russian Windows), everything as with default text.
ZiGGi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NEED HELP ASAP with C Lang TrinityGamingRoleplay Scripting Help 0 26/06/2014 05:29 PM
[FilterScript] My first FS - Bad Lang FS Frede Filterscripts 11 28/12/2012 08:19 AM
Need help with Lang system Daniel_Truk Help Archive 5 30/08/2009 12:57 AM


All times are GMT. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.