Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
1525 cbradney 1
/***************************************************************************
2
    begin                : Jan 2005
3
    copyright            : (C) 2005 by Craig Bradney
4
    email                : cbradney@zip.com.au
5
 ***************************************************************************/
6
 
7
/***************************************************************************
8
 *                                                                         *
9
 *   This program is free software; you can redistribute it and/or modify  *
10
 *   it under the terms of the GNU General Public License as published by  *
11
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 *   (at your option) any later version.                                   *
13
 *                                                                         *
14
 ***************************************************************************/
15
 
663 cbradney 16
#include <iostream>
17
 
18
#include <qdir.h>
19
#include <qfileinfo.h>
20
#include <qmap.h>
21
#include <qobject.h>
22
#include <qstringlist.h> 
23
 
24
#include "config.h"
25
#include "langmgr.h"
26
 
27
void LanguageManager::init()
28
{
29
        generateLangList();
30
        generateInstalledLangList();
31
}
32
 
33
void LanguageManager::generateLangList()
34
{
1020 cbradney 35
        langList.insert("af",    QObject::tr( "Afrikaans" ));
672 cbradney 36
        langList.insert("sq",    QObject::tr( "Albanian" ));
37
        langList.insert("eu",    QObject::tr( "Basque" ));
38
        langList.insert("bg",    QObject::tr( "Bulgarian" ));
39
        langList.insert("br",    QObject::tr( "Brazilian" ));
40
        langList.insert("ca",    QObject::tr( "Catalan" ));
41
        langList.insert("zh",    QObject::tr( "Chinese" ));
42
        langList.insert("cs",    QObject::tr( "Czech" ));
663 cbradney 43
        langList.insert("cs_CZ", QObject::tr( "Czech" ));
672 cbradney 44
        langList.insert("da",    QObject::tr( "Danish" ));
663 cbradney 45
        langList.insert("da_DK", QObject::tr( "Danish" ));
672 cbradney 46
        langList.insert("nl",    QObject::tr( "Dutch" ));
47
        langList.insert("en",    QObject::tr( "English" ));
663 cbradney 48
        langList.insert("en_GB", QObject::tr( "English (British)" ));
672 cbradney 49
        langList.insert("eo",    QObject::tr( "Esperanto" ));
50
        langList.insert("de",    QObject::tr( "German" ));
51
        langList.insert("fi",    QObject::tr( "Finnish" ));
52
        langList.insert("fr",    QObject::tr( "French" ));
663 cbradney 53
        langList.insert("galician", QObject::tr( "Galician" ));
672 cbradney 54
        langList.insert("gl",    QObject::tr( "Galician" ));
55
        langList.insert("el",    QObject::tr( "Greek" ));
56
        langList.insert("hu",    QObject::tr( "Hungarian" ));
57
        langList.insert("id",    QObject::tr( "Indonesian" ));
58
        langList.insert("it",    QObject::tr( "Italian" ));
59
        langList.insert("ko",    QObject::tr( "Korean" ));
60
        langList.insert("lt",    QObject::tr( "Lithuanian" ));
663 cbradney 61
        langList.insert("lt_LT", QObject::tr( "Lithuanian" ));
672 cbradney 62
        langList.insert("nb",    QObject::tr( "Norwegian (Bokmaal)" ));
663 cbradney 63
        langList.insert("nb_NO", QObject::tr( "Norwegian (Bokmaal)" ));
672 cbradney 64
        langList.insert("nn",    QObject::tr( "Norwegian (Nnyorsk)" ));
663 cbradney 65
        langList.insert("nn_NO", QObject::tr( "Norwegian (Nnyorsk)" ));
672 cbradney 66
        langList.insert("no",    QObject::tr( "Norwegian" ));
663 cbradney 67
        langList.insert("no_NO", QObject::tr( "Norwegian" ));
672 cbradney 68
        langList.insert("pl",    QObject::tr( "Polish" ));
663 cbradney 69
        langList.insert("pl_PL", QObject::tr( "Polish" ));
1302 cbradney 70
        langList.insert("pt_BR", QObject::tr( "Brazilian Portugese" ));
672 cbradney 71
        langList.insert("ru",    QObject::tr( "Russian" ));
72
        langList.insert("se",    QObject::tr( "Swedish" ));
73
        langList.insert("es",    QObject::tr( "Spanish" ));
1302 cbradney 74
        langList.insert("es_ES", QObject::tr( "Spanish" ));
672 cbradney 75
        langList.insert("es_LA", QObject::tr( "Spanish (Latin)" ));
76
        langList.insert("sk",    QObject::tr( "Slovak" ));
77
        langList.insert("sl",    QObject::tr( "Slovenian" ));
78
        langList.insert("sr",    QObject::tr( "Serbian" ));
79
        langList.insert("tr",    QObject::tr( "Turkish" ));
663 cbradney 80
        langList.insert("tr_TR", QObject::tr( "Turkish" ));
672 cbradney 81
        langList.insert("uk",    QObject::tr( "Ukranian" ));
82
        langList.insert("cy",    QObject::tr( "Welsh" ));
663 cbradney 83
}
84
 
85
void LanguageManager::generateInstalledLangList()
86
{
872 cbradney 87
    QString path = LIBDIR;
663 cbradney 88
    QString langAbbrev;
89
    QMap<QString, QString>::Iterator it;
90
 
91
    QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
92
    if (dir.exists() && (dir.count() != 0))
1303 cbradney 93
        for (uint i = 0; i < dir.count(); ++i)
94
                {
663 cbradney 95
            QFileInfo file(path + dir[i]);
1303 cbradney 96
            if (file.extension(false).lower() == "qm")
97
                        {
663 cbradney 98
                langAbbrev = file.extension().remove(".qm");
99
                if ((it=langList.find(langAbbrev))!=langList.end())
100
                                                installedLangList.insert(it.key(), it.data());
101
            }
102
        }
103
}
104
 
105
const QString LanguageManager::getLangFromAbbrev(QString langAbbrev)
106
{
107
        QMap<QString, QString>::Iterator it;
108
        if ((it=langList.find(langAbbrev))!=langList.end())
109
                return it.data();
110
        else
111
                return NULL;   
112
}
113
 
114
const QString LanguageManager::getAbbrevFromLang(QString lang)
115
{
116
        QMap<QString, QString>::Iterator it;
117
        for (it=langList.begin();it!=langList.end();++it)
118
                if (it.data()==lang)
119
                        return it.key();
120
        return NULL;   
121
}
122
 
123
void LanguageManager::fillInstalledStringList(QStringList *stringListToFill, bool addDefaults)
124
{
125
        if (stringListToFill)
126
        {
127
                QMap<QString, QString>::Iterator it;
128
 
129
                if (addDefaults)
130
                {
131
                        stringListToFill->append("");
132
                        stringListToFill->append( QObject::tr( "English" ));
133
                }
134
 
135
                for (it=installedLangList.begin();it!=installedLangList.end();++it)
136
                        stringListToFill->append(it.data());
137
        }
138
}
139
 
140
void LanguageManager::printInstalledList()
141
{
142
        QMap<QString, QString>::Iterator it;
143
 
144
        for (it=installedLangList.begin();it!=installedLangList.end();++it)
145
                std::cout << it.key().leftJustify(6) << ": " << it.data() << std::endl;
146
}