Cppcheck
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
TranslationHandler Class Reference

A class handling the available translations. More...

#include <translationhandler.h>

Inheritance diagram for TranslationHandler:

Public Member Functions

 TranslationHandler (QObject *parent=nullptr)
 
const QList< TranslationInfo > & getTranslations () const
 Get a list of available translations. More...
 
bool setLanguage (const QString &code)
 Set active translation. More...
 
const QString & getCurrentLanguage () const
 Get currently selected translation. More...
 
QString suggestLanguage () const
 Get translation suggestion for the system. More...
 

Protected Member Functions

void addTranslation (const char *name, const char *filename)
 Add new translation to list of available translations. More...
 
int getLanguageIndexByCode (const QString &code) const
 Find language in the list and return its index. More...
 

Private Attributes

QString mCurrentLanguage
 ISO 639 language code of the currently selected translation. More...
 
QList< TranslationInfomTranslations
 List of available translations. More...
 
QTranslator * mTranslator {}
 Translator class instance. More...
 

Detailed Description

A class handling the available translations.

This class contains a list of available translations. The class also keeps track which translation is the currently active translation.

Definition at line 62 of file translationhandler.h.

Constructor & Destructor Documentation

◆ TranslationHandler()

TranslationHandler::TranslationHandler ( QObject *  parent = nullptr)
explicit

Definition at line 43 of file translationhandler.cpp.

References addTranslation().

Member Function Documentation

◆ addTranslation()

void TranslationHandler::addTranslation ( const char *  name,
const char *  filename 
)
protected

Add new translation to list of available translations.

Parameters
nameName of the translation ("English").
filenameFilename of the translation.

Definition at line 167 of file translationhandler.cpp.

References TranslationInfo::mCode, TranslationInfo::mFilename, TranslationInfo::mName, and mTranslations.

Referenced by TranslationHandler().

◆ getCurrentLanguage()

const QString & TranslationHandler::getCurrentLanguage ( ) const

Get currently selected translation.

Returns
ISO 639 language code for current translation.

Definition at line 145 of file translationhandler.cpp.

References mCurrentLanguage.

Referenced by SettingsDialog::initTranslationsList(), MainWindow::saveSettings(), and MainWindow::setLanguage().

◆ getLanguageIndexByCode()

int TranslationHandler::getLanguageIndexByCode ( const QString &  code) const
protected

Find language in the list and return its index.

Parameters
codeISO 639 language code.
Returns
Index at list, or -1 if not found.

Definition at line 177 of file translationhandler.cpp.

References mTranslations.

Referenced by setLanguage(), and suggestLanguage().

◆ getTranslations()

const QList<TranslationInfo>& TranslationHandler::getTranslations ( ) const
inline

Get a list of available translations.

Returns
List of available translations.

Definition at line 72 of file translationhandler.h.

References mTranslations.

Referenced by SettingsDialog::initTranslationsList().

◆ setLanguage()

bool TranslationHandler::setLanguage ( const QString &  code)

Set active translation.

Parameters
codeISO 639 language code for new selected translation.
Returns
true if succeeds, false otherwise.

Definition at line 65 of file translationhandler.cpp.

References error, getDataDir(), getLanguageIndexByCode(), mCurrentLanguage, mTranslations, and mTranslator.

Referenced by MainWindow::setLanguage().

◆ suggestLanguage()

QString TranslationHandler::suggestLanguage ( ) const

Get translation suggestion for the system.

This function checks the current system locale and determines which of the available translations is best as current translation. If none of the available translations is good then it returns English ("en").

Returns
Suggested translation ISO 639 language code.

Definition at line 150 of file translationhandler.cpp.

References getLanguageIndexByCode().

Member Data Documentation

◆ mCurrentLanguage

QString TranslationHandler::mCurrentLanguage
private

ISO 639 language code of the currently selected translation.

Definition at line 125 of file translationhandler.h.

Referenced by getCurrentLanguage(), and setLanguage().

◆ mTranslations

QList<TranslationInfo> TranslationHandler::mTranslations
private

List of available translations.

Definition at line 131 of file translationhandler.h.

Referenced by addTranslation(), getLanguageIndexByCode(), getTranslations(), and setLanguage().

◆ mTranslator

QTranslator* TranslationHandler::mTranslator {}
private

Translator class instance.

Definition at line 137 of file translationhandler.h.

Referenced by setLanguage().


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