darkplaces, translations and .po files

Discuss programming in the QuakeC language.
Post Reply
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

darkplaces, translations and .po files

Post by Nahuel »

hello to everyone, as I have read on dpextensions.qc darkplaces has translation support via .po files

Code: Select all

//The engine supports translating by gettext compatible .po files.
//progs.dat uses progs.dat.<LANGUAGE>.po
//menu.dat uses menu.dat.<LANGUAGE>.po
//csprogs.dat uses csprogs.dat.<LANGUAGE>.po
//
//To create a string that can be translated, define it as
//  string dotranslate_FILENOTFOUND = "File not found";
//Note: if the compiler does constant folding, this will only work if there is
//no other "File not found" string in the progs!
//
//Alternatively, if using the Xonotic patched fteqcc compiler, you can simplify
//this by using _("File not found") directly in the source code.
//
//The language is set by the "prvm_language" cvar: if prvm_language is set to
//"de", it will read progs.dat.de.po for translating strings in progs.dat.
//
//If prvm_language is set to the special name "dump", progs.dat.pot will be
//written, which is a translation template to be edited by filling out the
//msgstr entries.
I am using a very simple csqc hud mod to test the translation. my problem is that when I use the command "prvm_language dump" (only works if a map is loaded). the result in csprogs.dat.pot is something strange, and the progs.dat.pot is empty (as i expected)
i get a list of All strings i used in csqc, stuff like that

Code: Select all

msgid "vid_conwidth"
msgstr ""

msgid "vid_conheight"
msgstr ""

msgid "vid_width"
msgstr ""

msgid "vid_height"
msgstr ""
I have never specified that these strings can be translated. Whats the problem?
is there a way to specify which strings can be translated? I don't need all of them, but only a few.
at dpextensions says they should be used as:

Code: Select all

//To create a string that can be translated, define it as
//  string dotranslate_FILENOTFOUND = "File not found";
//Note: if the compiler does constant folding, this will only work if there is
//no other "File not found" string in the progs!
[/b]

but I'm not quite sure how to make a string dumped in the.po template and can be translated later.
I tried declaring in progs.dat "string dotranslate_FILENOTFOUND = "File not found";" without problems in compiling but without results in the dump

thank you in advance
hi, I am nahuel, I love quake and qc.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: darkplaces, translations and .po files

Post by Spike »

as specified in that comment, its generally easier to do something like:
sprint(other, sprintf(_("You got %d shells\n"), self.ammo_shells)); or something.

You can then use the xgettext command (this is assuming you have linux or cygwin or something installed somewhere - you'll need to consult the man pages or something to figure out the right arguments to get it to parse your QC, but its similar enough to C that you'll have no issues) to create a .pot file from your source, one that will contain ONLY the strings contained within the _() intrinsic thing. You can then use the other programs provided in the same unix package to merge+manage your translations such that you don't need to restart from scratch all the itme.

Note that using sprintf as above gives your translators the possibility of reordering arguments to match their language (eg if the natural way to write it in some language is like 'shells +5 to you', then sprintf can cope with that where ftos and strcats would not be able to).
sprintf also allows more complete strings, which can help give more reliable translations.
Note that right now there's no way to deal with plurals properly. Eg a french mod might have '1st' and 'nth', but an english translation of that needs '2nd' and '3rd' pluralities too, and things get really messy when you deal with teens and french's utterly bizzare 'quatre vingt dix neuf'. As a result you may find you still need to change the qc code for specific languages.
Post Reply