Stellarium 0.13.0
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 "config.h"
27 
28 #include <QMap>
29 #include <QString>
30 
34 #define q_(str) StelTranslator::globalTranslator->qtranslate(str)
35 
39 #define qc_(str, ctxt) StelTranslator::globalTranslator->qtranslate(str, ctxt)
40 
44 #define N_(str) str
45 
52 {
53 public:
54 
62  StelTranslator(const QString& adomain, const QString& alangName);
63 
64  ~StelTranslator();
65 
70  QString qtranslate(const QString& s, const QString& c = QString()) const;
71 
74  const QString& getTrueLocaleName() const
75  {
76  if (langName=="system" || langName=="system_default")
77  return StelTranslator::systemLangName;
78  else
79  return langName;
80  }
81 
84 
86  QStringList getAvailableLanguagesNamesNative(const QString& localeDir="") const;
87 
90  static QString iso639_1CodeToNativeName(const QString& languageCode);
91 
93  static QString nativeNameToIso639_1Code(const QString& languageName);
94 
97  static void init(const QString& fileName);
98 
99 private:
101  const StelTranslator& operator=(const StelTranslator&);
102 
105  static void initIso639_1LanguageCodes(const QString& fileName);
106 
108  QStringList getAvailableIso639_1Codes(const QString& localeDir="") const;
109 
111  QString domain;
112 
114  QString langName;
115 
117  class QTranslator* translator;
118 
120  static void initSystemLanguage(void);
121 
123  static QString systemLangName;
124 
126  static QMap<QString, QString> iso639codes;
127 };
128 
129 #endif // _STELTRANSLATOR_HPP_
130 
const QString & getTrueLocaleName() const
Get true translator locale name.
Definition: StelTranslator.hpp:74
Class used to translate strings to any language.
Definition: StelTranslator.hpp:51
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.
Definition: StelTranslator.hpp:83
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.