KVIrc 5.2.6
Developer APIs
KviLocale Class Reference

Holds the localization functions. More...

#include <KviLocale.h>

+ Inheritance diagram for KviLocale:

Classes

struct  EncodingDescription
 

Public Member Functions

QTextCodec * codecForName (const char *pcName)
 Returns the codec associated to the given translation.
 
EncodingDescriptionencodingDescription (int iIdx)
 Returns the description of the encoding used.
 
const char * encodingGroup (int iIdx)
 Returns the description of the encoding used.
 
bool findCatalogue (QString &szBuffer, const QString &szName, const QString &szLocaleDir)
 Finds the catalogue.
 
KviMessageCataloguegetLoadedCatalogue (const QString &szName)
 Returns the loaded catalogue.
 
KviMessageCatalogueloadCatalogue (const QString &szName, const QString &szLocaleDir)
 Loads the catalogue.
 
const QString & localeName () const
 Returns the language code of the localization.
 
const char * translate (const char *pcText, const char *pcContext)
 Translates the given text from the given context.
 
const QString & translateToQString (const char *pcText, const char *pcContext)
 Translates the given text from the given context.
 
bool unloadCatalogue (const QString &szName)
 Unloads a catalogue.
 

Static Public Member Functions

static void done ()
 Destroys the class instance.
 
static void init (QApplication *pApp, const QString &szLocaleDir, const QString &szForceLocaleDir)
 Initializes the class instance.
 
static KviLocaleinstance ()
 Returns the instance of the class.
 

Static Public Attributes

static QString g_szLang = ""
 

Protected Member Functions

 KviLocale (QApplication *pApp, const QString &szLocaleDir, const QString &szForceLocaleDir)
 Constructs the KviLocale object.
 
 ~KviLocale ()
 Destroys the object.
 

Protected Attributes

QApplication * m_pApp
 

Static Private Attributes

static KviLocalem_pSelf = nullptr
 

Detailed Description

Holds the localization functions.

Constructor & Destructor Documentation

◆ KviLocale()

KviLocale::KviLocale ( QApplication * pApp,
const QString & szLocaleDir,
const QString & szForceLocaleDir )
protected

Constructs the KviLocale object.

Parameters
pAppThe main application
szLocaleDirThe directory containing the localizations
szForceLocaleDirThe directory forced by the user
Returns
KviLocale

References KviCString::cutFromFirst(), KviFileUtils::fileExists(), findCatalogue(), g_pCatalogueDict, g_pMainCatalogue, g_pSmartCodecDict, g_pTranslator, g_szDefaultLocalePath, g_szLang, KviEnvironment::getVariable(), KVI_FORCE_LOCALE_FILE_NAME, kvi_strEqualCI(), m_pApp, KviCString::ptr(), KviFileUtils::readFile(), szBuffer, and KviCString::toLower().

Referenced by init(), and instance().

◆ ~KviLocale()

KviLocale::~KviLocale ( )
protected

Destroys the object.

Returns
KviLocale

References g_pCatalogueDict, g_pMainCatalogue, g_pSmartCodecDict, g_pTranslator, and m_pApp.

Member Function Documentation

◆ codecForName()

◆ done()

void KviLocale::done ( )
static

Destroys the class instance.

Parameters
pAppThe main application
Returns
void

References m_pSelf.

Referenced by KviApplication::~KviApplication().

◆ encodingDescription()

KviLocale::EncodingDescription * KviLocale::encodingDescription ( int iIdx)

◆ encodingGroup()

const char * KviLocale::encodingGroup ( int iIdx)

Returns the description of the encoding used.

Parameters
iIdxThe index of the group
Warning
You MUST start iterating from 0 and terminate when you get an entry with a NULL value
Returns
const char *

References encoding_groups, and KVI_NUM_ENCODING_GROUPS.

Referenced by KviWindow::createSystemTextEncodingPopup().

◆ findCatalogue()

bool KviLocale::findCatalogue ( QString & szBuffer,
const QString & szName,
const QString & szLocaleDir )

Finds the catalogue.

This function attempts to determine the current locale and then load the corresponding translation file from the KVIrc locale directory. Returns true if the locale was correctly set; i.e. the locale is C or POSIX (no translation needed) or the locale is correctly defined and the translation map was successfully loaded

Parameters
szBufferThe buffer where to store the translation full path
szNameThe name of the translation file
szLocaleDirThe directory where the localizations are stored
Returns
bool

References KviCString::cutFromFirst(), KviQString::ensureLastCharIs(), KviFileUtils::fileExists(), KviCString::findFirstIdx(), g_szLang, KVI_PATH_SEPARATOR_CHAR, KviCString::ptr(), szBuffer, and KviCString::toLower().

Referenced by KviLocale(), and loadCatalogue().

◆ getLoadedCatalogue()

KviMessageCatalogue * KviLocale::getLoadedCatalogue ( const QString & szName)

Returns the loaded catalogue.

Parameters
szNameThe name of the catalogue to get
Returns
KviMessageCatalogue *

References g_pCatalogueDict.

Referenced by KviKvsCoreFunctions::KVSCF().

◆ init()

void KviLocale::init ( QApplication * pApp,
const QString & szLocaleDir,
const QString & szForceLocaleDir )
static

Initializes the class instance.

Parameters
pAppThe main application
szLocaleDirThe directory containing the localizations
szForceLocaleDirThe directory forced by the user
Returns
void

References KviLocale(), and m_pSelf.

Referenced by KviApplication::loadDirectories().

◆ instance()

◆ loadCatalogue()

KviMessageCatalogue * KviLocale::loadCatalogue ( const QString & szName,
const QString & szLocaleDir )

Loads the catalogue.

Parameters
szNameThe name of the catalogue
szLocaleDirThe directory where to look for the catalogue
Returns
KviMessageCatalogue *

References findCatalogue(), g_pCatalogueDict, KviMessageCatalogue::load(), and szBuffer.

Referenced by KviKvsCoreFunctions::KVSCF(), KviModuleManager::loadModule(), translate(), and translateToQString().

◆ localeName()

const QString & KviLocale::localeName ( ) const
inline

◆ translate()

const char * KviLocale::translate ( const char * pcText,
const char * pcContext )

Translates the given text from the given context.

Parameters
pcTextThe text to translate
pcContextThe context where to look for the text
Returns
const char *

References g_pCatalogueDict, g_pMainCatalogue, g_szDefaultLocalePath, loadCatalogue(), and KviMessageCatalogue::translate().

◆ translateToQString()

const QString & KviLocale::translateToQString ( const char * pcText,
const char * pcContext )

Translates the given text from the given context.

Parameters
pcTextThe text to translate
pcContextThe context where to look for the text
Returns
const QString &

References g_pCatalogueDict, g_pMainCatalogue, g_szDefaultLocalePath, loadCatalogue(), and KviMessageCatalogue::translateToQString().

◆ unloadCatalogue()

bool KviLocale::unloadCatalogue ( const QString & szName)

Unloads a catalogue.

Parameters
szNameThe catalogue to unload
Returns
bool

References g_pCatalogueDict.

Referenced by KviModuleManager::loadModule(), and KviModuleManager::unloadModule().

Member Data Documentation

◆ g_szLang

QString KviLocale::g_szLang = ""
static

◆ m_pApp

QApplication* KviLocale::m_pApp
protected

Referenced by KviLocale(), and ~KviLocale().

◆ m_pSelf

KviLocale * KviLocale::m_pSelf = nullptr
staticprivate

Referenced by done(), init(), and instance().


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