AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to adding translations function? (https://forums.alliedmods.net/showthread.php?t=308035)

highcoder 06-04-2018 08:41

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>
#include <amxmisc>

#define PLUGIN "Sample Plugin"
#define VERSION "1.0"
#define AUTHOR "John Doe"


public plugin_init() {

        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_clcmd("say", "sample")
        register_clcmd("say_team", "sample")
       
}

public sample(id) {

        client_print_color(id, id, "^4[INFO] ^3This is a sample text.")
       
}


Napoleon_be 06-04-2018 14:16

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:
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")

highcoder 06-05-2018 02:09

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)

instinctpt1 06-05-2018 07:06

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 )

highcoder 06-05-2018 08:17

Re: How to adding translations function?
 
Quote:

Originally Posted by instinctpt1 (Post 2595384)
%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 )

Thanks for your explain. Also, I saw the %L parameter is using for translation. Is there a document that contains what you're explaining?

instinctpt1 06-05-2018 08:30

Re: How to adding translations function?
 
%L is used to get strings from LangFile

Ex func :
PHP Code:

client_print(0print_chat"[AMXX] %L"LANG_PLAYER"SCORE_MSG"

Now if my plugin uses a dictionary ( lang file )
Then that file should look like this
HTML 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

Which means it will depend on user's language and will automatically take translations you provide in your dictionary ( lang file )

highcoder 06-05-2018 14:48

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.")

fysiks 06-05-2018 22:47

Re: How to adding translations function?
 
Quote:

Originally Posted by highcoder (Post 2595475)
is there a document that contains what you're explaining?

Did you look at the link or anything posted by Napoleon_be? He literally gave you the entire documentation for the Multi-lingual feature.

Quote:

Originally Posted by highcoder (Post 2595475)
I want to get two %L from the language file. What should I do?

I believe you just repeat what you do for one %L. Alternatively, you can format them separately and then combine them afterwards with add().

Quote:

Originally Posted by highcoder (Post 2595475)
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.")

This question doesn't make sense. Isn't this just the entire point of using the multi-lingual functionality?

highcoder 06-06-2018 02:28

Re: How to adding translations function?
 
Quote:

Originally Posted by fysiks (Post 2595522)
Did you look at the link or anything posted by Napoleon_be? He literally gave you the entire documentation for the Multi-lingual feature.

I couldnt find it.

Quote:

Originally Posted by fysiks (Post 2595522)
I believe you just repeat what you do for one %L. Alternatively, you can format them separately and then combine them afterwards with add().

It may be possible.

Quote:

Originally Posted by fysiks (Post 2595522)
This question doesn't make sense. Isn't this just the entire point of using the multi-lingual functionality?

You're not helping. I will try to solve it myself.

fysiks 06-06-2018 22:22

Re: How to adding translations function?
 
Quote:

Originally Posted by highcoder (Post 2595533)
I couldnt find it.

He posted the entire section for Multi-Lingual support in his post. Also, apparently, the link he posted is broken. The real link is here.



Quote:

Originally Posted by highcoder (Post 2595533)
You're not helping.

Most often, the quality of a response reflects that of the original question.


All times are GMT -4. The time now is 04:43.

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