source:
https://wiki.alliedmods.net/Advanced...ng_(AMX_Mod_X)
Next time search.
Multi-Lingual Support
Adding multi-lingual support to a plugin can be difficult, but it's usually worth it if you have clients who are willing to translate your strings into their native language.
The first step is to identify what needs to be translated. Say you have a call like this:
Code:
new score = get_score()
client_print(id, print_chat, "[AMXX] Your score is %d", score)
This is a good candidate for being multi-lingual. First, create a .txt file (preferrably named after your plugin) and store it in addons\amxmodx\data\lang\. Let's use "myplugin.txt" for the example. For each language, add an entry to the file. Entries are set up as 'keys', which are matched to 'translation strings'. Observe:
(addons\amxmodx\data\lang\myplugin.txt)
Code:
[en]
SCORE_MSG = Your score is %d
[de]
SCORE_MSG = Ihr Spielergebnis ist %d
[es]
SCORE_MSG = Su cuenta es %d
[fr]
SCORE_MSG = Votre score est %d
Then, in plugin_init(), you must register the language keys:
Code:
public plugin_init()
{
...
//assumes placed in amxmodx\data\lang
register_dictionary("myplugin.txt")
}
Now, here comes the hard part. AMX Mod X's Multi-Lingual API is built into the format() style routines. For anything that looks like or uses format()-style strings, you can use the ML API.
Code:
client_print(id, print_chat, "[AMXX] %L", id, "SCORE_MSG", get_score())
Let's break this down. For each %L that appears, we need at least two parameters. The first parameter is the TARGET. This must be a player id, LANG_SERVER (meaning show in the server's native language), or LANG_PLAYER. LANG_PLAYER is a special modifier that should only be used when sending a message to all players - it means "show in every player's native language". The second parameter is the key string that identifies the language phrase to translate. Lastly, if the translated string requires any parameters itself (ours needs %d, one integer), that must be added as well.
You can get very complicated designs with this, but it's recommended that you keep things simple for clarity. Here is a final example using a global message to all players, assuming the key HELLO is properly translated in all the languages available:
Code:
client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "HELLO")
__________________