I think it is important to be able to translate whole Glest to different languages, not only the user interfaces.
To be able to do that, we need a mechanism to translate things.
I haven't found out where the unit strings and descriptions are stored, but we need to translate voices and sound effects any way.
I personally think that these points are important for a translation:
* Translation file should not be much longer than the translation itself and the file should be easy to create
* If the original text is updated, the translation may need updates too so we need a mechanism to handle this
* Some languages are similar to each other, so we need a mechanism to specify the fallback-language
At first, the solution to fallback-languages could be an XML-File like this:
<languages>
<!--Language example-->
<lang id="de">
<name><translatable id="trans_de" lang="de">Deutsch</translatable>
<translatable ref="trans_de" lang="en">German</translatable>
</name>
<!--Sublanguages-->
<sub-languages>
<lang id="de-ch">
<name><translatable id="trans_dech" lang="de-ch">Schweizerdeutsch</translatable>
</name>
</lang>
</sub-languages>
<!--Similar languages, then english at last? -->
<fallback-languages>
<lang ref="en" />
</fallback-languages>
</lang>
<!--Small ref example-->
<lang id="en">
<name><translatable id="trans_en" lang="en">English</translatable></name>
</lang>
</languages>
You specify Languages using a "lang"-tag with the required attribute id. All these languages have got a translatable name, zero or more sub-languages which have the same structure as a language and zero or more fallback-languages which are used if no text for the original language can be found (since english is glest's main language it would be sensible to add it as fallback-language to all languages)
All data for the translations could be in lang/<language-id>/data (folder-structure like "normal" /data)
So I thought we could add a <translatable>-tag to each glest XML-file
This tag should have one required attribute, an id which is unique in (?) all these translatable-Tags in the glest file.
Optionally you can specify a language there, then you add a lang-Tag which contains the abbr. of the base language (e.g. lang="en"). There should also be one optional version-Tag which defaults to 0 and should be increased whenever a substantial change (meaning: not a simple correction of mistakes, but different content or formatting) occurs. Maybe there could be three additional tags to "copy" strings: ref-lang="?" to take a string from a certain language, ref-id="?" to take a string from another id and ref-src="?" to take a string from another XML-File (of course the last one is only sensible if ref-id is set)
All the elements in the translatable-tag are the same as "normally", but in another folder (language-specific? e.g. having de/data or something like that?) There is another file which contains the translations: only elements of type <translatable> using ref (Refering to an ID), lang and version-tag.
Glest, at loading any XML-file, if it comes to any translatable Tag, it does:
* if the tag has set the attribute id, the node is saved (for example in a Map<ID,Node> translatableNodes)
* If the lang-Attribute has a higher priority than the one current one in (Map<Id, Node> curTranslation), the node there is replaced.
The direction-Information in Map<Id, string> currentDirectories is replaced with the directory the file is in
The priority for languages could be as following:
- The exact specified language in the Glest options
- Any sublanguages of the specified language
- Any parent languages
- Any manually specified fallback-language
- Any fallback-language of the chosen language (earlier fallback-language = higher priority)
- Any fallback-language of any sublanguage of the chosen language
- Any fallback-language of any parent language of the chosen language
- Nothing
* Glest looks for the best-matching language:
It looks for language-files in the order of priorities until the language of curTranslation has higher priority than the language which glest would look for (because then the curLanguage could never be replaced).
* If the attribute "version" exists for both the Nodes in curTranslation and translatableNodes and it is smaller in curTranslation than in translatableNodes, a warning is emitted
* Every $CURDIR in every attribute is replaced by the String of currentDirectories
* the Node in translatableNodes is replaced by the content (!) of the one in curTranslation
* maybe the resulting XML-File is saved in order to cache it?
* The modified XML-file is returned
Example:
Assume we have the following, simple XML-Filepart:
<selection-sounds enabled="true">
<sound path="../archmage_tower/sounds/magic_click_nolang.wav"/>
<sound path="../archmage_tower/sounds/magic_click_1.wav"/>
<sound path="../archmage_tower/sounds/magic_click_2.wav"/>
<sound path="../archmage_tower/sounds/magic_click_3.wav"/>
</selection-sounds>
While magic_click_nolang does not need any translation, the other ones should be translated.
<selection-sounds enabled="true">
<sound path="../archmage_tower/sounds/magic_click_nolang.wav" />
<translatable id="archmage_sounds" version="1" lang="en">
<sound path="$CURDIR../archmage_tower/sounds/magic_click_1.wav"/>
<sound path="$CURDIR../archmage_tower/sounds/magic_click_2.wav"/>
<sound path="$CURDIR../archmage_tower/sounds/magic_click_3.wav"/>
</translatable>
</selection-sounds>
or you can add no default language:
<selection-sounds enable="true">
<sound path="../archmage_tower/sounds/magic_click_nolang.wav />
<translatable id="archmage_sounds" />
</selection-sounds>
If the user wants to have e. g. german, there could be the following file in
$GLEST/lang/de/.../archmage_tower.xml:
<translations>
<translatable ref="archmage_sounds" version="1" lang="de">
<sound path="$CURDIR../archmage_tower/sounds/magic_click_1.wav" />
</translatable>
</translations>
because only one sound has been respoken in german.
The XML-Reader would replace the
<translatable id="archmage_sounds" /> of the XML-File with
<sound path="$CURDIR../archmage_tower/sounds/magic_click_1.wav>
and replace $CURDIR with e.g. /usr/share/glest/lang/de/data/game/techs/magitech/factions/magic/units/archmage_tower/
so the XML-File for german users would be
<selection-sounds enabled="true">
<sound path="../archmage_tower/sounds/magic_click_nolang.wav" />
<sound path="/usr/share/glest/lang/de/data/game/techs/magitech/factions/magic/units/archmage_tower/../archmage_tower/sounds/magic_click_1.wav"
</selection-sounds>
Of course the whole translation-thing would be more effective for descriptions etc. but I haven't found any.
EDIT:
Some logical mistakes corrected