Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/Language


Ignore:
Timestamp:
Feb 27, 2008, 12:37:56 AM (17 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Language

    v1 v1  
     1= Language =
     2
     3== Description ==
     4
     5The [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
     7All 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#Adding_a_new_language] for more informations about this.
     8
     9== Functions ==
     10
     11 * '''getLanguage()''': Returns a reference to the only existing instance of the [wiki:Language] class.
     12 * '''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.
     13 * '''getLocalisation('''''label''''')''': Returns the localisation of the given label.
     14
     15== Example ==
     16
     17Piece of code:
     18{{{
     19#!cpp
     20// Displays the users age
     21int age = 20;
     22Language::getLanguage().addEntry("user_age", "Age");
     23std::cout << Language::getLanguage().getLocalisation("user_age") << ": " << age << std::endl;
     24}}}
     25
     26Extract of translation_default.lang:
     27{{{
     28user_age=Age
     29}}}
     30
     31Extract of translation_german.lang:
     32{{{
     33user_age=Alter
     34}}}
     35
     36Extract of orxonox.ini:
     37{{{
     38language_="german"
     39}}}
     40
     41Resulting output:
     42{{{
     43Alter: 20
     44}}}
     45
     46== Adding a new language ==
     47
     48Simply 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.
     49
     50An entry has the following form:
     51{{{
     52label=fallback string
     53}}}
     54
     55Change it to:
     56{{{
     57label=translated string
     58}}}
     59
     60Now you can change the config-value ''language_'' to "''xxxxx''" in orxonox.ini. The translated entries should now be used in the game.