Subversion Repositories Scribus

Rev

Rev 5093 | Rev 5481 | 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" )) );
49
        langList.insert("br",    langPair("Brazilian", QObject::tr( "Brazilian" )) );
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" )) );
59
        langList.insert("en_GB", langPair("English (British)", QObject::tr( "English (British)" )) );
60
        langList.insert("eo",    langPair("Esperanto", QObject::tr( "Esperanto" )) );
61
        langList.insert("de",    langPair("German", QObject::tr( "German" )) );
4820 cbradney 62
        langList.insert("de_ol", langPair("German (Trad.)", QObject::tr( "German (Trad.)" )) );
3776 cbradney 63
        langList.insert("fi",    langPair("Finnish", QObject::tr( "Finnish" )) );
64
        langList.insert("fr",    langPair("French", QObject::tr( "French" )) );
65
        langList.insert("ga",    langPair("Galician", QObject::tr( "Galician" )) );
66
        langList.insert("galician", langPair("Galician", QObject::tr( "Galician" )) );
67
        langList.insert("gl",    langPair("Galician", QObject::tr( "Galician" )) );
68
        langList.insert("el",    langPair("Greek", QObject::tr( "Greek" )) );
69
        langList.insert("hu",    langPair("Hungarian", QObject::tr( "Hungarian" )) );
70
        langList.insert("id",    langPair("Indonesian", QObject::tr( "Indonesian" )) );
71
        langList.insert("it",    langPair("Italian", QObject::tr( "Italian" )) );
4947 cbradney 72
        langList.insert("ja",    langPair("Japanese", QObject::tr( "Japanese" )) );
3776 cbradney 73
        langList.insert("ko",    langPair("Korean", QObject::tr( "Korean" )) );
74
        langList.insert("lt",    langPair("Lithuanian", QObject::tr( "Lithuanian" )) );
75
        langList.insert("lt_LT", langPair("Lithuanian", QObject::tr( "Lithuanian" )) );
4820 cbradney 76
        langList.insert("lu",    langPair("Luxembourgish", QObject::tr( "Luxembourgish" )) );
3776 cbradney 77
        langList.insert("nb",    langPair("Norwegian (Bokmaal)", QObject::tr( "Norwegian (Bokmaal)" )) );
78
        langList.insert("nb_NO", langPair("Norwegian (Bokmaal)", QObject::tr( "Norwegian (Bokmaal)" )) );
79
        langList.insert("nn",    langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
80
        langList.insert("nn_NO", langPair("Norwegian (Nnyorsk)", QObject::tr( "Norwegian (Nnyorsk)" )) );
81
        langList.insert("no",    langPair("Norwegian", QObject::tr( "Norwegian" )) );
82
        langList.insert("no_NO", langPair("Norwegian", QObject::tr( "Norwegian" )) );
83
        langList.insert("pl",    langPair("Polish", QObject::tr( "Polish" )) );
84
        langList.insert("pl_PL", langPair("Polish", QObject::tr( "Polish" )) );
85
        langList.insert("pt",    langPair("Portuguese", QObject::tr( "Portuguese" )) );
86
        langList.insert("pt_BR", langPair("Portuguese (BR)", QObject::tr( "Portuguese (BR)" )) );
87
        langList.insert("ru",    langPair("Russian", QObject::tr( "Russian" )) );
88
        langList.insert("se",    langPair("Swedish", QObject::tr( "Swedish" )) );
89
        langList.insert("es",    langPair("Spanish", QObject::tr( "Spanish" )) );
90
        langList.insert("es_ES", langPair("Spanish", QObject::tr( "Spanish" )) );
91
        langList.insert("es_LA", langPair("Spanish (Latin)", QObject::tr( "Spanish (Latin)" )) );
92
        langList.insert("sk",    langPair("Slovak", QObject::tr( "Slovak" )) );
93
        langList.insert("sl",    langPair("Slovenian", QObject::tr( "Slovenian" )) );
94
        langList.insert("sr",    langPair("Serbian", QObject::tr( "Serbian" )) );
95
        langList.insert("sv",    langPair("Swedish", QObject::tr( "Swedish" )) );
4187 mrdocs 96
        langList.insert("th",    langPair("Thai", QObject::tr( "Thai" )) );
97
        langList.insert("th_TH", langPair("Thai", QObject::tr( "Thai" )) );
3776 cbradney 98
        langList.insert("tr",    langPair("Turkish", QObject::tr( "Turkish" )) );
99
        langList.insert("tr_TR", langPair("Turkish", QObject::tr( "Turkish" )) );
100
        langList.insert("uk",    langPair("Ukranian", QObject::tr( "Ukranian" )) );
101
        langList.insert("cy",    langPair("Welsh", QObject::tr( "Welsh" )) );
663 cbradney 102
}
103
 
104
void LanguageManager::generateInstalledLangList()
105
{
3776 cbradney 106
        QString path = ScPaths::instance().libDir();
107
        QString langAbbrev;
108
        QMap<QString, langPair>::Iterator it;
663 cbradney 109
 
3776 cbradney 110
        QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
111
        if (dir.exists() && (dir.count() != 0))
112
                for (uint i = 0; i < dir.count(); ++i)
1303 cbradney 113
                {
3776 cbradney 114
                        QFileInfo file(path + dir[i]);
115
                        if (file.extension(false).lower() == "qm")
1303 cbradney 116
                        {
3776 cbradney 117
                                langAbbrev = file.extension().remove(".qm");
118
                                if ((it=langList.find(langAbbrev))!=langList.end())
119
                                                installedLangList.insert(it.key(), it.data().second);
120
                        }
121
                }
663 cbradney 122
}
123
 
3776 cbradney 124
const QString LanguageManager::getLangFromAbbrev(QString langAbbrev, bool getTranslated)
663 cbradney 125
{
3776 cbradney 126
        QMap<QString, langPair>::Iterator it;
663 cbradney 127
        if ((it=langList.find(langAbbrev))!=langList.end())
3776 cbradney 128
        {
129
                if (getTranslated)
130
                        return it.data().second;
131
                else
132
                        return it.data().first;
133
        }
663 cbradney 134
        else
2010 cbradney 135
                return "";     
663 cbradney 136
}
137
 
3776 cbradney 138
const QString LanguageManager::getAbbrevFromLang(QString lang, bool getTranslated)
663 cbradney 139
{
3776 cbradney 140
        QMap<QString, langPair>::Iterator it;
663 cbradney 141
        for (it=langList.begin();it!=langList.end();++it)
3776 cbradney 142
        {
5072 cbradney 143
                if (installedLangList.find(it.key()) != installedLangList.end())
144
                {
145
                        if (getTranslated && it.data().second==lang)
146
                                return it.key();
147
                        if (!getTranslated && it.data().first==lang)
148
                                return it.key();
149
                }
3776 cbradney 150
        }
2010 cbradney 151
        return "";     
663 cbradney 152
}
153
 
154
void LanguageManager::fillInstalledStringList(QStringList *stringListToFill, bool addDefaults)
155
{
156
        if (stringListToFill)
157
        {
158
                QMap<QString, QString>::Iterator it;
159
 
160
                if (addDefaults)
161
                {
162
                        stringListToFill->append("");
163
                        stringListToFill->append( QObject::tr( "English" ));
164
                }
165
 
166
                for (it=installedLangList.begin();it!=installedLangList.end();++it)
167
                        stringListToFill->append(it.data());
168
        }
169
}
170
 
171
void LanguageManager::printInstalledList()
172
{
173
        QMap<QString, QString>::Iterator it;
174
 
175
        for (it=installedLangList.begin();it!=installedLangList.end();++it)
176
                std::cout << it.key().leftJustify(6) << ": " << it.data() << std::endl;
177
}