Home · All Namespaces · All Classes · Functions · Coding Style · 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #ifndef _STELTRANSLATOR_HPP_
00021 #define _STELTRANSLATOR_HPP_
00022 
00025 
00026 #include <config.h>
00027 
00028 #include <QMap>
00029 #include <QString>
00030 #include "StelUtils.hpp"
00031 
00032 // These macro are used as global function replacing standard gettext operation
00033 #include "gettext.h"
00034 
00038 #define q_(str) StelTranslator::globalTranslator.qtranslate(str)
00039 
00043 #define N_(str) gettext_noop(str)
00044 
00050 class StelTranslator
00051 {
00052 public:
00053 
00061     StelTranslator(const QString& adomain, const QString& amoDirectory, const QString& alangName) :
00062             domain(adomain), moDirectory(amoDirectory), langName(alangName)
00063     {
00064         StelTranslator::lastUsed = NULL;
00065     }
00066     
00070     QString qtranslate(const QString& s)
00071     {
00072         if (s.isEmpty()) return QString();
00073         reload();
00074         return QString::fromUtf8(gettext(s.toUtf8().constData()));
00075     }
00076     
00079     const QString& getTrueLocaleName(void) const
00080     {
00081         if (langName=="system" || langName=="system_default")
00082             return StelTranslator::systemLangName;
00083         else
00084             return langName;
00085     }
00086 
00088     static StelTranslator globalTranslator;
00089 
00091     QStringList getAvailableLanguagesNamesNative(const QString& localeDir="") const;    
00092 
00095     static QString iso639_1CodeToNativeName(const QString& languageCode);
00096     
00098     static QString nativeNameToIso639_1Code(const QString& languageName);
00099     
00102     static void init(const QString& fileName);
00103     
00104 private:
00107     static void initIso639_1LanguageCodes(const QString& fileName);
00108     
00110     QStringList getAvailableIso639_1Codes(const QString& localeDir="") const;
00111     
00113     void reload();
00114 
00116     QString domain;
00117 
00119     QString moDirectory;
00120 
00122     QString langName;
00123 
00125     static StelTranslator* lastUsed;
00126 
00128     static void initSystemLanguage(void);
00129     
00131     static QString systemLangName;
00132     
00134     static QMap<QString, QString> iso639codes;
00135 };
00136 
00137 #endif // _STELTRANSLATOR_HPP_
00138 

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5