When you mentioned domain earlier, I thought domain implied the regional translation (ie english, german, polish, etc.). So it instead means "which file name to lookup the translated string in"? That makes things a little more confusing than I thought they'd be for our code.
Hmm...so yeah..I'm thinking maybe this is a little confusing..
-instead of adding gettext("string") for every single string that needs to be translated in the .lua files...I went to the source where all the strings are being processed..and called TranslateString() on the variable passed within the program..
So for example, dialogues..
All dialogues call the AddText() function defined in map_dialogue.cpp...so by calling TranslateString(text) within AddText()...i can get the resulting translated string..
Similarly if i wanted to translate the item names, descriptions..
I would go into global_objects.cpp and call TranslateString() and pass the appropriate variable to get the resulted translation..
Which is why i have such a thing as the "domain" variable..
When initiating gettext you can call
Code: Select all
bindtextdomain( "domain name", "./folder that .mo files are in")
This is what allows us to work with multiple .mo files..
The domain name is basically the .mo filename we're working with..
And so for example...we could set up things like:
And when we call TranslateString() in map_dialouge.cpp we can pass the domain variable "dialogue" to indicate that we're working with the dialogue.mo file..
Similarly, we pass "item" in global_objects.cpp to indicate we are working with the item.mo file..
and so on..
The plus side of this approach is that we dont have to put gettext("string") or _("string)...
around every single string in our src files and .lua files that needed to be translated..
because we can use variables passed within the program...
But this also means that I cant just simply extract all the translatable strings within one .lua file to one .po file...
because different strings call different functions...and are used by different parts of our program..
So in terms of extracting the strings...it might be a harder task than this second approach..
-Put TranslateString("string") around all the strings that need to be translated in src files and .lua files...
-This means i probably need to bind the function TranslateString() using luabind...i think this goes in defs.cpp
-Then we simply extract using xgettext ALL the translatable strings..
-We can probably split them up into multiple .mo files as well
-But we still need to pass TranslateString() a domain name to indicate which .mo file to look up when calling gettext
I think..actually this is closer to what Roots told me to do in this post:
http://www.allacrost.org/forum/viewtopi ... c&start=60
So..I should ask which approach sounds better?
Also on a note to the language like (english, german, polish, etc)
I found out that the environment variable $LANGUAGE
is what determines what gettext considers..so by calling:
Code: Select all
setenv ("LANGUAGE", _language.c_str(), 1);
and setting _lanugage to "ko" for testing purposes..
i was able to get the program to display my "korean" translation
in an English OS setting...so I guess all we need to do is get this into
the boot menu options..
Question: do all .po/.mo files (not too sure about the difference yet, but I think .mo is compiled form of .po?) have to be contained within the same directory (e.g. "txt/")? Or can they be in subdirectories, like "txt/maps", "txt/objects", etc?
From my testing..I dont think we can create subdirectories..
This is how my txt folder is setup right now:
(if i move the .mo file to any other folder it doesnt seem to work)
(The filenames are just what i made up)
something like that..
the general setup is that the .mo file needs to be in:
the difference between .pot files and .po files is that the
.po file has the headers with all the information about the file..
# Korean translations for Hero of Allacrost - Demo package.
# Copyright (C) 2007 THE Hero of Allacrost - Demo'S COPYRIGHT HOLDER
# This file is distributed under the same license as the Hero of Allacrost - Demo package.
# DongHa Lee <email@example.com
"Project-Id-Version: Hero of Allacrost - Demo 0.2.0\n"
"POT-Creation-Date: 2007-08-03 20:18-0400\n"
"PO-Revision-Date: 2007-08-03 20:23-0400\n"
"Last-Translator: DongHa Lee <firstname.lastname@example.org
"Language-Team: Korean <email@example.com
"Content-Type: text/plain; charset=ASCII\n"
"Plural-Forms: nplurals=1; plural=0;\n"
So, basically we use the .pot files to create different versions of .po files for different languages..using msginit command mentioned in the first thread of this topic..
And as for .po/.mo they're basically the same thing...
PO files are what translators edit
MO files are what the gettext() functions read, and is the only thing
that needs to be in the specific folder mentioned above..
(the .po file could be somewhere else)
but i put them in the same folder because if you use poEDIT
to edit the .po files they create .mo files in the same folder for you
so it's more convenient to put them in the same folder