Subversion Repositories Scribus

Rev

Rev 7670 | Rev 9494 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1525 cbradney 7
/***************************************************************************
8
    begin                : Jan 2005
9
    copyright            : (C) 2005 by Craig Bradney
10
    email                : cbradney@zip.com.au
11
 ***************************************************************************/
12
 
13
/***************************************************************************
14
 *                                                                         *
15
 *   This program is free software; you can redistribute it and/or modify  *
16
 *   it under the terms of the GNU General Public License as published by  *
17
 *   the Free Software Foundation; either version 2 of the License, or     *
18
 *   (at your option) any later version.                                   *
19
 *                                                                         *
20
 ***************************************************************************/
21
 
663 cbradney 22
#include <iostream>
23
 
24
#include <qdir.h>
25
#include <qfileinfo.h>
26
#include <qmap.h>
27
#include <qobject.h>
28
#include <qstringlist.h> 
29
 
2688 craig 30
#include "scconfig.h"
663 cbradney 31
#include "langmgr.h"
1693 craig 32
#include "scpaths.h"
663 cbradney 33
 
2010 cbradney 34
void LanguageManager::init(bool generateInstalledList)
663 cbradney 35
{
3776 cbradney 36
        //generateUntranslatedLangList();
663 cbradney 37
        generateLangList();
2010 cbradney 38
        if (generateInstalledList)
39
                generateInstalledLangList();
663 cbradney 40
}
41
 
