[Include] Multi-language system (MySQL version)
#1

What is this?
This is a multi-language script, which allows you to easily add languages for your players to use on the server. I know this is the Include sub-forum, but this script isn't really an include. This script is given as a Gamemode example. If you're interested in the INC script, which is based on the file writing/reading system, then look here. The script went through the basic testing, everything should work fine. If you notice any bug, please report.



Credits:
- Incognito for GVar plugin,
- BlueG/GStylezzz for MySQL plugin,
- ****** for foreach/iterator.



MySQL table and message adding:
You'll need this MySQL table in your database:
Код:
CREATE TABLE smf_serverlanguages (
  id int(5) unsigned NOT NULL auto_increment,
  lang_name varchar(24) NOT NULL default '',
  lang_key varchar(24) NOT NULL default '',
  content varchar(128) NOT NULL default '',
  comment varchar(64) NOT NULL default '',
  PRIMARY KEY (id)
) ENGINE=MyISAM;
Change the name of the table as you need. Once you create the table, you can create keys for language messages through the phpMyAdmin option or directly in the script.

MySQL table (phpMyAdmin):


Example in script:
Код:
#define LANG_ENGLISH		("English")	// English.
#define LANG_CROATIAN		("Hrvatski")	// Croatian.
Код:
// English.
AddLanguageKey(LANG_ENGLISH,	"WLCM_PLYR",	"Welcome to the server %s!",	"First message when player connects to the server.");
AddLanguageKey(LANG_ENGLISH,	"WLCM_PLYR_2",	"Have fun on the server!",	"Second message when player connects to the server.");
AddLanguageKey(LANG_ENGLISH,	"FLOAT_MSG",	"Float number: %0.2f",		"Just a random float message. :)");
Код:
// Croatian.
AddLanguageKey(LANG_CROATIAN,	"WLCM_PLYR",	"Dobrodosao na server %s!",	"Prva poruka kad se igrac poveze na server.");
AddLanguageKey(LANG_CROATIAN,	"WLCM_PLYR_2",	"Uzivaj u igri!",		"Druga poruka kad se igrac poveze na server.");
AddLanguageKey(LANG_CROATIAN,	"FLOAT_MSG",	"Float broj: %0.2f",		"Samo nasumicna float poruka. :)");

Functions:
LoadLanguage, LoadLanguageTexts
With this function you can load keys and language messages.
@langname[] = Language name.
returns - true (1) if the function is executed correctly and false (0) if not (the name of the language is too long).
Example:
pawn Код:
LoadLanguage("English");
AddLanguageKey
With this function you can add language messages in the script.
@langname[] = Language name.
@langkey[] = Language key which holds the information about the language message.
@content[] = Language message.
@comment[] = Key comment.
returns - true (1) if the function is executed correctly, -1 if the name of the language is too long, -2 if the name of the language key is too long, -3 if the language message is too long and -4 if the key comment is too long.
Example:
pawn Код:
AddLanguageKey(LANG_ENGLISH, "WLCM_PLYR", "Welcome to the server %s!", "First message when player connects to the server.");
Код:
switch(AddLanguageKey(string[0], string[1], string[2], string[3]))
{
	case -1: SendClientMessage(playerid, -1, "The name of the language is too long!");
	case -2: SendClientMessage(playerid, -1, "The name of the language key is too long!");
	case -3: SendClientMessage(playerid, -1, "The language message is too long!");
	case -4: SendClientMessage(playerid, -1, "The key comment is too long!");
	default: SendClientMessage(playerid, -1, "Key with the language message is successfully added!");
}
GetLanguageKey
With this function you can get the language message from the language key.
@langname[] = Language name.
@langkey[] = Language key which holds the information about the language message.
returns - language message which is defined by language key.
Example:
pawn Код:
SendClientMessage(playerid, -1, GetLanguageKey(GetPlayerLanguage(playerid), "WLCM_PLYR_2"));
SetPlayerLanguage
With this function you can set the language of the player.
@playerid = ID of the player.
@langname[] = Language name.
returns - this function does not return any specific values.
Example:
pawn Код:
SetPlayerLanguage(playerid, "English");
pawn Код:
SetPlayerLanguage(playerid, LANG_ENGLISH);
Set the player's language before you send him any language message or before you start using the GetPlayerLanguage function.

GetPlayerLanguage
With this function you can get the language of the player.
@playerid = ID of the player.
returns - language name.
Example:
Код:
new
		string[42];
format(string, 42, "Your language: %s.", GetPlayerLanguage(playerid));
SendClientMessage(playerid, -1, string);
SendLanguageMessage
With this function you can send language message to the player.
@playerid = ID of the player.
@color = Color of the language message.
@langkey[] = Language key which holds the information about the language message.
returns - this function does not return any specific values.
Example:
pawn Код:
SendLanguageMessage(playerid, -1, "WLCM_PLYR_2");
SendLanguageMessageEx
With this function you can send formatted language message to the player.
@playerid = ID of the player.
@color = Color of the language message.
@langkey[] = Language key which holds the information about the language message.
@... = formatted arguments.
returns - this function does not return any specific values.
Example:
Код:
new
		name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
SendLanguageMessageEx(playerid, -1, "WLCM_PLYR", name);

Definitions in the script:
Код:
#define MAX_LANGUAGE_NAME		(24)
#define MAX_KEY_NAME			(24)
#define MAX_KEY_CONTENT			(128)
#define MAX_COMMENT_CONTENT		(64)

Download:
Reply
#2

Well done.

it's very interesting what you did here.
Reply
#3

Great work
Reply
#4

Seems good, congratz.
Reply
#5

Great job!
Reply
#6

Fucking SolidFiles! Use GitHub of Pastebin please!
Reply
#7

Quote:
Originally Posted by ea8de1
Посмотреть сообщение
Fucking SolidFiles! Use GitHub of Pastebin please!
Ye gods!

http://pastebin.com/LzgSb2ef
Reply
#8

Great job
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)