SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/07/2012, 11:11 PM   #1
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 6,340
Reputation: 365
Default [INC] Multi-language system

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.

Last edited by Correlli; 14/07/2013 at 08:15 PM.
Correlli is offline   Reply With Quote
Old 27/07/2012, 11:17 PM   #2
Sanady
High-roller
 
Sanady's Avatar
 
Join Date: May 2012
Location: Los Santos
Posts: 1,170
Reputation: 132
Default Re: Multi-language system

Good work man!
__________________

Sanady is offline   Reply With Quote
Old 22/03/2017, 05:43 PM   #3
Novacaine
Little Clucker
 
Join Date: Aug 2016
Posts: 42
Reputation: 0
Default Re: Multi-language system

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?
Novacaine is offline   Reply With Quote
Old 25/11/2018, 06:43 AM   #4
Wajttachu
Little Clucker
 
Join Date: Oct 2018
Location: Belgrade, Serbia
Posts: 20
Reputation: 0
Default Re: Multi-language system

Hey, how I can use colors like COLOR_BLUE in here?
Wajttachu is offline   Reply With Quote
Old 25/11/2018, 01:24 PM   #5
DIRTYBYT3
Big Clucker
 
DIRTYBYT3's Avatar
 
Join Date: Sep 2018
Location: DYRTYBYT3#2856
Posts: 87
Reputation: 11
Default Re: Multi-language system

Very good job!
__________________
DIRTYBYT3 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
[Tutorial] Multi Language System (Very short and easy) Abruu Tutorials 11 16/10/2011 08:02 AM
XML multi language armyoftwo Help Archive 0 26/12/2010 12:33 PM
Best multi-language inc? [Ha]Lommo Help Archive 1 13/09/2010 03:28 PM
San Fierro PR multi language system Tony_Arracardo Help Archive 9 31/07/2009 03:02 PM


All times are GMT. The time now is 10:38 AM.


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