Stellarium 0.11.3
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelTranslator.hpp

Go to the documentation of this file.
00001 /*
00002 * Stellarium
00003 * Copyright (C) 2005 Fabien Chereau
00004 *
00005 * This program is free software; you can redistribute it and/or
00006 * modify it under the terms of the GNU General Public License
00007 * as published by the Free Software Foundation; either version 2
00008 * of the License, or (at your option) any later version.
00009 * 
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * 
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program; if not, write to the Free Software
00017 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018 */
00019 
00020 #ifndef _STELTRANSLATOR_HPP_
00021 #define _STELTRANSLATOR_HPP_
00022 
00025 
00026 #include <QMap>
00027 #include <QString>
00028 #include "StelUtils.hpp"
00029 
00030 // These macro are used as global function replacing standard gettext operation
00031 #include "gettext.h"
00032 
00036 #define q_(str) StelTranslator::globalTranslator.qtranslate(str)
00037 
00041 #define N_(str) gettext_noop(str)
00042 
00048 class StelTranslator
00049 {
00050 public:
00051 
00059     StelTranslator(const QString& adomain, const QString& amoDirectory, const QString& alangName) :
00060             domain(adomain), moDirectory(amoDirectory), langName(alangName)
00061     {
00062         StelTranslator::lastUsed = NULL;
00063     }
00064     
00068     QString qtranslate(const QString& s)
00069     {
00070         if (s.isEmpty()) return QString();
00071         reload();
00072         return QString::fromUtf8(gettext(s.toUtf8().constData()));
00073     }
00074     
00077     const QString& getTrueLocaleName(void) const
00078     {
00079         if (langName=="system" || langName=="system_default")
00080             return StelTranslator::systemLangName;
00081         else
00082             return langName;
00083     }
00084 
00086     static StelTranslator globalTranslator;
00087 
00089     QStringList getAvailableLanguagesNamesNative(const QString& localeDir="") const;    
00090 
00093     static QString iso639_1CodeToNativeName(const QString& languageCode);
00094     
00096     static QString nativeNameToIso639_1Code(const QString& languageName);
00097     
00100     static void init(const QString& fileName);
00101     
00102 private:
00105     static void initIso639_1LanguageCodes(const QString& fileName);
00106     
00108     QStringList getAvailableIso639_1Codes(const QString& localeDir="") const;
00109     
00111     void reload();
00112 
00114     QString domain;
00115 
00117     QString moDirectory;
00118 
00120     QString langName;
00121 
00123     static StelTranslator* lastUsed;
00124 
00126     static void initSystemLanguage(void);
00127     
00129     static QString systemLangName;
00130     
00132     static QMap<QString, QString> iso639codes;
00133 };
00134 
00135 #endif // _STELTRANSLATOR_HPP_
00136 
Generated on Thu May 31 10:37:19 2012 for Stellarium by  doxygen 1.6.3