[Include] zlang - GVar per player lang system
#1

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 код:
Lang:Lang_Add(code[], name[]) 
Remove language
PHP код:
Lang_Remove(Lang:lang
Load language file
PHP код:
Lang_LoadFile(Lang:langfilename[]) 
Unload language file
PHP код:
Lang_UnloadFile(Lang:langfilename[] = ""fid INVALID_LANG_FILE_ID
Reload all language files
PHP код:
Lang_Reload(Lang:lang
Get language id by *code* or *name*
PHP код:
Lang:Lang_Get(code[] = ""name[] = ""
Set language name
PHP код:
Lang_SetName(Lang:langname[]) 
Get language name
PHP код:
Lang_GetName(Lang:langname[], const size sizeof(name)) 
Get language name and return it
PHP код:
Lang_ReturnName(Lang:lang
Set language code
PHP код:
Lang_SetCode(Lang:langcode[]) 
Get language code
PHP код:
Lang_GetCode(Lang:langcode[], const size sizeof(code)) 
Get language code and return it
PHP код:
Lang_ReturnCode(Lang:lang
Get language codes string
PHP код:
Lang_GetCodes(result[], const size sizeof(result), const separator '/', const bool:isuppercase false
Get language codes string and return it
PHP код:
Lang_ReturnCodes(const separator '/', const bool:isuppercase false
Check language on valid
PHP код:
Lang_IsValid(Lang:lang
Get languages count
PHP код:
Lang_GetCount() 
Set player language
PHP код:
Lang_SetPlayerLang(playeridLang:lang
Get player language
PHP код:
Lang:Lang_GetPlayerLang(playerid
Set player language by code
PHP код:
Lang:Lang_SetPlayerLangByCode(playeridcode[]) 
Set player language by name
PHP код:
Lang:Lang_SetPlayerLangByName(playeridname[]) 
Set default server language
PHP код:
Lang_SetDefaultLang(Lang:lang
Get default server language
PHP код:
Lang_GetDefaultLang() 
Get language text
PHP код:
Lang_GetText(Lang:lang, var[], text[], const size sizeof(text), {Float_}:...) 
Get player language text
PHP код:
Lang_GetPlayerText(playerid, var[], text[], const size sizeof(text), {Float_}:...) 
Get default language text
PHP код:
Lang_GetDefaultText(var[], text[], const size sizeof(text), {Float_}:...) 
Remove language text
PHP код:
Lang_RemoveText(Lang:lang, var[]) 
Is language text exists
PHP код:
Lang_IsTextExists(Lang:lang, var[]) 
Language printf function with default language
PHP код:
Lang_printf(var[], {Float_}:...) 
Language printf function with specific language
PHP код:
Lang_printfex(Lang:lang, var[], {Float_}:...) 
Language print function with default language
PHP код:
Lang_print(var[], {Float_}:...) 
Language print function with specific language
PHP код:
Lang_printex(Lang:lang, var[]) 
Send language text to player
PHP код:
Lang_SendText(playerid, var[], {Float_}:...) 
Send language text to all players
PHP код:
Lang_SendTextToAll(var[], {Float_}:...) 
Send language text to all players in array
PHP код:
Lang_SendTextToPlayers(players[], var[], {Float_}:...) 
Show language dialog to player
PHP код:
Lang_ShowDialog(playeriddialogidstylevar_caption[], var_info[], var_button1[], var_button2[], {Float_}:...) 
Show language game text to player
PHP код:
Lang_GameText(playeridtimestyle, var[], {Float_}:...) 
Show language game text to all players
PHP код:
Lang_GameTextForAll(timestyle, var[], {Float_}:...) 
Create player TextDraw with language var
PHP код:
Lang_CreatePlayerTextDraw(playeridFloat:xFloat:y, var[], {Float_}:...) 
Sets the language text to the player TextDraw
PHP код:
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 код:
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 код:
#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 код:
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 код:
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
Reply
#2

zlang v3.3.0 is available!

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

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

PHP код:
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
Reply
#3

Woah, weird that this include went unnoticed.

Very nice tho.
Reply
#4

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
Reply
#5

GVar is slow compared to regular variables, why use it?
Reply
#6

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
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.
Reply
#7

Quote:
Originally Posted by ZiGGi
Посмотреть сообщение
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.
Reply
#8

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
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
Reply
#9

Quote:
Originally Posted by ZiGGi
Посмотреть сообщение
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?
Reply
#10

Nice. I did multilang system in my server in same way, funniest thing was export already existed messages from mode
Reply
#11

Sorry for bump,

is this possible with formatex.inc ?
lets say i want to make message with %p format
Reply
#12

Quote:
Originally Posted by Dice_
Посмотреть сообщение
Sorry for bump,

is this possible with formatex.inc ?
lets say i want to make message with %p format
No, for now zlang is not working with formatex and I don't know how to do it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)