IzNoGoD
20th October 2014, 07:41
This post will (hopefully) cover everything you need to get my translation engine working (Note: this thing does NOT do the actual translation, which still has to be done by hand).
First off, you have to register the languages so the system can actually look for them:
add_language("EN");
add_language("HU");
add_language("CZ");
add_language("DE");
add_language("HR");
This will result in a warning if the language loaded has already been loaded (on a previous map for example), which you can ignore (will be displayed in serverconsole)
After this, you'll need to load the language-files:
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_b3.txt", 1);
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_lang.txt", 1);
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_update_1.txt", 1);
Note the , 1 in there, which forces a reload. I haven't exactly pinpointed why not-forcing causes issues and as it works by forcing, I never might.
Furthermore note that, contrary to the localization files, the filename in which a "localized" string is found does in no way influence the localized string name (aka JH_b3.txt does not result in all strings in there being referenced by using JH_b3_somestringname)
The actual language files are closely related to the CoD2 localization files in terms of syntax, here is a small example from my jumpmod:
REFERENCE b3_language_changed
LANG_EN "Language changed to: %s"
LANG_DE "Sprache ge?ndert auf: %s"
LANG_HU "A nyelv megvaltozott erre: %s"
LANG_CZ "Jazyk zmenen na: %s"
LANG_HR "Jezik promjenjen u %s"
REFERENCE b3_help_language_1
LANG_EN "Change the global language of the mod"
LANG_DE "Wechsel die Mod-Sprache"
LANG_HU "Megvaltoztatja a teljes mod nyelvezetet"
LANG_CZ "Zmenit globalni jazyk"
LANG_HR "Mjenja jezik servera"
REFERENCE b3_language_list
LANG_EN "Available languages:"
LANG_DE "Verf?gbare Sprachen:"
LANG_HU "Elerheto nyelvek:"
LANG_CZ "Dostupne jazyky:"
LANG_HR "Dostupni jezici:"
As visible, the actual items support printf-like syntaxis (due to my sprintf addition to libcod :) ).
Actual code calling these translations:
self locprintln("b3_language_changed", data[2]);
The helper functions I use are:
locprintln(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)
{
if(!isdefined(self) || (isplayer(self) && !isdefined(self.izno)))
return;
if(!isplayer(self))
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(isdefined(players[i].izno["login_completed"]))
players[i] thread locprintln(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
}
}
else
{
lang = self.izno["language"];
if(!isdefined(lang))
lang = level.languages[0];
//printf("getting item %s for lang %s\n", item, lang);
str = get_language_item(lang, item);
str = sprintf(str, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
self iprintln(str);
}
}
locprintlnbold(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)
{
if(!isdefined(self) || (isplayer(self) && !isdefined(self.izno)))
return;
if(!isplayer(self))
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(isdefined(players[i].izno["login_completed"]))
players[i] thread locprintlnbold(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
}
}
else
{
lang = self.izno["language"];
if(!isdefined(lang))
lang = level.languages[0];
//printf("getting item %s for lang %s\n", item, lang);
str = get_language_item(lang, item);
str = sprintf(str, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
self iprintlnbold(str);
}
}
Which allow for level locprintln("some_reference"), player locprintln("some_reference") etc.
Appendix:
Please note that the system does NOT default to english when a translation is unavailable but instead defaults to the first language found in the file, example:
add_language("EN");
add_language("HU");
add_language("CZ");
add_language("DE");
with language file:
REFERENCE b3_language_list
LANG_HU "Elerheto nyelvek:"
LANG_CZ "Dostupne jazyky:"
LANG_EN "Available languages:"
will result in "Elerheto nyelvek" when trying to obtain the german translation ("DE").
First off, you have to register the languages so the system can actually look for them:
add_language("EN");
add_language("HU");
add_language("CZ");
add_language("DE");
add_language("HR");
This will result in a warning if the language loaded has already been loaded (on a previous map for example), which you can ignore (will be displayed in serverconsole)
After this, you'll need to load the language-files:
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_b3.txt", 1);
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_lang.txt", 1);
load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_update_1.txt", 1);
Note the , 1 in there, which forces a reload. I haven't exactly pinpointed why not-forcing causes issues and as it works by forcing, I never might.
Furthermore note that, contrary to the localization files, the filename in which a "localized" string is found does in no way influence the localized string name (aka JH_b3.txt does not result in all strings in there being referenced by using JH_b3_somestringname)
The actual language files are closely related to the CoD2 localization files in terms of syntax, here is a small example from my jumpmod:
REFERENCE b3_language_changed
LANG_EN "Language changed to: %s"
LANG_DE "Sprache ge?ndert auf: %s"
LANG_HU "A nyelv megvaltozott erre: %s"
LANG_CZ "Jazyk zmenen na: %s"
LANG_HR "Jezik promjenjen u %s"
REFERENCE b3_help_language_1
LANG_EN "Change the global language of the mod"
LANG_DE "Wechsel die Mod-Sprache"
LANG_HU "Megvaltoztatja a teljes mod nyelvezetet"
LANG_CZ "Zmenit globalni jazyk"
LANG_HR "Mjenja jezik servera"
REFERENCE b3_language_list
LANG_EN "Available languages:"
LANG_DE "Verf?gbare Sprachen:"
LANG_HU "Elerheto nyelvek:"
LANG_CZ "Dostupne jazyky:"
LANG_HR "Dostupni jezici:"
As visible, the actual items support printf-like syntaxis (due to my sprintf addition to libcod :) ).
Actual code calling these translations:
self locprintln("b3_language_changed", data[2]);
The helper functions I use are:
locprintln(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)
{
if(!isdefined(self) || (isplayer(self) && !isdefined(self.izno)))
return;
if(!isplayer(self))
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(isdefined(players[i].izno["login_completed"]))
players[i] thread locprintln(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
}
}
else
{
lang = self.izno["language"];
if(!isdefined(lang))
lang = level.languages[0];
//printf("getting item %s for lang %s\n", item, lang);
str = get_language_item(lang, item);
str = sprintf(str, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
self iprintln(str);
}
}
locprintlnbold(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)
{
if(!isdefined(self) || (isplayer(self) && !isdefined(self.izno)))
return;
if(!isplayer(self))
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(isdefined(players[i].izno["login_completed"]))
players[i] thread locprintlnbold(item, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
}
}
else
{
lang = self.izno["language"];
if(!isdefined(lang))
lang = level.languages[0];
//printf("getting item %s for lang %s\n", item, lang);
str = get_language_item(lang, item);
str = sprintf(str, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
self iprintlnbold(str);
}
}
Which allow for level locprintln("some_reference"), player locprintln("some_reference") etc.
Appendix:
Please note that the system does NOT default to english when a translation is unavailable but instead defaults to the first language found in the file, example:
add_language("EN");
add_language("HU");
add_language("CZ");
add_language("DE");
with language file:
REFERENCE b3_language_list
LANG_HU "Elerheto nyelvek:"
LANG_CZ "Dostupne jazyky:"
LANG_EN "Available languages:"
will result in "Elerheto nyelvek" when trying to obtain the german translation ("DE").