Torc  0.1
torclanguage.h
Go to the documentation of this file.
1 #ifndef TORCLANGUAGE_H
2 #define TORCLANGUAGE_H
3 
4 // Qt
5 #include <QMap>
6 #include <QObject>
7 #include <QLocale>
8 #include <QTranslator>
9 #include <QReadWriteLock>
10 
11 // Torc
12 #include "torcsetting.h"
13 #include "torchttpservice.h"
14 
15 #define DEFAULT_QT_LANGUAGE (QLocale::AnyLanguage)
16 
17 class TorcLanguage : public QObject, public TorcHTTPService
18 {
19  Q_OBJECT
20  Q_CLASSINFO("Version", "1.0.0")
21  Q_PROPERTY(QString languageCode READ GetLanguageCode NOTIFY LanguageCodeChanged)
22  Q_PROPERTY(QString languageString READ GetLanguageString NOTIFY LanguageStringChanged)
23 
24  public:
25  static QMap<QString,int> gLanguageMap;
26  static QString ToString (QLocale::Language Language, bool Empty = false);
27  static QLocale::Language From2CharCode (const char *Code);
28  static QLocale::Language From2CharCode (const QString &Code);
29  static QLocale::Language From3CharCode (const char *Code);
30  static QLocale::Language From3CharCode (const QString &Code);
31 
32  public:
33  explicit TorcLanguage(TorcSetting *SettingParent);
34  virtual ~TorcLanguage();
35 
36  QLocale GetLocale (void);
37  QString GetUIName (void);
38 
39  signals:
40  void LanguageCodeChanged (QString &Language);
41  void LanguageStringChanged (QString &String);
42 
43  public slots:
44  void LanguageSettingChanged(QString &Language);
45  void SetLanguageCode (const QString &Language);
46  QString GetLanguageCode (void);
47  QString GetLanguageString (void);
48  QString GetTranslation (const QString &Context, const QString &String,
49  const QString &Disambiguation, int Number);
50  void SubscriberDeleted (QObject *Subscriber);
51 
52  private:
53  void InitialiseTranslations (void);
54  static void Initialise (void);
55 
56  private:
57  Q_DISABLE_COPY(TorcLanguage)
58  TorcSetting *m_languageSetting;
59  QString languageCode;
60  QString languageString;
61  QLocale m_locale;
62  QList<QLocale> m_languages;
63  QTranslator m_translator;
64 };
65 
67 {
68  public:
69  TorcStringFactory();
70  virtual ~TorcStringFactory() = default;
71 
72  static QVariantMap GetTorcStrings (void);
73  static TorcStringFactory* GetTorcStringFactory (void);
74  TorcStringFactory* NextFactory (void) const;
75 
76  virtual void GetStrings (QVariantMap &Strings) = 0;
77 
78  protected:
79  static TorcStringFactory* gTorcStringFactory;
80  TorcStringFactory* nextTorcStringFactory;
81 
82  private:
83  Q_DISABLE_COPY(TorcStringFactory)
84 };
85 
86 #endif // TORCLANGUAGE_H
QLocale GetLocale(void)
A wrapper around a database setting.
Definition: torcsetting.h:15
static QLocale::Language From2CharCode(const char *Code)
Return the language associated with the given 2 character code.
void SetLanguageCode(const QString &Language)
Set the current language for this application.
static QMap< QString, int > gLanguageMap
Definition: torclanguage.h:25
void LanguageCodeChanged(QString &Language)
void LanguageSettingChanged(QString &Language)
A class to track and manage language and locale settings and available translations.
Definition: torclanguage.h:17
QString GetLanguageString(void)
QString languageString
Definition: torclanguage.h:22
TorcStringFactory * nextTorcStringFactory
Definition: torclanguage.h:80
static TorcStringFactory * gTorcStringFactory
Definition: torclanguage.h:79
QString GetLanguageCode(void)
Return the current language.
QString languageCode
Definition: torclanguage.h:21
QString GetTranslation(const QString &Context, const QString &String, const QString &Disambiguation, int Number)
A factory class to register translatable strings for use with external interfaces/applications.
Definition: torclanguage.h:66
QString GetUIName(void)
void LanguageStringChanged(QString &String)
static QLocale::Language From3CharCode(const char *Code)
Return the language associated with the given 3 character code.
void SubscriberDeleted(QObject *Subscriber)
static QString ToString(QLocale::Language Language, bool Empty=false)
Return a user readable string for the current language.