Version 1 (modified by landauf, 17 years ago) (diff) |
---|
Language
Description
The Language is a singleton? that handles strings in different languages. It replaces hardcoded strings by labeled strings, where the coder only uses the label and the Language searches for the localised string in the configured language-file. Every string has a fallback-value that is used if there is no localised version or no language was configured. The language can be configured by changing the language_ entry in the config-file.
All labels and the corresponding fallback strings are written to translation_default.lang. If the fallback-string gets changed in the code, translation_default.lang changes too. If a new label gets added in the code, it gets added to translation_default.lang. You can't change labels or fallback-strings in this file, it will be set back to the default. You can use translation_default.lang as a sample for a new language file. See Language for more informations about this.
Functions
- getLanguage(): Returns a reference to the only existing instance of the Language class.
- addEntry(label, fallback string): Adds a new entry to the Language by defining a unique label and a fallback string that gets used in case there is no localisation.
- getLocalisation(label): Returns the localisation of the given label.
Example
Piece of code:
// Displays the users age int age = 20; Language::getLanguage().addEntry("user_age", "Age"); std::cout << Language::getLanguage().getLocalisation("user_age") << ": " << age << std::endl;
Extract of translation_default.lang:
user_age=Age
Extract of translation_german.lang:
user_age=Alter
Extract of orxonox.ini:
language_="german"
Resulting output:
Alter: 20
Adding a new language
Simply copy translation_default.lang and rename it to translation_xxxxx.lang where xxxxx is the name of your new language. Then translate all entries in the file.
An entry has the following form:
label=fallback string
Change it to:
label=translated string
Now you can change the config-value language_ to "xxxxx" in orxonox.ini. The translated entries should now be used in the game.