Raised This Month: $51 Target: $400
 12% 

Multi-Lingual System


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
SniperBeamer
AMX Mod X Founder
Join Date: Jun 2003
Location: Good Old Europe
Old 07-30-2004 , 17:38   Multi-Lingual System
#1

This writeup is intended to introduce users to how AMX Mod X 0.20's Multi-Lingual system works. If you are not a developer, you can probably disregard this.

I. Overview
II. Scripting
III. Modules
IV. Implementation

I. Overview

The AMX Mod X Multi-Lingual system is designed for optimized formatting of phrases to be delivered to clients. Each plugin and module is responsible for "reinforcing" a set of dictionary translations which can be used across many AMX Mod X functions. Each server sets a default language for translations to take place, and clients may set their own language as a setinfo ("_language").

AMX Mod X 0.20 will come with a plugin that allows users to select their language upon joining a server, if they do not already have one set. The Admin Menu will also let you choose the server's default language.
Language definitions are stored as formatted strings inside a "dictionary file". A dictionary file is a simple text file that looks like this (we'll call this one "greetings.txt"):
Code:
[en]
Hello = Hello, %s!
Bye = Goodbye, %s!
[es]
Hello = Hola, %s!
Bye = Adios, %s!
[de]
Hello = Guten Tag, %s!
Bye = Auf Wiedersehen, %s!
Three options are available for formatting - %s (String), %d (integer number), %f (float/decimal number). Dictionary files are loaded by plugins and cached by the AMX Mod X core.

II. Scripting
Dictionary Text Files are "reinforcements" for the master dictionary - which is an optimized binary file stored in the data folder. A plugin should make sure their definitions are already registered in the master dictionary with "register_dictionary", like so:
Code:
public plugin_init() {    register_plugin("Language Test", "1.0", "BAILOPAN")    register_dictionary("greetings.txt") }
For more information on how this works, see the Implementation section.
To format a message to a certain language phrase, there is a new descriptor available for all commands which accept the style of "format" (such as client_print, server_print, et cetera). The descriptor is L and is used like so:
Code:
format(buffer[], maxLength, "%L", clientID, languageKey[], [ ... ])
Here is an example:
Code:
public client_putinserver(id) {    new name[24]    get_user_name(id, name, 24)    client_print(id, print_chat, "%L", id, "Hello", name) }
Taking this step by step:
1. "%L" tells the string formatter to start a language translation. "%L" must always occur by itself like it is here.
2. "id" tells the language translation to use the language of the specific client "id". The client's setinfo _language is read, and if no language is found, the server's default is used (cvar amxx_language).
3. "Hello" tells the language translation to look up the definition for "Hello" (case insensitive). The definition from our dictionary is "Hello, %s" if the client is using English.
4. "name" tells the language translation to insert the client's name into the translation string as the first parameter (%s). This will result in "Hello, !".
5. The final formatted string is sent to the client. There are special exceptions to this rule. This will send a message to all clients in their own language:
Code:
client_print(0, print_chat, "%L", LANG_PLAYER, key[], [ ... ])
This will send a message to all clients in the server's language:
Code:
client_print(0, print_chat, "%L", LANG_SERVER, key[], [ ... ])
The special modifier -1 is only useable in functions that apply to
all users. Note that you cannot do something like:
Code:
//This is illegal, %L must appear alone. client_cmd(0, print_chat, "echo %L", id, "Hello", name)

Also, as a side note, the "id" parameter can be the two letter code for a language, like "en" or "de", although most of the time this will be unnecessary.

Lastly, there are some commands you will most likely never need to
use. They are:
Code:
// Return the number of languages loaded native get_langsnum(); // Return the name of a loaded language (0 to x-1) // two letter code native get_lang(id, name[3]); //registers a dictionary file, making sure the words are in the dictionary // the file should be in "addons/amxx/data/lang/", but only the name  needs to be // given.  (e.g. register_dictionary("file.txt") will be addons/amxx/data/file.txt). native register_dictionary(const filename[]); //returns 1 if the language is loaded, 0 otherwise. native lang_exists(const name[]);

III. Module Functions

The AMX Mod X MDK (Module Development Kit) has been updated with
two new functions:
Code:
void MF_MergeDefinitionFile(const char *file);
void MF_MergeDefinition(const char *language, const char *key, const char *definition);
Also, MF_FormatAmxString() can now accept the "%L" format listed above.

IV. Implementation
All dictionary results are cached in memory and on the disk in a binary file called "languages.dat", in addons/amxx/data or datadir. It's optimized for lookup by storing key pairs of hashes to offsets. More information will be available on this later.

Credits:
PM OnoTo, BAILOPAN, original concept by T(+)rget
__________________
SniperBeamer is offline
Downtown1
Veteran Member
Join Date: Mar 2004
Old 07-30-2004 , 18:38  
#2

Very interesting.. so %L can be used with any string functions, or just client_print() and format() ?

And to do something like "echo %L" we'd have to concantenate the strings using a second function, yes?

By the way, the dictionaries, they are precached no matter what? That sounds good as long as nobody writes encyclopedia entries!

[edit] Oh, another question, what kind of charset(s) does this support? Unicode? ISO? Just plain ASCII?
Downtown1 is offline
SniperBeamer
AMX Mod X Founder
Join Date: Jun 2003
Location: Good Old Europe
Old 07-30-2004 , 19:19  
#3

Quote:
Originally Posted by Downtown1
Oh, another question, what kind of charset(s) does this support? Unicode? ISO? Just plain ASCII?
The charset Half-Life supports so only English chars are supported.
We can't do anything about this.
__________________
SniperBeamer is offline
sanaell
Senior Member
Join Date: May 2004
Location: SamutPrakarn Thailand
Old 07-31-2004 , 04:14  
#4

hi


if i want print

"HELLO THE WORLD" in french how you made this?

sometimes in french or german or other the order of word aren t the same

"the public is brainless" => "le public est sans cervelle"
"my brain is aware" => "mon cerveau est a l'ecoute"
ect....


is a limited function ?

why don t made something like
lang_FR.txt
and detect it in a global cvar like amxx_lang = 0 (1 for french, 2 for german etc...)

or
[english]
Msg01=""
[french]
Msg01=""
.....
__________________
[email protected]
The Source of Pain is the Pain of Source
sanaell is offline
Send a message via MSN to sanaell
AlucarD_fOx
Member
Join Date: Jul 2004
Location: Araraquara, SP - Bra
Old 07-31-2004 , 04:15  
#5

What´s languages are supported?

Have support for portuguese too?

Thankx!!
AlucarD_fOx is offline
Send a message via ICQ to AlucarD_fOx Send a message via MSN to AlucarD_fOx
SniperBeamer
AMX Mod X Founder
Join Date: Jun 2003
Location: Good Old Europe
Old 07-31-2004 , 04:16  
#6

we are looking for translators ...
__________________
SniperBeamer is offline
sanaell
Senior Member
Join Date: May 2004
Location: SamutPrakarn Thailand
Old 07-31-2004 , 04:17  
#7

I am here LOL, i PM you before no ,
__________________
[email protected]
The Source of Pain is the Pain of Source
sanaell is offline
Send a message via MSN to sanaell
[FBX]
Senior Member
Join Date: May 2004
Old 07-31-2004 , 06:26  
#8

looks like generic things, like hello, good-bye, or things you might say during the game. Most likely wont be complicated things or things you would probably use in a plugin unless you did a lot of concatination.
[FBX] is offline
Deagle
Veteran Member
Join Date: Jun 2004
Old 07-31-2004 , 06:44  
#9

i can translate into Turkish thats a big market too and i would personally love to see that language in it

all i need is the list of words that needs to be translated

Regards Deag
__________________
http://www.kingpinservers.com
-=(Wickedest Host On Eastcoast)=-
Deagle is offline
sanaell
Senior Member
Join Date: May 2004
Location: SamutPrakarn Thailand
Old 07-31-2004 , 07:48  
#10

every lang can be support but you must use the ENGLISH ALPHABETIC RESTRICT

so only the azertyuiopqsdfghjklmwxcvbn character can be support
no àéèÜÖÏËÄ etc....
__________________
[email protected]
The Source of Pain is the Pain of Source
sanaell is offline
Send a message via MSN to sanaell
Closed Thread



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

Forum Jump


All times are GMT -4. The time now is 10:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode