Torc  0.1
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Properties | List of all members
TorcLanguage Class Reference

A class to track and manage language and locale settings and available translations. More...

#include <torclanguage.h>

Inheritance diagram for TorcLanguage:
[legend]

Public Slots

void LanguageSettingChanged (QString &Language)
 
void SetLanguageCode (const QString &Language)
 Set the current language for this application. More...
 
QString GetLanguageCode (void)
 Return the current language. More...
 
QString GetLanguageString (void)
 
QString GetTranslation (const QString &Context, const QString &String, const QString &Disambiguation, int Number)
 
void SubscriberDeleted (QObject *Subscriber)
 

Signals

void LanguageCodeChanged (QString &Language)
 
void LanguageStringChanged (QString &String)
 

Public Member Functions

 TorcLanguage (TorcSetting *SettingParent)
 
virtual ~TorcLanguage ()
 
QLocale GetLocale (void)
 
QString GetUIName (void)
 
- Public Member Functions inherited from TorcHTTPService
 TorcHTTPService (QObject *Parent, const QString &Signature, const QString &Name, const QMetaObject &MetaObject, const QString &Blacklist=QStringLiteral(""))
 
virtual ~TorcHTTPService ()
 
void ProcessHTTPRequest (const QString &PeerAddress, int PeerPort, const QString &LocalAddress, int LocalPort, TorcHTTPRequest &Request) override
 
QVariantMap ProcessRequest (const QString &Method, const QVariant &Parameters, QObject *Connection, bool Authenticated) override
 
QString GetMethod (int Index)
 
QVariant GetProperty (int Index)
 Get the value of a given property. More...
 
QVariantMap GetServiceDetails (void)
 Return a QVariantMap describing the services methods and properties. More...
 
virtual QString GetPresentationURL (void)
 
- Public Member Functions inherited from TorcHTTPHandler
 TorcHTTPHandler (const QString &Signature, const QString &Name)
 
virtual ~TorcHTTPHandler ()
 
QString Signature (void) const
 
bool GetRecursive (void) const
 
QString Name (void) const
 

Static Public Member Functions

static QString ToString (QLocale::Language Language, bool Empty=false)
 Return a user readable string for the current language. More...
 
static QLocale::Language From2CharCode (const char *Code)
 Return the language associated with the given 2 character code. More...
 
static QLocale::Language From2CharCode (const QString &Code)
 Return the language associated with the given 2 character code. More...
 
static QLocale::Language From3CharCode (const char *Code)
 Return the language associated with the given 3 character code. More...
 
static QLocale::Language From3CharCode (const QString &Code)
 Return the language associated with the given 3 character code. More...
 

Static Public Attributes

static QMap< QString, int > gLanguageMap
 

Properties

QString languageCode
 
QString languageString
 

Additional Inherited Members

- Protected Member Functions inherited from TorcHTTPService
void HandleSubscriberDeleted (QObject *Subscriber)
 
- Static Protected Member Functions inherited from TorcHTTPHandler
static bool MethodIsAuthorised (TorcHTTPRequest &Request, int Allowed)
 Check the current request is authorised and set the authentication header if not. More...
 
static void HandleOptions (TorcHTTPRequest &Request, int Allowed)
 
static void HandleFile (TorcHTTPRequest &Request, const QString &Filename, int Cache)
 
- Protected Attributes inherited from TorcHTTPService
QReadWriteLock m_httpServiceLock
 
- Protected Attributes inherited from TorcHTTPHandler
QString m_signature
 
bool m_recursive
 
QString m_name
 

Detailed Description

A class to track and manage language and locale settings and available translations.

TorcLanguage uses the 2 or 4 character language/country code to identify a language (e.g. en_GB, en_US, en). If a specific language has not been set in the settings database, the system language will be used (with a final fallback to en_GB). The current language can be set with SetLanguageCode and retrieved with GetLanguageCode. GetLanguageString returns a translated, user presentable string naming the language.

GetLanguages returns a list of available translations.

GetTranslation provides a context sensitive translation service for strings. It is intended for dynamically translated strings (e.g. plurals) retrieved via the HTTP interface. Other strings should be loaded once only.

Various utility functions are available for interfacing with 3rd party libraries (From2CharCode etc).

TorcLanguage is available from QML via QAbstractListModel inheritance and from the HTTP interface via TorcHTTPService.

Todo:

Check whether QTranslator::load is thread safe.

Add support for multiple translation files (e.g. plugins as well ).

Definition at line 17 of file torclanguage.h.

Constructor & Destructor Documentation

TorcLanguage::TorcLanguage ( TorcSetting SettingParent)
explicit

Definition at line 57 of file torclanguage.cpp.

TorcLanguage::~TorcLanguage ( )
virtual

Definition at line 90 of file torclanguage.cpp.

Member Function Documentation

QLocale::Language TorcLanguage::From2CharCode ( const char *  Code)
static

Return the language associated with the given 2 character code.

Definition at line 193 of file torclanguage.cpp.

QLocale::Language TorcLanguage::From2CharCode ( const QString &  Code)
static

Return the language associated with the given 2 character code.

Definition at line 199 of file torclanguage.cpp.

QLocale::Language TorcLanguage::From3CharCode ( const char *  Code)
static

Return the language associated with the given 3 character code.

Definition at line 213 of file torclanguage.cpp.

QLocale::Language TorcLanguage::From3CharCode ( const QString &  Code)
static

Return the language associated with the given 3 character code.

Definition at line 219 of file torclanguage.cpp.

QString TorcLanguage::GetLanguageCode ( void  )
slot

Return the current language.

Definition at line 154 of file torclanguage.cpp.

QString TorcLanguage::GetLanguageString ( void  )
slot

Definition at line 166 of file torclanguage.cpp.

QLocale TorcLanguage::GetLocale ( void  )

Definition at line 160 of file torclanguage.cpp.

QString TorcLanguage::GetTranslation ( const QString &  Context,
const QString &  String,
const QString &  Disambiguation,
int  Number 
)
slot

Definition at line 172 of file torclanguage.cpp.

QString TorcLanguage::GetUIName ( void  )
virtual

Reimplemented from TorcHTTPService.

Definition at line 103 of file torclanguage.cpp.

void TorcLanguage::LanguageCodeChanged ( QString &  Language)
signal
void TorcLanguage::LanguageSettingChanged ( QString &  Language)
slot

Definition at line 97 of file torclanguage.cpp.

void TorcLanguage::LanguageStringChanged ( QString &  String)
signal
void TorcLanguage::SetLanguageCode ( const QString &  Language)
slot

Set the current language for this application.

Definition at line 111 of file torclanguage.cpp.

void TorcLanguage::SubscriberDeleted ( QObject *  Subscriber)
slot

Definition at line 178 of file torclanguage.cpp.

QString TorcLanguage::ToString ( QLocale::Language  Language,
bool  Empty = false 
)
static

Return a user readable string for the current language.

Definition at line 184 of file torclanguage.cpp.

Member Data Documentation

QMap< QString, int > TorcLanguage::gLanguageMap
static

Definition at line 25 of file torclanguage.h.

Property Documentation

QString TorcLanguage::languageCode
read

Definition at line 21 of file torclanguage.h.

QString TorcLanguage::languageString
read

Definition at line 22 of file torclanguage.h.


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