42
void LanguageManager::generateLangList()
43
{
3776 cbradney 44
        langList.insert("af",    langPair("Afrikaans", QObject::tr( "Afrikaans" )) );
5437 cbradney 45
        langList.insert("ar",    langPair("Arabic", QObject::tr( "Arabic" )) );
3776 cbradney 46
        langList.insert("sq",    langPair("Albanian", QObject::tr( "Albanian" )) );
47
        langList.insert("eu",    langPair("Basque", QObject::tr( "Basque" )) );
48
        langList.insert("bg",    langPair("Bulgarian", QObject::tr( "Bulgarian" )) );
6678 cbradney 49
        langList.insert("br",    langPair("Breton", QObject::tr( "Breton" )) );
3776 cbradney 50
        langList.insert("ca",    langPair("Catalan", QObject::tr( "Catalan" )) );
51
        langList.insert("zh",    langPair("Chinese", QObject::tr( "Chinese" )) );
52
        langList.insert("hr",    langPair("Croatian", QObject::tr( "Croatian" )) );
53
        langList.insert("cs",    langPair("Czech", QObject::tr( "Czech" )) );
54
        langList.insert("cs_CZ", langPair("Czech", QObject::tr( "Czech" )) );
55
        langList.insert("da",    langPair("Danish", QObject::tr( "Danish" )) );
56
        langList.insert("da_DK", langPair("Danish", QObject::tr( "Danish" )) );
57
        langList.insert("nl",    langPair("Dutch", QObject::tr( "Dutch" )) );
58
        langList.insert("en",    langPair("English", QObject::tr( "English" )) );
6776 cbradney 59
        langList.insert("en_US", langPair("English (American)", QObject::tr( "English (American)" )) );
60
        langList.insert("en_AU", langPair("English (Australian)", QObject::tr( "English (Australian)" )) );
3776 cbradney 61
        langList.insert("en_GB", langPair("English (British)", QObject::tr( "English (British)" )) );
62
        langList.insert("eo",    langPair("Esperanto", QObject::tr( "Esperanto" )) );
5481 cbradney 63
        langList.insert("et",    langPair("Estonian", QObject::tr( "Estonian" )) );
3776 cbradney 64
        langList.insert("de",    langPair("German", QObject::tr( "German" )) );
8137 cbradney 65
        langList.insert("de_CH", langPair("German (Swiss)", QObject::tr( "German (Swiss)" )) );
4820 cbradney 66
        langList.insert("de_ol", langPair("German (Trad.)", QObject::tr( "German (Trad.)" )) );
3776 cbradney 67
        langList.insert("fi",    langPair("Finnish", QObject::tr( "Finnish" )) );
68
        langList.insert("fr",    langPair("French", QObject::tr( "French" )) );
69
        langList.insert("ga",    langPair("Galician", QObject::tr( "Galician" )) );
70
        langList.insert("galician", langPair("Galician", QObject::tr( "Galician" )) );
71
        langList.insert("gl",    langPair("Galician", QObject::tr( "Galician" )) );
72
        langList.insert("el",    langPair("Greek", QObject::tr( "Greek" )) );
73
        langList.insert("hu",    langPair("Hungarian", QObject::tr( "Hungarian" )) );
74
        langList.insert("id",    langPair("Indonesian", QObject::tr( "Indonesian" )) );
5533 mrdocs 75
        langList.insert("is",    langPair("Icelandic", QObject::tr( "Icelandic" )) );
3776 cbradney 76
        langList.insert("it",    langPair("Italian", QObject::tr( "Italian" )) );
4947 cbradney 77
        langList.insert("ja",    langPair("Japanese", QObject::tr( "Japanese" )) );
3776 cbradney 78
        langList.insert("ko",    langPair("Korean", QObject::tr( "Korean" )) );
79
        langList.insert("lt",    langPair("Lithuanian", QObject::tr( "Lithuanian" )) );
80
        langList.insert("lt_LT", langPair("Lithuanian", QObject::tr( "Lithuanian" )) );
4820 cbradney 81
        langList.insert("lu",    langPair("Luxembourgish", QObject::tr( "Luxembourgish" )) );
3776 cbradney 82
        langList.insert("nb",    langPair("Norwegian (Bokmaal)", QObject::tr( "Norwegian (Bokmaal)" )) );
83
        langList.insert("nb_NO", langPair("Norwegian (Bokmaal)", QObject::tr( "Norwegian (Bokmaal)" )) );
84
        langList.insert("nn",    langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
85
        langList.insert("nn_NO", langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
86
        langList.insert("no",    langPair("Norwegian", QObject::tr( "Norwegian" )) );
87
        langList.insert("no_NO", langPair("Norwegian", QObject::tr( "Norwegian" )) );
88
        langList.insert("pl",    langPair("Polish", QObject::tr( "Polish" )) );
89
        langList.insert("pl_PL", langPair("Polish", QObject::tr( "Polish" )) );
90
        langList.insert("pt",    langPair("Portuguese", QObject::tr( "Portuguese" )) );
91
        langList.insert("pt_BR", langPair("Portuguese (BR)", QObject::tr( "Portuguese (BR)" )) );
92
        langList.insert("ru",    langPair("Russian", QObject::tr( "Russian" )) );
93
        langList.insert("se",    langPair("Swedish", QObject::tr( "Swedish" )) );
94
        langList.insert("es",    langPair("Spanish", QObject::tr( "Spanish" )) );
95
        langList.insert("es_ES", langPair("Spanish", QObject::tr( "Spanish" )) );
96
        langList.insert("es_LA", langPair("Spanish (Latin)", QObject::tr( "Spanish (Latin)" )) );
97
        langList.insert("sk",    langPair("Slovak", QObject::tr( "Slovak" )) );
98
        langList.insert("sl",    langPair("Slovenian", QObject::tr( "Slovenian" )) );
99
        langList.insert("sr",    langPair("Serbian", QObject::tr( "Serbian" )) );
100
        langList.insert("sv",    langPair("Swedish", QObject::tr( "Swedish" )) );
4187 mrdocs 101
        langList.insert("th",    langPair("Thai", QObject::tr( "Thai" )) );
102
        langList.insert("th_TH", langPair("Thai", QObject::tr( "Thai" )) );
3776 cbradney 103
        langList.insert("tr",    langPair("Turkish", QObject::tr( "Turkish" )) );
104
        langList.insert("tr_TR", langPair("Turkish", QObject::tr( "Turkish" )) );
105
        langList.insert("uk",    langPair("Ukranian", QObject::tr( "Ukranian" )) );
106
        langList.insert("cy",    langPair("Welsh", QObject::tr( "Welsh" )) );
663 cbradney 107
}
108
 
109
void LanguageManager::generateInstalledLangList()
110
{
3776 cbradney 111
        QString path = ScPaths::instance().libDir();
112
        QString langAbbrev;
113
        QMap<QString, langPair>::Iterator it;
663 cbradney 114
 
3776 cbradney 115
        QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
116
        if (dir.exists() && (dir.count() != 0))
117
                for (uint i = 0; i < dir.count(); ++i)
1303 cbradney 118
                {
3776 cbradney 119
                        QFileInfo file(path + dir[i]);
120
                        if (file.extension(false).lower() == "qm")
1303 cbradney 121
                        {
3776 cbradney 122
                                langAbbrev = file.extension().remove(".qm");
123
                                if ((it=langList.find(langAbbrev))!=langList.end())
124
                                                installedLangList.insert(it.key(), it.data().second);
125
                        }
126
                }
663 cbradney 127
}
128
 
3776 cbradney 129
const QString LanguageManager::getLangFromAbbrev(QString langAbbrev, bool getTranslated)
663 cbradney 130
{
3776 cbradney 131
        QMap<QString, langPair>::Iterator it;
663 cbradney 132
        if ((it=langList.find(langAbbrev))!=langList.end())
3776 cbradney 133
        {
134
                if (getTranslated)
135
                        return it.data().second;
136
                else
137
                        return it.data().first;
138
        }
663 cbradney 139
        else
2010 cbradney 140
                return "";     
663 cbradney 141
}
142
 
3776 cbradney 143
const QString LanguageManager::getAbbrevFromLang(QString lang, bool getTranslated)
663 cbradney 144
{
3776 cbradney 145
        QMap<QString, langPair>::Iterator it;
663 cbradney 146
        for (it=langList.begin();it!=langList.end();++it)
3776 cbradney 147
        {
5072 cbradney 148
                if (installedLangList.find(it.key()) != installedLangList.end())
149
                {
150
                        if (getTranslated && it.data().second==lang)
151
                                return it.key();
152
                        if (!getTranslated && it.data().first==lang)
153
                                return it.key();
154
                }
3776 cbradney 155
        }
2010 cbradney 156
        return "";     
663 cbradney 157
}
158
 
159
void LanguageManager::fillInstalledStringList(QStringList *stringListToFill, bool addDefaults)
160
{
161
        if (stringListToFill)
162
        {
163
                QMap<QString, QString>::Iterator it;
164
 
165
                if (addDefaults)
166
                {
167
                        stringListToFill->append("");
168
                        stringListToFill->append( QObject::tr( "English" ));
169
                }
170
 
171
                for (it=installedLangList.begin();it!=installedLangList.end();++it)
172
                        stringListToFill->append(it.data());
173
        }
174
}
175
 
176
void LanguageManager::printInstalledList()
177
{
178
        QMap<QString, QString>::Iterator it;
179
 
180
        for (it=installedLangList.begin();it!=installedLangList.end();++it)
181
                std::cout << it.key().leftJustify(6) << ": " << it.data() << std::endl;
182
}
7670 cbradney 183
 
184
LanguageManager::~LanguageManager()
185
{
186
        langList.clear();
187
        installedLangList.clear();
188
}