[Include] Multi-language system
#1

What is this?
This is a simple multi-language system which is using Incognito's GVar plugin feature to store language keys and texts for different languages.


Credits:
- Incognito for GVar plugin,
- Whoever created StripNewLine (DracoBlue?) & SplitChar functions.


How to install?
It's easy and simple - download and put the language.inc into the \pawno\include\ folder and do the same thing with the gvar.inc file.
Open your script and put this:
pawn Code:
#include <gvar>
#include <language>
right after the
pawn Code:
#include <a_samp>
Download the correct version of GVar plugin and put it into the \plugins\ folder, and don't forget to add the name of the plugin into the server.cfg in the line plugins.
Load the languages in the OnGameModeInit callback.
Example:
pawn Code:
LoadLanguage("English");
LoadLanguage("Croatian");
LoadLanguage("Slovenian");
Create the folder languages in the \scriptfiles\ folder and put your language files there (example: english.lng).
Example if you want to use English and Croatian language on your server:
English.lng file:
pawn Code:
LANG_KEY_1=(wlc-msg1) Welcome to my server player!
LANG_KEY_2=(frm-wlc-msg2) Welcome to my server, %s!
LANGUAGE_KEY_LONG_123456=(msg) Hello world [1]!
LANG_KEY_TOO_LONG_FOR_123444444444444444444444=(msg) Hello world [2]!
LANG_KEY_3=(max-IO) 0123456789 abcdef 01010101 __________ ---------- qwertzuiopasdfghjklyxcvbnm 0123456789 abcdef 01010101 .............E.
LANG_KEY_4=(exc-max-IO) 0123456789 abcdef 01010101 __________ ---------- qwertzuiopasdfghjklyxcvbnm 0123456789 abcdef 01010101 ..........E.
Croatian.lng file:
pawn Code:
LANG_KEY_1=(wlc-msg1) Dobrodoљao na moj server igra&#269;u!
LANG_KEY_2=(frm-wlc-msg2) Dobrodoљao na moj server, %s!
LANGUAGE_KEY_LONG_123456=(msg) Pozdrav sviete [1]!
LANG_KEY_TOO_LONG_FOR_123444444444444444444444=(msg) Pozdrav sviete [2]!
LANG_KEY_3=(max-IO) 0123456789 abcdef 01010101 __________ ---------- qwertzuiopasdfghjklyxcvbnm 0123456789 abcdef 01010101 .............E.
LANG_KEY_4=(exc-max-IO) 0123456789 abcdef 01010101 __________ ---------- qwertzuiopasdfghjklyxcvbnm 0123456789 abcdef 01010101 ..........E.
When creating new language and translating the old English file to your new language, make sure you won't translate the language key (example: LANG_KEY_1).


Functions:
LoadLanguage | LoadLanguageTexts
Loads the language keys and texts from language file if exists (.lng file)
@langname[] = Language name.
returns - doesn't return a specific value.
Example:
pawn Code:
LoadLanguage("English");
SetPlayerLanguage
Set the language for the player
@playerid = The ID of the player.
@langname[] = Language name.
returns - doesn't return a specific value.
Example:
pawn Code:
SetPlayerLanguage(playerid, "English");
You should set the language for the player before you send him any multi-language text or use GetPlayerLanguage function.

GetPlayerLanguage
Get the language of player
@playerid = The ID of the player.
returns - language name.
Example:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/mylang", true))
    {
        new
                string[42];
        format(string, 42, "YOUR-LANGUAGE: %s.", GetPlayerLanguage(playerid));
        SendClientMessage(playerid, 0xFFFFFFFF, string);
        return true;
    }
    return false;
}
SendLanguageMessage
Send the multi-language message to player
@playerid = The ID of the player.
@color = Color of text message.
@langkey[] = Language key (stored in language_name.lng file) which holds the information of language text.
returns - doesn't return a specific value.
Example:
pawn Code:
SendLanguageMessage(playerid, 0xFFFFFFFF, "WLC_MSG_1");

/* in English.lng file: */
WLC_MSG_1=(wlc-msg1) Welcome to my server player!
SendLanguageMessageEx
Send the formatted multi-language message to player
@playerid = The ID of the player.
@color = Color of text message.
@langkey[] = Language key (stored in language_name.lng file) which holds the information of language text.
@... = formatted arguments.
returns - doesn't return a specific value.
Example:
pawn Code:
new
        playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
SendLanguageMessageEx(playerid, 0xFFFFFFFF, "WLC_MSG_2", playerName);

/* in English.lng file: */
WLC_MSG_2=(frm-wlc-msg2) Welcome to my server, %s!
GetLanguageKey
Get the language text from language key
@langname[] = Language name.
@langkey[] = Language key (stored in language_name.lng file) which holds the information of language text.
returns - language text of the key.
Example:
pawn Code:
SendClientMessage(playerid, 0xFFFFFFFF, GetLanguageKey(GetPlayerLanguage(playerid), "WLC_MSG_1"));

/* in English.lng file: */
WLC_MSG_1=(wlc-msg1) Welcome to my server player!

/* will print on player's screen (if the player is using the English language): */
(wlc-msg1) Welcome to my server player!

Defines:
pawn Code:
#define MAX_LANGUAGES (3)
MAX_LANGUAGES - The maximum amount of languages allowed for script to load on the server.


Download:
http://www.solidfiles.com/d/8711071da4


Other:
- Don't use the language name which has length of name bigger than 24 characters, the same goes for the language keys. Don't use more than 128 characters for language texts.
- Don't forget to set the player's language to English (or any other loaded language) before you send him any multi-language text or use GetPlayerLanguage function.
- Filename extension of language file should be .lng.
Reply
#2

Good work man!
Reply
#3

Thank you. It's a great job. But i have a problem with new lines. When I use \n for new line (e.g. for 3d labels or dialogs) it didn't break the line. How can i fix this?
Reply
#4

Hey, how I can use colors like COLOR_BLUE in here?
Reply
#5

Very good job!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)