Emergency 2017 Dokumentation  v3.0.1
qsf::Translator Class Reference

Translator class. More...

#include <Translator.h>

Public Member Functions

LocalizationSystemgetLocalizationSystem () const
 Return the owner localization system. More...
 
bool loadByFilename (const std::string &filename)
 Load a translator by using a given filename. More...
 
bool saveByFilename (const std::string &filename)
 Save the translator by using a given filename. More...
 
const std::string & getFilename () const
 Return the filename of the translator. More...
 
const std::string & getLanguage () const
 Return the language. More...
 
void setLanguage (const std::string &language)
 Set the language. More...
 
LocalizationContextcreateLocalizationContext ()
 Create a new localization context instance. More...
 
void destroyLocalizationContext (LocalizationContext &localizationContext)
 Destroy a given localization context instance. More...
 
void destroyAllLocalizationContexts ()
 Destroy all localization contexts within this translator. More...
 
const std::vector< LocalizationContext * > & getLocalizationContexts () const
 Return the list of currently loaded localization contexts. More...
 

Friends

class LocalizationSystem
 

Additional Inherited Members

- Protected Member Functions inherited from qsf::Manager
 Manager ()
 Default constructor. More...
 
virtual ~Manager ()
 Destructor. More...
 

Detailed Description

Translator class.

Remarks
A translator is a collection of localization context instances. Translators are completely independent from each other and each translator is serialized by using its own file.

The translator is reusing the Qt internationalization infrastructure. The Qt translation class is named "QTranslator", so the class name "Translator" was chosen to highlight that we're basically using the Qt way of handling localization. Meaning we don't introduce new proprietary localization file formats. Instead, we're using Qt's XML "ts" file format. This way we can use the Qt tools "lupdate" and especially "linguist" in order to streamline the localization process.

Definition at line 51 of file Translator.h.

Member Function Documentation

LocalizationContext* qsf::Translator::createLocalizationContext ( )

Create a new localization context instance.

Returns
The created localization context instance, null pointer on error, don't destroy the returned instance
void qsf::Translator::destroyAllLocalizationContexts ( )

Destroy all localization contexts within this translator.

void qsf::Translator::destroyLocalizationContext ( LocalizationContext localizationContext)

Destroy a given localization context instance.

Parameters
[in]localizationContextThe localization context instance to destroy, after this method call this instance is no longer valid
const std::string & qsf::Translator::getFilename ( ) const
inline

Return the filename of the translator.

Returns
The UTF-8 filename in platform-independent notation of the translator, do no destroy the returned instance
Note
  • There's no "setFilename()"-method by intent

Definition at line 27 of file Translator-inl.h.

const std::string & qsf::Translator::getLanguage ( ) const
inline

Return the language.

Returns
The UTF-8 language, e.g. "en"

Definition at line 32 of file Translator-inl.h.

const std::vector< LocalizationContext * > & qsf::Translator::getLocalizationContexts ( ) const
inline

Return the list of currently loaded localization contexts.

Returns
Reference to the internal list of currently loaded localization context, do not manipulate the list or destroy the localization contexts

Definition at line 42 of file Translator-inl.h.

LocalizationSystem & qsf::Translator::getLocalizationSystem ( ) const
inline

Return the owner localization system.

Returns
The owner localization system, do not destroy the instance

Definition at line 20 of file Translator-inl.h.

bool qsf::Translator::loadByFilename ( const std::string &  filename)

Load a translator by using a given filename.

Parameters
[in]filenameUTF-8 filename in platform-independent notation of the translator to load
Returns
"true" if all went fine, else "false" (file not found?)
Note
  • The current translator content will get lost, so, you might want to save a manipulated translator before loading a new one
  • On success, automatically makes the given filename to the internally stored translator filename
Todo:
  • TODO(co) For now, we only support Qt XML ts
bool qsf::Translator::saveByFilename ( const std::string &  filename)

Save the translator by using a given filename.

Parameters
[in]filenameUTF-8 filename in platform-independent notation of the translator to save
Returns
"true" if all went fine, else "false"
Note
  • On success, automatically makes the given filename to the internally stored translator filename
Todo:
  • TODO(co) For now, we only support Qt XML ts
void qsf::Translator::setLanguage ( const std::string &  language)
inline

Set the language.

Parameters
[in]languageThe UTF-8 language to set, e.g. "en"

Definition at line 37 of file Translator-inl.h.

Friends And Related Function Documentation

friend class LocalizationSystem
friend

Definition at line 58 of file Translator.h.


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