Translation support - how did you do it?

Translation support - how did you do it?

Postby KroArtem » 17 Aug 2012, 21:58

Hello,
I remember you guys added translation support to Me&MyShadow some time ago and I'm interested how have you done that? I mean, some of you worked with translation support for the first time and I'd like to know from where you started.
As far as I can judge you're using tinygettext to support .po/.mo files. Is this lib compiled when the game compiles, what's the main syntax, are .po files converted to .mo (looks like .po files are used without converting to .mo while other projects convert these files. That looks a bit strange to me.) etc.. In other words : were you using some tutorial for this? If yes, share a link to those tutorial, please :)

The reason I'm asking it is simple - I just want to receive some experience in this field and add simple translation support to my program.
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: Translation support - how did you do it?

Postby Edward_Lii » 18 Aug 2012, 05:51

Hello KroArtem,

KroArtem {l Wrote}:were you using some tutorial for this? If yes, share a link to those tutorial, please :)

We didn't really use any tutorial AFAIK.
Although we decided to use tinygettext and not gettext their documentation still has some valuable information:
http://www.gnu.org/software/gettext/manual/gettext.html

KroArtem {l Wrote}:As far as I can judge you're using tinygettext to support .po/.mo files. Is this lib compiled when the game compiles

The lib is indeed bundled with the game and compiled alongside it.
BTW I'm not even sure tinygettext can handle .mo files at all...

KroArtem {l Wrote}:what's the main syntax

For gettext the default syntax is basically gettext( ... ) for every translatable string.
For tinygettext that will be dictionaryManager->get_dictionary().translate( ... ).

What most people do is alias gettext() to _().
We did the same thing with tinygettext using this code:
{l Code}: {l Select All Code}
#define _(message) (dictionaryManager!=NULL?dictionaryManager->get_dictionary().translate(message).c_str():std::string(message).c_str())

In our case we have also defined a _C() method which accepts both a message and a dictionary manager.
We need this for different translation files ( = different dictionarymanagers) for (addon) levelpacks and that's one of the main reasons we chose tinygettext.
Gettext simply doesn't support multiple message catalogs in use at the same time.

KroArtem {l Wrote}:are .po files converted to .mo (looks like .po files are used without converting to .mo while other projects convert these files. That looks a bit strange to me.) etc..

.po files can be converted to .mo, which is the binary version of the message catalogue and uses less disk space.
The reason we don't compile them is, first of all that tinygettext doesn't support .mo files.
But keeping it human readable also has the advantage that one can edit it manually without the need to compile.
And you can easily see what has changed when comparing svn revisions.

If you've got any questions left, feel free to ask.
Also take a look at the code for how we initialize the dictionarymanager and use it. ;)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Translation support - how did you do it?

Postby KroArtem » 18 Aug 2012, 18:44

Hello,
could you please tell me in which source file does M&MS handles work with this stuff?

Right now I'm reading about gnu gettext utilities from the link given above, and some paragraphs are pretty useful. I'll certainly have more questions soon :)
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: Translation support - how did you do it?

Postby Edward_Lii » 18 Aug 2012, 18:54

Hello KroArtem,

KroArtem {l Wrote}:could you please tell me in which source file does M&MS handles work with this stuff?

The initialization of the main dictionaryManager which is used to translate all strings in-game (no levelpack strings):
http://sourceforge.net/p/meandmyshadow/meandmyshadow/508/tree/src/Functions.cpp#l539
The initialization of the levelpack dictionaryManagers:
http://sourceforge.net/p/meandmyshadow/meandmyshadow/508/tree/src/LevelPack.cpp#l91
The defining of the _() and _C() methods:
http://sourceforge.net/p/meandmyshadow/meandmyshadow/508/tree/src/Functions.h#l32

The script we use to generate the main messages.pot file might also be interesting/useful:
http://sourceforge.net/p/meandmyshadow/meandmyshadow/508/tree/tools/messages.pot.sh

And basically everywhere there's a translatable string you'll see _( message ) or _C( message ).
Note that the help messages in Main.cpp aren't translatable that's because the dataPath isn't configured yet so the .po files can't be located yet.

We use findlocale for detecting the system configured locale.

KroArtem {l Wrote}:I'll certainly have more questions soon :)

No problem, feel free to ask. ;)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Translation support - how did you do it?

Postby acme_pjz » 19 Aug 2012, 06:58

Hi KroArtem,

I have some off-topic information about gettext: IMHO .mo files are easier to read then .po files, and I also programming in Visual Basic, I had written a class for determining system locale and load corresponding .mo file in Visual Basic :) So maybe you can look at .mo file format, and write a simple .mo file reader, because GNU gettext is toooooo big...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Translation support - how did you do it?

Postby KroArtem » 28 Aug 2012, 23:31

Sorry for not being active, I'll have some exams soon so I had to prepare for them. I'll come back to this topic in the middle of September.
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Who is online

Users browsing this forum: No registered users and 1 guest