Stellarium  25.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes
StelTranslator Class Reference

Class used to translate strings to any language. More...

#include <StelTranslator.hpp>

Public Member Functions

 StelTranslator (const QString &adomain, const QString &alangName)
 Create a translator from a language name. More...
 
virtual bool isEmpty () const
 Checks whether any translations have been loaded.
 
QString qtranslate (const QString &s, const QString &c=QString()) const
 Translate input message and return it as a QString. More...
 
QString qTranslateStar (const QString &s, const QString &c=QString()) const
 Same as qtranslate, but with additional code to handle Chinese names of stars.
 
virtual QString tryQtranslate (const QString &s, const QString &c=QString()) const
 Try to translate input message and return it as a QString. More...
 
QString tryQtranslateStar (const QString &s, const QString &c=QString()) const
 Same as tryQtranslate, but with additional code to handle Chinese names of stars.
 
const QString & getTrueLocaleName () const
 Get true translator locale name. More...
 
QStringList getAvailableLanguagesNamesNative (const QString &localeDir="", const QString &section="") const
 Get available language name in native language from passed locales directory.
 

Static Public Member Functions

static QString iso639_1CodeToNativeName (const QString &languageCode)
 Convert from ISO639-1 language code to native language name. More...
 
static QString nativeNameToIso639_1Code (const QString &languageName)
 Convert from native language name to ISO639-1 2 letters language code.
 
static void init (const QString &fileName)
 Initialize Translation. More...
 

Static Public Attributes

static StelTranslatorglobalTranslator
 Used as a global translator by the whole app.
 

Protected Attributes

QString domain
 The domain name.
 
QString langName
 The two letter string defining the current language name.
 
class QTranslator * translator = nullptr
 QTranslator instance.
 

Detailed Description

Class used to translate strings to any language.

Implements a nice interface to gettext which is UTF-8 compliant and is somewhat multiplateform All its operations do not modify the global locale. The purpose of this class is to remove all non-OO C locale functions from stellarium.

Author
Fabien Chereau

Constructor & Destructor Documentation

◆ StelTranslator()

StelTranslator::StelTranslator ( const QString &  adomain,
const QString &  alangName 
)

Create a translator from a language name.

If the passed locale name cannot be handled by the system, default value will be used. The passed language name is a language code string like "fr" or "fr_FR". This class wrap gettext to simulate an object oriented multiplateform gettext UTF8 translator

Parameters
adomainThe name of the domain to use for translation
alangNameThe C locale name or language name like "fr" or "fr_FR". If string is "" or "system" it will use the system locale.

Member Function Documentation

◆ getTrueLocaleName()

const QString& StelTranslator::getTrueLocaleName ( ) const
inline

Get true translator locale name.

Actual locale, never "system".

Returns
Locale name e.g "fr_FR"

◆ init()

static void StelTranslator::init ( const QString &  fileName)
static

Initialize Translation.

Parameters
fileNamefile containing the list of language codes

◆ iso639_1CodeToNativeName()

static QString StelTranslator::iso639_1CodeToNativeName ( const QString &  languageCode)
static

Convert from ISO639-1 language code to native language name.

Parameters
languageCodethe code to look up

◆ qtranslate()

QString StelTranslator::qtranslate ( const QString &  s,
const QString &  c = QString() 
) const

Translate input message and return it as a QString.

If the string is not translated in the current locale, the input string is returned unchanged.

Parameters
sinput string in english.
cdisambiguation string (gettext "context" string).
Returns
The translated QString

◆ tryQtranslate()

virtual QString StelTranslator::tryQtranslate ( const QString &  s,
const QString &  c = QString() 
) const
virtual

Try to translate input message and return it as a QString.

If no translation exist for the current StelTranslator language, a null string is returned.

Parameters
sinput string in english.
cdisambiguation string (gettext "context" string).
Returns
The translated QString

Reimplemented in StelSkyTranslator.