|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include "extendedlocaleutil.h" |
|
26 |
|
27 #if defined(Q_OS_SYMBIAN) |
|
28 #include <QFile> |
|
29 #include <QTextStream> |
|
30 #include <QStringList> |
|
31 |
|
32 #define LANGUAGE_LIST_FILE "/resource/hbi18n/translations/language_list.txt" |
|
33 #define LANGUAGE_MAPPINGS_FILE "/resource/hbi18n/translations/locale_mappings.txt" |
|
34 #endif // Q_OS_SYMBIAN |
|
35 |
|
36 #include "cplanguagepluginlog.h" |
|
37 |
|
38 /*! |
|
39 @beta |
|
40 @hbcore |
|
41 \class ExtendedLocaleUtil |
|
42 \brief ExtendedLocaleUtil provides mappings needed for Control Panel plugin which are not available through HbLocaleUtil class. |
|
43 */ |
|
44 |
|
45 |
|
46 /*! |
|
47 \brief Return list of language, region, collation and writing language mappings. |
|
48 |
|
49 \attention Symbian specific API |
|
50 |
|
51 \return a list containing mapped locale properties |
|
52 */ |
|
53 |
|
54 //#define __TESTCODE__ |
|
55 |
|
56 QList<LanguageRegionMapping> ExtendedLocaleUtil::localeMappings(bool onlySupported) |
|
57 { |
|
58 CPLANG_LOG_FUNC_ENTRY("ExtendedLocaleUtil::localeMappings") |
|
59 |
|
60 QList<LanguageRegionMapping> mps = allLocaleMappings(); |
|
61 |
|
62 if (!onlySupported) { |
|
63 return mps; |
|
64 } |
|
65 |
|
66 QList<LanguageRegionMapping> supportedmps; |
|
67 |
|
68 QStringList supportedLanguages = HbLocaleUtil::supportedLanguages(); |
|
69 QStringList supportedRegions = HbLocaleUtil::supportedRegions(); |
|
70 |
|
71 foreach (const QString &language,supportedLanguages) { |
|
72 LanguageRegionMapping *found = 0; |
|
73 for (int i = 0; i < mps.count();i++) { |
|
74 if (mps.at(i).languageId == language) { |
|
75 found = const_cast<LanguageRegionMapping*>(&mps.at(i)); |
|
76 break; |
|
77 } |
|
78 } |
|
79 if (found) { |
|
80 supportedmps.append(*found); |
|
81 } |
|
82 else { |
|
83 LanguageRegionMapping map; |
|
84 map.languageId = language; |
|
85 map.primaryWritingLan = HbInputLanguage(QLocale(language).language()); |
|
86 } |
|
87 |
|
88 } |
|
89 |
|
90 return supportedmps; |
|
91 } |
|
92 |
|
93 QList<LanguageRegionMapping> ExtendedLocaleUtil::allLocaleMappings() |
|
94 { |
|
95 CPLANG_LOG_FUNC_ENTRY("ExtendedLocaleUtil::allLocaleMappings") |
|
96 |
|
97 QList<LanguageRegionMapping> mps; |
|
98 |
|
99 #if defined(Q_OS_SYMBIAN) |
|
100 |
|
101 QString path = "c:"; |
|
102 path += QString(LANGUAGE_MAPPINGS_FILE); |
|
103 QFile* file = new QFile(path); |
|
104 if (!file->exists() ) { |
|
105 path = "z:"; |
|
106 path += QString(LANGUAGE_MAPPINGS_FILE); |
|
107 delete file; |
|
108 file = new QFile(path); |
|
109 } |
|
110 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
111 delete file; |
|
112 return mps; |
|
113 } |
|
114 |
|
115 QTextStream in(file); |
|
116 while (!in.atEnd()) { |
|
117 QString line = in.readLine(256); |
|
118 if (!line.isEmpty()) { |
|
119 QStringList list = line.split(',', QString::SkipEmptyParts); |
|
120 if (list.count() < 7) { |
|
121 continue; |
|
122 } |
|
123 |
|
124 QString strCode = list[0]; |
|
125 QString lanName = list[4]; |
|
126 QString region = list[5]; |
|
127 QString collation = list[6]; |
|
128 |
|
129 bool ok; |
|
130 int code = strCode.toUInt(&ok); |
|
131 if (!ok) { |
|
132 continue; |
|
133 } |
|
134 |
|
135 QString lanPart = (lanName.indexOf('_')>0) ? lanName.left(lanName.indexOf('_')) : lanName; |
|
136 QString regPart = (region.indexOf('_')>0) ? region.left(region.indexOf('_')) : region; |
|
137 QLocale loc = QLocale(QString(lanPart+'_'+regPart)); |
|
138 HbInputLanguage primaryWriting = HbInputLanguage(loc.language(), loc.country()); |
|
139 HbInputLanguage secondaryWriting = HbInputLanguage(QLocale::English, QLocale::UnitedKingdom); |
|
140 |
|
141 LanguageRegionMapping map; |
|
142 map.languageId = lanName; |
|
143 map.regionId = region; |
|
144 map.collationId = collation; |
|
145 map.primaryWritingLan = primaryWriting; |
|
146 map.secondaryWritingLan = secondaryWriting; |
|
147 mps.append(map); |
|
148 |
|
149 } |
|
150 } |
|
151 delete file; |
|
152 |
|
153 #endif // Q_OS_SYMBIAN |
|
154 |
|
155 |
|
156 return mps; |
|
157 } |