Mapper  0.9.0
API documentation
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
OpenOrienteering::TranslationUtil Class Reference

A simplified interface to searching and loading translations. More...

#include <translation_util.h>

Collaboration diagram for OpenOrienteering::TranslationUtil:
Collaboration graph
[legend]

Classes

struct  Language
 A struct for representing the language of a translation. More...
 

Public Types

using LanguageList = std::vector< Language >
 A collection of languages. More...
 

Public Member Functions

 TranslationUtil ()
 Creates a new translation utility for the file or language from the settings. More...
 
 TranslationUtil (const QSettings &settings)
 Creates a new translation utility for the file or language from the given settings. More...
 
 TranslationUtil (const QString &code, QString translation_file={})
 Creates a new translation utility for the given language. More...
 
QString code () const
 Returns the code of the language. More...
 
QString displayName () const
 Returns the display name of the language. More...
 
QTranslatorgetQtTranslator ()
 Returns a translator for Qt strings. More...
 
QTranslatorgetAppTranslator ()
 Returns a translator for application strings. More...
 
std::unique_ptr< QTranslatorload (const QString &translation_name) const
 Tries to create a QTranslator for the named translation. More...
 

Static Public Member Functions

static void setBaseName (const QLatin1String &name)
 Sets the common base name of the application's translation files. More...
 
static LanguageList availableLanguages ()
 Returns a collection of available languages for this application. More...
 
static Language languageFromFilename (const QString &path)
 Returns the language for a given translation file. More...
 
static Language languageFromCode (const QString &code)
 Returns the language for a language name. More...
 
static Language languageFromSettings (const QSettings &settings)
 Returns the language for the given settings object. More...
 

Protected Member Functions

bool load (QTranslator &translator, const QString &translation_name) const
 Finds a named translation from the search path and loads it to the translator. More...
 

Protected Attributes

Language language
 
QTranslator qt_translator
 
QTranslator app_translator
 

Static Protected Attributes

static QString base_name
 

Detailed Description

A simplified interface to searching and loading translations.

Member Typedef Documentation

◆ LanguageList

A collection of languages.

Constructor & Destructor Documentation

◆ TranslationUtil() [1/3]

OpenOrienteering::TranslationUtil::TranslationUtil ( )

Creates a new translation utility for the file or language from the settings.

The base name of the translation files must be set in advance.

◆ TranslationUtil() [2/3]

OpenOrienteering::TranslationUtil::TranslationUtil ( const QSettings settings)

Creates a new translation utility for the file or language from the given settings.

The base name of the translation files must be set in advance.

◆ TranslationUtil() [3/3]

OpenOrienteering::TranslationUtil::TranslationUtil ( const QString code,
QString  translation_file = {} 
)

Creates a new translation utility for the given language.

The base name of the translation files must be set in advance.

Member Function Documentation

◆ availableLanguages()

TranslationUtil::LanguageList OpenOrienteering::TranslationUtil::availableLanguages ( )
static

Returns a collection of available languages for this application.

◆ code()

QString OpenOrienteering::TranslationUtil::code ( ) const
inline

Returns the code of the language.

◆ displayName()

QString OpenOrienteering::TranslationUtil::displayName ( ) const
inline

Returns the display name of the language.

◆ getAppTranslator()

QTranslator& OpenOrienteering::TranslationUtil::getAppTranslator ( )
inline

Returns a translator for application strings.

◆ getQtTranslator()

QTranslator& OpenOrienteering::TranslationUtil::getQtTranslator ( )
inline

Returns a translator for Qt strings.

◆ languageFromCode()

TranslationUtil::Language OpenOrienteering::TranslationUtil::languageFromCode ( const QString code)
static

Returns the language for a language name.

◆ languageFromFilename()

TranslationUtil::Language OpenOrienteering::TranslationUtil::languageFromFilename ( const QString path)
static

Returns the language for a given translation file.

◆ languageFromSettings()

TranslationUtil::Language OpenOrienteering::TranslationUtil::languageFromSettings ( const QSettings settings)
static

Returns the language for the given settings object.

◆ load() [1/2]

std::unique_ptr< QTranslator > OpenOrienteering::TranslationUtil::load ( const QString translation_name) const

Tries to create a QTranslator for the named translation.

If the named translation cannot be loaded from the search path, returns an unset unique_prt.

◆ load() [2/2]

bool OpenOrienteering::TranslationUtil::load ( QTranslator translator,
const QString translation_name 
) const
protected

Finds a named translation from the search path and loads it to the translator.

◆ setBaseName()

void OpenOrienteering::TranslationUtil::setBaseName ( const QLatin1String name)
static

Sets the common base name of the application's translation files.

Member Data Documentation

◆ app_translator

QTranslator OpenOrienteering::TranslationUtil::app_translator
protected

◆ base_name

QString OpenOrienteering::TranslationUtil::base_name
staticprotected

◆ language

Language OpenOrienteering::TranslationUtil::language
protected

◆ qt_translator

QTranslator OpenOrienteering::TranslationUtil::qt_translator
protected

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