How to adding translations function?
Hello to everyone!
What should we do to translate the messages of the plugin into different languages? Shortly, how is multi-language function added to the plugin? Could you give an example using the following simple plugin? Code:
#include <amxmodx> |
Re: How to adding translations function?
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:
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]Code:
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:
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:
|
Re: How to adding translations function?
Hi Napoleon_be,
Thanks for your detailed explain. There is one more thing I want to ask. I understand the use of this %L parameter. Sometimes they use %s, sometimes use %d and sometimes %i parameters. How to determine which one to use? Is the following usage correct? Code:
client_print(id, print_chat, "[INFO] Name: %s | Kills: %s | Score: %s", NAME, KILLS, SCORE) |
Re: How to adding translations function?
%s - To retrieve a string ( words / sentences )
%i or %d - To retrieve an integer value ( ex : ... 1 / 2 / 3 ... ) %f - For Floats value ( ex : 0.525000 ) |
Re: How to adding translations function?
Quote:
|
Re: How to adding translations function?
%L is used to get strings from LangFile
Ex func : PHP Code:
Then that file should look like this HTML Code:
[en] |
Re: How to adding translations function?
Hi instinctpt1, thanks for your explain. I want to get two %L from the language file. What should I do? Also, is there a document that contains what you're explaining? I want to make two different translations for the "[INFO] and "This is the test message." below.
Code:
client_print(0, print_chat, "[INFO] This is the test message.") |
Re: How to adding translations function?
Quote:
Quote:
Quote:
|
Re: How to adding translations function?
Quote:
Quote:
Quote:
|
Re: How to adding translations function?
Quote:
Quote:
|
| All times are GMT -4. The time now is 04:43. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.