SA-MP Forums Archive
[Include] translate.inc - Translating has never been easier! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] translate.inc - Translating has never been easier! (/showthread.php?tid=468821)

Pages: 1 2


translate.inc - Translating has never been easier! - Slice - 10.10.2013

This gettext-inspired include will make it very easy to translate your your scripts!

Usage
This is what translatable code would look like:
pawn Код:
// If the player's language is set to spanish, this message will be sent in spanish.
SendClientMessage(playerid, color, __("Hello! How are you?", playerid));
Your translation file will now look like this:
pawn Код:
"Hello! How are you?" = "Hello! How are you?"
To translate it, simply change the right side:
pawn Код:
"Hello! How are you?" = "Hola! їCуmo estбs?"
I don't get it.. explain more?
http://forum.sa-mp.com/showpost.php?...2&postcount=10

Advanced usage
You can go very far with this. You can use the strings pretty much anywhere.

pawn Код:
SendClientMessage(playerid, color, sprintf(__("You just bought %d gold for $%d.", playerid), gold, money));
Planned features Performance
No matter how many strings you have, this include will not be any slower. It scans the AMX code on startup and modifies it to look for the translated string in an array.
There's not even a function being called when you use __("string", playerid)!

Compatibility
It works on Windows and Linux with or without the JIT plugin.

Download
More info: https://github.com/oscar-broman/samp...samp-translate
GitHub: https://github.com/oscar-broman/samp-translate


Re: translate.inc - Translating has never been easier! - Konstantinos - 10.10.2013

Nice release, Slice! I always like your work.


Re: translate.inc - Translating has never been easier! - Champ - 10.10.2013

Great


Re: translate.inc - Translating has never been easier! - IPrototypeI - 10.10.2013

Nice Include i love to study your includes which are written with #emit and i have an idea for your include you can add even an audiotranslation
via ****** translator
To create this Audioaddress you have to format the address with the text and the language
Код:
format(str, 512, "http://translate.******.kg/translate_tts?ie=UTF-8&q=%s&tl=%s&prev=input", text, lang);



Re: translate.inc - Translating has never been easier! - SsHady - 10.10.2013

Great work! Another Great Release from you
Keep up the good work!
+1


Re: translate.inc - Translating has never been easier! - Michael@Belgium - 10.10.2013

Ah ! Nice Slice


Re: translate.inc - Translating has never been easier! - BloodMaster - 10.10.2013

With few updates this is going to be big Great Job


AW: translate.inc - Translating has never been easier! - Mellnik - 10.10.2013

I don't get this.


Re: AW: translate.inc - Translating has never been easier! - Slice - 10.10.2013

Quote:
Originally Posted by Mellnik
Посмотреть сообщение
I don't get this.
It allows you to have your script in multiple languages. Say you have one spanish guy, one russian, and one canadian - this script will allow you to send messages in each respective language to them.

Normal translation scripts usually do something like define variables such as LANG_HELLO then give them values in language files ("hola", "privet", "hello").
That can get rather confusing, because the language string is not in your code - you have to look it up every time. Furthermore, you don't know what format specifiers are in it (%s, %d, etc.).

Other includes:
pawn Код:
[russian]
LANG_HELLO = "privet"
LANG_GIVEN_WEAPON = "vodka vodka %s na zdorovye %s."
[spanish]
LANG_HELLO = "hola"
LANG_GIVEN_WEAPON = "tengo much armas %s y %s."
[english]
LANG_HELLO = "hello"
LANG_GIVEN_WEAPON = "You were given a %s by %s."
pawn Код:
SendClientMessage(playerid, color, GetText(LANG_HELLO, playerid));
SendClientMessage(playerid, color, sprintf(GetText(LANG_GIVEN_WEAPON, playerid), weapon, name));
This include:
pawn Код:
// russian.lang.inc
"hello" = "privet"
"You were given a %s by %s." = "vodka vodka %s na zdorovye %s."
// spanish.lang.inc
"hello" = "hola"
"You were given a %s by %s." = "tengo much armas %s y %s."
pawn Код:
SendClientMessage(playerid, color, __("hello", playerid));
SendClientMessage(playerid, color, sprintf(__("You were given a %s by %s.", playerid), weapon, name));



Re: translate.inc - Translating has never been easier! - iZN - 11.10.2013

Great work Slice as usual. I was little bit confused but your last post cleared it up.


Re: translate.inc - Translating has never been easier! - Matt - 12.10.2013

nice work man, rep


Re: translate.inc - Translating has never been easier! - Lorenc_ - 13.10.2013

This is great, always wanted to make the same thing.

I just would hate to go through the whole script to replace every SendClientMessage. It would be possible to hook some code into SCM and return out the translated text, right? If so, definitely translating has been never easier with this!

Good job Slice!


Re: translate.inc - Translating has never been easier! - Slice - 13.10.2013

Quote:
Originally Posted by Lorenc_
View Post
This is great, always wanted to make the same thing.

I just would hate to go through the whole script to replace every SendClientMessage. It would be possible to hook some code into SCM and return out the translated text, right? If so, definitely translating has been never easier with this!

Good job Slice!
Well, you'll always need the underscore macro around text, but in future versions there will be a macro that takes only 1 argument - the text. It'll automatically figure out what playerid it's being sent to.

FYI, this is what I'm trying to replicate (without PBP): https://github.com/oscar-broman/PAWN...e#translations

Edit: I just realized it's possible to have this format of the strings: @"text"!! All I need to do is write some tricky macros.


Re: translate.inc - Translating has never been easier! - Sublime - 13.10.2013

pawn Code:
#DEFINE __ @
Won't that work?


Re: translate.inc - Translating has never been easier! - Astralis - 13.10.2013

awesome release, will help a lot of servers^^


Re: translate.inc - Translating has never been easier! - Slice - 13.10.2013

Quote:
Originally Posted by Sublime
View Post
pawn Code:
#DEFINE __ @
Won't that work?
I'm talking about @"text" instead of _("text").


Re: translate.inc - Translating has never been easier! - Excel™ - 13.10.2013

Fantastic include.

REP+


Re: translate.inc - Translating has never been easier! - Sublime - 14.10.2013

It would be great to have something like @", instead of __( since it's a pain-in-the-ass.

Is it possible to do something like, language set using country detect using this include?


Re: translate.inc - Translating has never been easier! - shittt - 14.10.2013

good work


Re: translate.inc - Translating has never been easier! - Slice - 14.10.2013

Quote:
Originally Posted by Sublime
View Post
It would be great to have something like @", instead of __( since it's a pain-in-the-ass.

Is it possible to do something like, language set using country detect using this include?
You could us a GeoIP plugin and a switch statement. Many countries have multiple languages, though, and some people aren't native inhabitants. You'd probably be better off with a dialog shown once per IP or per account.