[Include] translate.inc - Translating has never been easier!
#1

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
  • Make a _ macro that automatically knows which playerid it's sending to.
  • SendClientMessageToAll, GameTextForAll, etc.
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
Reply
#2

Nice release, Slice! I always like your work.
Reply
#3

Great
Reply
#4

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);
Reply
#5

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

Ah ! Nice Slice
Reply
#7

With few updates this is going to be big Great Job
Reply
#8

I don't get this.
Reply
#9

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));
Reply
#10

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

nice work man, rep
Reply
#12

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!
Reply
#13

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.
Reply
#14

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

awesome release, will help a lot of servers^^
Reply
#16

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

Fantastic include.

REP+
Reply
#18

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?
Reply
#19

good work
Reply
#20

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)