27.07.2012, 23:11
(
Last edited by Correlli; 14/07/2013 at 08:15 PM.
)
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:
right after the
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:
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:
Croatian.lng file:
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:
SetPlayerLanguage
Set the language for the player
@playerid = The ID of the player.
@langname[] = Language name.
returns - doesn't return a specific value.
Example:
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:
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:
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:
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:
Defines:
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.
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>
pawn Code:
#include <a_samp>
Load the languages in the OnGameModeInit callback.
Example:
pawn Code:
LoadLanguage("English");
LoadLanguage("Croatian");
LoadLanguage("Slovenian");
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.
pawn Code:
LANG_KEY_1=(wlc-msg1) Dobrodoљao na moj server igrač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.
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");
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");
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;
}
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!
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!
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)
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.