Stellarium 0.13.2
StelTranslator.hpp
Go to the documentation of this file.
1 /*
2 * Stellarium
3 * Copyright (C) 2005 Fabien Chereau
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19 
20 #ifndef _STELTRANSLATOR_HPP_
21 #define _STELTRANSLATOR_HPP_
22 
25 
26 #include <QMap>
27 #include <QString>
28 
32 #define q_(str) StelTranslator::globalTranslator->qtranslate(str)
33 
37 #define qc_(str, ctxt) StelTranslator::globalTranslator->qtranslate(str, ctxt)
38 
42 #define N_(str) str
43 
50 {
51 public:
52 
60  StelTranslator(const QString& adomain, const QString& alangName);
61 
62  ~StelTranslator();
63 
68  QString qtranslate(const QString& s, const QString& c = QString()) const;
69 
72  const QString& getTrueLocaleName() const
73  {
74  if (langName=="system" || langName=="system_default")
75  return StelTranslator::systemLangName;
76  else
77  return langName;
78  }
79 
82 
84  QStringList getAvailableLanguagesNamesNative(const QString& localeDir="") const;
85 
88  static QString iso639_1CodeToNativeName(const QString& languageCode);
89 
91  static QString nativeNameToIso639_1Code(const QString& languageName);
92 
95  static void init(const QString& fileName);
96 
97 private:
99  const StelTranslator& operator=(const StelTranslator&);
100 
103  static void initIso639_1LanguageCodes(const QString& fileName);
104 
106  QStringList getAvailableIso639_1Codes(const QString& localeDir="") const;
107 
109  QString domain;
110 
112  QString langName;
113 
115  class QTranslator* translator;
116 
118  static void initSystemLanguage(void);
119 
121  static QString systemLangName;
122 
124  static QMap<QString, QString> iso639codes;
125 };
126 
127 #endif // _STELTRANSLATOR_HPP_
128 
const QString & getTrueLocaleName() const
Get true translator locale name.
Class used to translate strings to any language.
static QString nativeNameToIso639_1Code(const QString &languageName)
Convert from native language name to ISO639-1 2 letters langage code.
static QString iso639_1CodeToNativeName(const QString &languageCode)
Convert from ISO639-1 langage code to native language name.
static StelTranslator * globalTranslator
Used as a global translator by the whole app.
static void init(const QString &fileName)
Initialize Translation.
QStringList getAvailableLanguagesNamesNative(const QString &localeDir="") const
Get available language name in native language from passed locales directory.
StelTranslator(const QString &adomain, const QString &alangName)
Create a translator from a language name.
QString qtranslate(const QString &s, const QString &c=QString()) const
Translate input message and return it as a QString.