You.i Engine
CYITranslation Class Reference

Detailed Description

Provides string localization.

String localization is performed using GNU's "gettext" utility.

Overview of You.i Engine's localization steps: 1 - The software is written in English. Other "key languages" are possible as well, but they have to use ASCII characters only. 2 - Translatable strings are marked in the source code by a special function YiTranslate or YiTranslateMarker. 3 - A special tool called "xgettext" extracts all translatable strings and collects them in one file, which is named "testproj.pot". 4 - If a new language, or translation target, is added, this file is copied to <locale>.po, where <locale> denotes the language; see CYILocale for details 5 - The <locale>.po files are then translated by a human translator. Various tools are available to assist the translator. The target language can use any unicode encoding, although UTF-8 is recommended. Translated strings are added into the <locale>.po file below the original English string. 6 - When the source code has changed, the "xgettext" utility should recreate the testproj.pot file. This file must be merged with the <locale>.po file using the tool "msgmerge." The merged <locale>.po's should be checked by the human translator to make sure they are correct. Some tools eliminate or highlight duplicate strings from the merged files. 7 - The <locale>.po files now need to be compiled into <locale>.mo files by another tool called "msgfmt." The resulting ".mo" files are are binary equivalents to the ".po" files. 8 - During the You.i Engine application package creation process, these <locale>.mo files are copied into the "assets/text/<locale>/" directory. 9 - At run time, You.i Engine tries to find the correct ".mo" file. Each string to be displayed is passed through the YiTranslate function, which now looks for the translation. If no translation exists (if there is no ".mo" file or if the string is not translated), the English string is used.

Overview of You.i Engine tools:

  • tools/localization contains a script to simplyfy gettext processing (runGetText.rb)
  • tools/localization/Win32 contains binary files for running gettext under a Windows environment
  • runGetText.rb has three functions:
  • 'runGetText.rb parse' - parses ".cpp" and exported After Effects layouts for translatable text generating a ".pot" file (2)
  • 'runGetText.rb generate' - generates new and updates existing ".po" files
  • 'runGetText.rb compile' - compiles ".po" files into ".mo" files (7)
See also

#include <utility/YiTranslation.h>

Public Member Functions

 CYITranslation ()
 CYITranslation (const CYITranslation &rOther)
virtual ~CYITranslation ()
CYITranslationoperator= (const CYITranslation &rOther)
std::shared_ptr< CYITranslatorGetTranslator () const
void SetTranslator (const std::shared_ptr< CYITranslator > &pTranslator)
CYIString Translate (const CYIString &text)

Constructor & Destructor Documentation

◆ CYITranslation() [1/2]

CYITranslation::CYITranslation ( )

◆ CYITranslation() [2/2]

CYITranslation::CYITranslation ( const CYITranslation rOther)

◆ ~CYITranslation()

virtual CYITranslation::~CYITranslation ( )

Member Function Documentation

◆ GetTranslator()

std::shared_ptr<CYITranslator> CYITranslation::GetTranslator ( ) const

Returns the current translator object; the default is CYIMOTranslator.

◆ operator=()

CYITranslation& CYITranslation::operator= ( const CYITranslation rOther)

◆ SetTranslator()

void CYITranslation::SetTranslator ( const std::shared_ptr< CYITranslator > &  pTranslator)

Sets the translator object to use; providing a null object pointer will cause the translator to be disabled.

◆ Translate()

CYIString CYITranslation::Translate ( const CYIString text)

Uses the text string as a key for the translator to retreive the localised string from the translation table. If the translator is null or if the translation table is empty, the original string will be returned. If the key cannot be found in the translation table, the default string "<missing>" will be returned.

The documentation for this class was generated from the following file: