Stellarium 0.15.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 
69  QString qtranslate(const QString& s, const QString& c = QString()) const;
70 
76  QString tryQtranslate(const QString& s, const QString& c = QString()) const;
77 
80  const QString& getTrueLocaleName() const
81  {
82  if (langName=="system" || langName=="system_default")
83  return StelTranslator::systemLangName;
84  else
85  return langName;
86  }
87 
90 
92  QStringList getAvailableLanguagesNamesNative(const QString& localeDir="", const QString &section="") const;
93 
96  static QString iso639_1CodeToNativeName(const QString& languageCode);
97 
99  static QString nativeNameToIso639_1Code(const QString& languageName);
100 
103  static void init(const QString& fileName);
104 
105 private:
107  const StelTranslator& operator=(const StelTranslator&);
108 
111  static void initIso639_1LanguageCodes(const QString& fileName);
112 
114  QStringList getAvailableIso639_1Codes(const QString& localeDir="") const;
115 
117  QString domain;
118 
120  QString langName;
121 
123  class QTranslator* translator;
124 
126  static void initSystemLanguage(void);
127 
129  static QString systemLangName;
130 
132  static QMap<QString, QString> iso639codes;
133 };
134 
135 #endif // _STELTRANSLATOR_HPP_
136 
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.
QString tryQtranslate(const QString &s, const QString &c=QString()) const
Try to translate input message and return it as a QString.
static void init(const QString &fileName)
Initialize Translation.
QStringList getAvailableLanguagesNamesNative(const QString &localeDir="", const QString &section="") 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.