Changes between Version 6 and Version 7 of code/doc/Language
- Timestamp:
- Sep 29, 2008, 4:03:14 AM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/doc/Language
v6 v7 4 4 == Description == 5 5 6 The [wiki:Language] is a [wiki:singleton] that handles strings in different languages. It replaces hardcoded strings by labeled strings, where the coder only uses the label and the [wiki:Language]searches for the localised string in the [wiki:ConfigValueContainer 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 [wiki:ConfigValueContainer config-file].6 Language is a [wiki: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 [wiki:ConfigValueContainer 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 [wiki:ConfigValueContainer config-file]. 7 7 8 8 A new language-entry can be added with the !AddLanguageEntry(label, fallbackstring) macro and the localisation can be retrieved with !GetLocalisation(label). 9 9 10 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 [wiki:Language#Addinganewlanguage ] for more information about this.10 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 [wiki:Language#Addinganewlanguage the chapter at the end] for more information about this. 11 11 12 12 == Macros == 13 13 14 * '''!AddLanguageEntry('''''label''''', '''''fallbackstring''''')''': Adds a new entry to the [wiki:Language]by defining a unique label and a fallback string that gets used in case there is no localisation.14 * '''!AddLanguageEntry('''''label''''', '''''fallbackstring''''')''': 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. 15 15 * '''!GetLocalisation('''''label''''')''': Returns the localisation of the given label. 16 16 17 17 == Functions == 18 18 19 * '''getLanguage()''': Returns a reference to the only existing instance of the [wiki:Language]class.20 * '''addEntry('''''label''''', '''''fallback string''''')''': Adds a new entry to the [wiki:Language]by defining a unique label and a fallback string that gets used in case there is no localisation.19 * '''getLanguage()''': Returns a reference to the only existing instance of the Language class. 20 * '''addEntry('''''label''''', '''''fallbackstring''''')''': 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. 21 21 * '''getLocalisation('''''label''''')''': Returns the localisation of the given label. 22 22 … … 28 28 // Displays the users age 29 29 int age = 20; 30 Language::getLanguage().addEntry("user_age", "Age");31 std::cout << Language::getLanguage().getLocalisation("user_age") << ": " << age << std::endl;30 AddLanguageEntry("user_age", "Age"); 31 std::cout << GetLocalisation("user_age") << ": " << age << std::endl; 32 32 }}} 33 33 … … 67 67 68 68 Now you can change the config-value ''language_'' to "''xxxxx''" in orxonox.ini. The translated entries should now be used in the game. 69 70 '''Attention''': Language entries are only added to the file if they are at least once executed. Otherwise you wont find them in the file. If you need a complete translation, you have to search the code for all entries. If you know a better solution, just tell me. ;)