Back to index

scribus-ng  1.3.4.dfsg+svn20071115
langmgr.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008     begin                : Jan 2005
00009     copyright            : (C) 2005 by Craig Bradney
00010     email                : cbradney@zip.com.au
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021  
00022 #include <iostream>
00023 
00024 #include <qdir.h>
00025 #include <qfileinfo.h>
00026 #include <qmap.h>
00027 #include <qobject.h>
00028 #include <qstringlist.h> 
00029 
00030 #include "scconfig.h"
00031 #include "langmgr.h"
00032 #include "scpaths.h"
00033 
00034 void LanguageManager::init(bool generateInstalledList)
00035 {
00036        //generateUntranslatedLangList();
00037        generateLangList();
00038        if (generateInstalledList)
00039               generateInstalledLangList();
00040 }
00041 
00042 void LanguageManager::generateLangList()
00043 {
00044        langList.insert("af",       langPair("Afrikaans",           QObject::tr( "Afrikaans" )) );
00045        langList.insert("ar",       langPair("Arabic",              QObject::tr( "Arabic" )) );
00046        langList.insert("sq",       langPair("Albanian",            QObject::tr( "Albanian" )) );
00047        langList.insert("eu",       langPair("Basque",              QObject::tr( "Basque" )) );
00048        langList.insert("bg",       langPair("Bulgarian",           QObject::tr( "Bulgarian" )) );
00049        langList.insert("br",       langPair("Breton",              QObject::tr( "Breton" )) );
00050        langList.insert("ca",       langPair("Catalan",             QObject::tr( "Catalan" )) );
00051        langList.insert("zh",       langPair("Chinese",             QObject::tr( "Chinese" )) );
00052        langList.insert("zh_TW",    langPair("Chinese (Trad.)",     QObject::tr( "Chinese (Trad.)" )) );
00053        langList.insert("hr",       langPair("Croatian",            QObject::tr( "Croatian" )) );
00054        langList.insert("cs",       langPair("Czech",               QObject::tr( "Czech" )) );
00055        langList.insert("cs_CZ",    langPair("Czech",               QObject::tr( "Czech" )) );
00056        langList.insert("da",       langPair("Danish",              QObject::tr( "Danish" )) );
00057        langList.insert("da_DK",    langPair("Danish",              QObject::tr( "Danish" )) );
00058        langList.insert("dz",       langPair("Dzongkha",            QObject::tr( "Dzongkha" )) );
00059        langList.insert("nl",       langPair("Dutch",               QObject::tr( "Dutch" )) );
00060        langList.insert("en",       langPair("English",             QObject::tr( "English" )) );
00061        langList.insert("en_AU",    langPair("English (Australian)",QObject::tr( "English (Australian)" )) );
00062        langList.insert("en_GB",    langPair("English (British)",   QObject::tr( "English (British)" )) );
00063        langList.insert("en_US",    langPair("English (American)",  QObject::tr( "English (American)" )) );
00064        langList.insert("eo",       langPair("Esperanto",           QObject::tr( "Esperanto" )) );
00065        langList.insert("et",       langPair("Estonian",            QObject::tr( "Estonian" )) );
00066        langList.insert("de",       langPair("German",              QObject::tr( "German" )) );
00067        langList.insert("de_CH",    langPair("German (Swiss)",      QObject::tr( "German (Swiss)" )) );
00068        langList.insert("de_ol",    langPair("German (Trad.)",      QObject::tr( "German (Trad.)" )) );
00069        langList.insert("fi",       langPair("Finnish",             QObject::tr( "Finnish" )) );
00070        langList.insert("fr",       langPair("French",              QObject::tr( "French" )) );
00071        langList.insert("ga",       langPair("Galician",            QObject::tr( "Galician" )) );
00072        langList.insert("galician", langPair("Galician",            QObject::tr( "Galician" )) );
00073        langList.insert("gl",       langPair("Galician",            QObject::tr( "Galician" )) );
00074        langList.insert("el",       langPair("Greek",               QObject::tr( "Greek" )) );
00075        langList.insert("he",       langPair("Hebrew",              QObject::tr( "Hebrew" )) );
00076        langList.insert("hu",       langPair("Hungarian",           QObject::tr( "Hungarian" )) );
00077        langList.insert("ia",       langPair("Latin",               QObject::tr( "Latin" )) );
00078        langList.insert("is",       langPair("Icelandic",           QObject::tr( "Icelandic" )) );
00079        langList.insert("id",       langPair("Indonesian",          QObject::tr( "Indonesian" )) );
00080        langList.insert("it",       langPair("Italian",             QObject::tr( "Italian" )) );
00081        langList.insert("ja",       langPair("Japanese",            QObject::tr( "Japanese" )) );
00082        langList.insert("ko",       langPair("Korean",              QObject::tr( "Korean" )) );
00083        langList.insert("la",       langPair("Latin",               QObject::tr( "Latin" )) );
00084        langList.insert("lt",       langPair("Lithuanian",          QObject::tr( "Lithuanian" )) );
00085        langList.insert("lt_LT",    langPair("Lithuanian",          QObject::tr( "Lithuanian" )) );
00086        langList.insert("lu",       langPair("Luxembourgish",       QObject::tr( "Luxembourgish" )) );
00087        //We might need &#00E5; for this accented a
00088        langList.insert("nb",       langPair("Norwegian (Bokmål)",  QObject::trUtf8( "Norwegian (Bokmål)" )) );
00089        langList.insert("nb_NO",    langPair("Norwegian (Bokmål)",  QObject::trUtf8( "Norwegian (Bokmål)" )) );
00090        langList.insert("nn",       langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
00091        langList.insert("nn_NO",    langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
00092        langList.insert("no",       langPair("Norwegian",           QObject::tr( "Norwegian" )) );
00093        langList.insert("no_NO",    langPair("Norwegian",           QObject::tr( "Norwegian" )) );
00094        langList.insert("pl",       langPair("Polish",              QObject::tr( "Polish" )) );
00095        langList.insert("pl_PL",    langPair("Polish",              QObject::tr( "Polish" )) );
00096        langList.insert("pt",       langPair("Portuguese",          QObject::tr( "Portuguese" )) );
00097        langList.insert("pt_BR",    langPair("Portuguese (BR)",     QObject::tr( "Portuguese (BR)" )) );
00098        langList.insert("ro",       langPair("Romanian",            QObject::tr( "Romanian" )) );
00099        langList.insert("ru",       langPair("Russian",             QObject::tr( "Russian" )) );
00100        langList.insert("se",       langPair("Swedish",             QObject::tr( "Swedish" )) );
00101        langList.insert("es",       langPair("Spanish",             QObject::tr( "Spanish" )) );
00102        langList.insert("es_ES",    langPair("Spanish",             QObject::tr( "Spanish" )) );
00103        langList.insert("es_LA",    langPair("Spanish (Latin)",     QObject::tr( "Spanish (Latin)" )) );
00104        langList.insert("sk",       langPair("Slovak",              QObject::tr( "Slovak" )) );
00105        langList.insert("sl",       langPair("Slovenian",           QObject::tr( "Slovenian" )) );
00106        langList.insert("sr",       langPair("Serbian",             QObject::tr( "Serbian" )) );
00107        langList.insert("sv",       langPair("Swedish",             QObject::tr( "Swedish" )) );
00108        langList.insert("th",       langPair("Thai",                QObject::tr( "Thai" )) );
00109        langList.insert("th_TH",    langPair("Thai",                QObject::tr( "Thai" )) );
00110        langList.insert("tr",       langPair("Turkish",             QObject::tr( "Turkish" )) );
00111        langList.insert("tr_TR",    langPair("Turkish",             QObject::tr( "Turkish" )) );
00112        langList.insert("uk",       langPair("Ukranian",            QObject::tr( "Ukranian" )) );
00113        langList.insert("cy",       langPair("Welsh",               QObject::tr( "Welsh" )) );
00114 }
00115 
00116 void LanguageManager::generateInstalledLangList()
00117 {
00118         QString path = ScPaths::instance().translationDir();
00119        QString langAbbrev;
00120        QMap<QString, langPair>::Iterator it;
00121 
00122        QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
00123        if (dir.exists() && (dir.count() != 0))
00124               for (uint i = 0; i < dir.count(); ++i) 
00125               {
00126                      QFileInfo file(path + dir[i]);
00127                      if (file.extension(false).lower() == "qm") 
00128                      {
00129                             langAbbrev = file.extension().remove(".qm");
00130                             if ((it=langList.find(langAbbrev))!=langList.end())
00131                                           installedLangList.insert(it.key(), it.data().second);
00132                      }
00133               }
00134 }
00135 
00136 const QString LanguageManager::getLangFromAbbrev(QString langAbbrev, bool getTranslated)
00137 {
00138        QMap<QString, langPair>::Iterator it;
00139        if ((it=langList.find(langAbbrev))!=langList.end())
00140        {
00141               if (getTranslated)
00142                      return it.data().second;
00143               else
00144                      return it.data().first;
00145        }
00146        else
00147               return "";    
00148 }
00149 
00150 const QString LanguageManager::getAbbrevFromLang(QString lang, bool getFromTranslated, bool useInstalled)
00151 {
00152        QMap<QString, langPair>::Iterator it;
00153        if (useInstalled)
00154        {
00155               for (it=langList.begin();it!=langList.end();++it)
00156               {
00157                      if (installedLangList.find(it.key()) != installedLangList.end())
00158                      {
00159                             if (getFromTranslated && it.data().second==lang)
00160                                    return it.key();
00161                             if (!getFromTranslated && it.data().first==lang)
00162                                    return it.key();
00163                      }
00164               }
00165        }
00166        else
00167        {
00168               for (it=langList.begin();it!=langList.end();++it)
00169               {
00170 //                   if (installedLangList.find(it.key()) != installedLangList.end())
00171 //                   {
00172                             if (getFromTranslated && it.data().second==lang)
00173                                    return it.key();
00174                             if (!getFromTranslated && it.data().first==lang)
00175                                    return it.key();
00176 //                   }
00177               }
00178        }
00179        return "";
00180 }
00181 
00182 void LanguageManager::fillInstalledStringList(QStringList *stringListToFill, bool addDefaults) 
00183 {
00184        if (stringListToFill)
00185        {
00186               QMap<QString, QString>::Iterator it;
00187 
00188               if (addDefaults) 
00189               {
00190                      stringListToFill->append("");
00191                      stringListToFill->append( QObject::tr( "English" ));
00192               }
00193 
00194               for (it=installedLangList.begin();it!=installedLangList.end();++it)
00195                      stringListToFill->append(it.data());
00196        }
00197 }
00198 
00199 void LanguageManager::printInstalledList()
00200 {
00201        QMap<QString, QString>::Iterator it;
00202 
00203        for (it=installedLangList.begin();it!=installedLangList.end();++it)
00204               std::cout << it.key().leftJustify(6) << ": " << it.data() << std::endl;
00205 }
00206 
00207 QString LanguageManager::numericSequence(QString seq)
00208 {
00209        QString retSeq;
00210        const int nsBengali=0,nsDevanagari=1,nsGujarati=2,nsGurumukhi=3,nsKannada=4,nsMalayalam=5,nsOriya=6,nsTamil=7,nsTelugu=8,nsTibetan=9,nsLepcha=10;
00211        switch (1)
00212        {
00213               case nsBengali:
00214                      retSeq+="";
00215                      break;
00216               case nsDevanagari:
00217                      retSeq+="०१२३४५६७८९";
00218                      break;
00219               case nsGujarati:
00220                      retSeq+="૦૧૨૩૪૫૬૭૮૯";
00221                      break;
00222               case nsGurumukhi:
00223                      retSeq+="੦੧੨੩੪੫੬੭੮੯";
00224                      break;
00225               case nsKannada:
00226                      retSeq+="";
00227                      break;
00228               case nsMalayalam:
00229                      retSeq+="";
00230                      break;
00231               case nsOriya:
00232                      retSeq+="";
00233                      break;
00234               case nsTamil:
00235                      retSeq+="";
00236                      break;
00237               case nsTelugu:
00238                      retSeq+="";
00239                      break;
00240               case nsTibetan:
00241                      retSeq+="";
00242                      break;
00243               case nsLepcha:
00244                      retSeq+="";
00245                      break;
00246               default:
00247                      retSeq="0123456789";
00248                      break;
00249        }
00250        return retSeq;
00251 }
00252 
00253 LanguageManager::~LanguageManager()
00254 {
00255        langList.clear();
00256        installedLangList.clear();
00257 }
00258