CrystalSpace

Public API Reference

iTranslator Struct Reference

Translator interface. More...

#include <ivaria/translator.h>

Inheritance diagram for iTranslator:

List of all members.

Public Member Functions

virtual const char * GetCurrentLanguage () const =0
 Get the current language.
virtual csPtr< iStringArrayGetFallbacks (const char *language) const =0
 Get the list of fallback languages defined for the given language.
virtual const char * GetMsg (const char *src, bool fallback=true) const =0
 Get the translation of the given source message.
virtual bool LoadTranslation (const char *file, iLoaderPlugin *loader=nullptr)=0
 Utility method to load the translation data from the given file.
virtual void SetCurrentLanguage (const char *language)=0
 Set the current language.

Detailed Description

Translator interface.

It can be used to translate one message to another using a predefined dictionary and the current system language. The dictionary can be initialized eg with successive calls to the method LoadTranslation().

The configuration of the iTranslator is defined in the VFS file '/config/translator.cfg'.

Definition at line 37 of file translator.h.


Member Function Documentation

virtual const char* iTranslator::GetCurrentLanguage (  )  const [pure virtual]

Get the current language.

Languages are represented by their two letters language code. The default language is 'en' (for English), but may be overwritten within the configuration file.

virtual csPtr<iStringArray> iTranslator::GetFallbacks ( const char *  language  )  const [pure virtual]

Get the list of fallback languages defined for the given language.

If no dictionary is found when searching for the current language, then the fallback languages should be used instead, in the given priority order.

virtual const char* iTranslator::GetMsg ( const char *  src,
bool  fallback = true 
) const [pure virtual]

Get the translation of the given source message.

There are two main fallback policies that you can use when the given message is not found in the dictionary: either use the source message as the fallback, or implement by yourself a more complex behavior. The first policy is the simplest to implement but has several drawbacks:

  • It won't allow the use of synonyms, that is, one sentence that can have several different translations depending on the context.
  • It is not memory efficient since there are no limits on the size of the key messages, and they can therefore turn pretty long.
  • It is not flexible since every time you tweak a source message, you would need to report the exact same changes in all translation dictionaries.
Parameters:
src The source message to be used as the key of translation.
fallback Whether the value returned should fallback to src or to nullptr if the source message is not found in the translation dictionary.
virtual bool iTranslator::LoadTranslation ( const char *  file,
iLoaderPlugin loader = nullptr 
) [pure virtual]

Utility method to load the translation data from the given file.

Only the translation data of the language returned by GetCurrentLanguage() will be loaded.

Parameters:
file The VFS path of the file to be loaded.
loader The translator loader plugin to be used. If none are provided then the default one will be used.
virtual void iTranslator::SetCurrentLanguage ( const char *  language  )  [pure virtual]

Set the current language.

Languages are represented by their two letters language code.


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

Generated for Crystal Space 2.1 by doxygen 1.6.1