|
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 |
|
26 #include <QFile> |
|
27 #include <QLocale> |
|
28 #include <QTimer> |
|
29 #include <QHash> |
|
30 #include <QHashIterator> |
|
31 #include <QTextStream> |
|
32 #include <QTranslator> |
|
33 #include <QTextCodec> |
|
34 #include <QCoreApplication> |
|
35 #include <QStringList> |
|
36 |
|
37 #if defined(Q_OS_SYMBIAN) |
|
38 #include <e32lang.h> |
|
39 #include <e32property.h> |
|
40 #include <centralrepository.h> |
|
41 #include <hal.h> |
|
42 #include <syslangutil.h> |
|
43 #include <CommonEngineDomainCRKeys.h> //Ui language |
|
44 #endif // Q_OS_SYMBIAN |
|
45 |
|
46 #include <hbglobal.h> |
|
47 #include <hblocaleutil.h> |
|
48 |
|
49 #if defined(Q_OS_SYMBIAN) |
|
50 #define LANGUAGE_LIST_FILE "/resource/hbi18n/translations/language_list.txt" |
|
51 #define LANGUAGE_MAPPINGS_FILE "/resource/hbi18n/translations/locale_mappings.txt" |
|
52 #define LANGUAGE_ID_PREFIX "language" |
|
53 #define LANGUAGE_TRANSLATOR_PATH "/resource/hbi18n/translations/languages" |
|
54 |
|
55 #define REGION_LIST_FILE "z:/resource/bootdata/regions.txt" |
|
56 #define REGION_ID_PREFIX "region" |
|
57 #define REGION_TRANSLATOR_PATH "/resource/hbi18n/translations/regions" |
|
58 #define REGION_DLL_PREFIX "elocl_reg." |
|
59 |
|
60 #define COLLATION_LIST_FILE "z:/resource/bootdata/collations.txt" |
|
61 #define COLLATION_ID_PREFIX "collation" |
|
62 #define COLLATION_TRANSLATOR_PATH "/resource/hbi18n/translations/collations" |
|
63 #define COLLATION_DLL_PREFIX "elocl_col." |
|
64 #define COLLATION_DLL_PREFIX_POSITION 3 |
|
65 #endif // Q_OS_SYMBIAN |
|
66 |
|
67 /*! |
|
68 @beta |
|
69 @hbcore |
|
70 \class HbLocaleUtil |
|
71 \brief HbLocaleUtil provides functions for quering supported languages, regions and collations and activing them. |
|
72 |
|
73 Language and collation identifiers typically corresponds with two-letter ISO 639 language code, but for certain languages and collations combination of ISO 639 language code and ISO 3166 country code id used. |
|
74 Region identifiers always corresponds with two-letter ISO 3166 country code. |
|
75 |
|
76 HbLocaleUtil also provides functions for converting language, region and collation identifiers to their localised names. |
|
77 */ |
|
78 |
|
79 #if defined(Q_OS_SYMBIAN) |
|
80 |
|
81 struct HbLocaleMapping |
|
82 { |
|
83 int symLangValue; |
|
84 QString languageDllId; |
|
85 QString collationDllId; |
|
86 QString regionDllId; |
|
87 QString langName; |
|
88 QString regName; |
|
89 QString collName; |
|
90 }; |
|
91 |
|
92 QList<HbLocaleMapping> mappingList; |
|
93 QList<int> regions; |
|
94 QStringList availRegions; |
|
95 QHash<QString, QString> locRegionNames; |
|
96 QList<int> collations; |
|
97 QStringList availCollations; |
|
98 QHash<QString, QString> locCollationNames; |
|
99 |
|
100 /*! |
|
101 \brief Reads langauge, region and collation mappings. |
|
102 */ |
|
103 void readMappings() |
|
104 { |
|
105 QString path = "c:"; |
|
106 path += QString(LANGUAGE_MAPPINGS_FILE); |
|
107 QFile* file = new QFile(path); |
|
108 if (!file->exists() ) { |
|
109 path = "z:"; |
|
110 path += QString(LANGUAGE_MAPPINGS_FILE); |
|
111 delete file; |
|
112 file = new QFile(path); |
|
113 } |
|
114 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
115 delete file; |
|
116 return; |
|
117 } |
|
118 QTextStream in(file); |
|
119 while (!in.atEnd()) { |
|
120 QString line = in.readLine(256); |
|
121 if (!line.isEmpty()) { |
|
122 QStringList list = line.split(',', QString::SkipEmptyParts); |
|
123 if (list.count() < 7) { |
|
124 continue; |
|
125 } |
|
126 QString strCode = list[0]; |
|
127 QString strLang = list[1]; |
|
128 QString strRegion = list[2]; |
|
129 QString strCollation = list[3]; |
|
130 QString lanName = list[4]; //en_GB |
|
131 QString region = list[5]; //en_GB |
|
132 QString collation = list[6]; //en_GB |
|
133 |
|
134 bool ok; |
|
135 int code = strCode.toUInt(&ok); |
|
136 if (!ok) { |
|
137 continue; |
|
138 } |
|
139 |
|
140 HbLocaleMapping map; |
|
141 map.symLangValue = code; |
|
142 map.languageDllId = strLang; |
|
143 map.collationDllId = strCollation; |
|
144 map.regionDllId = strRegion; |
|
145 map.langName = lanName; |
|
146 map.regName = region; |
|
147 map.collName = collation; |
|
148 mappingList.append(map); |
|
149 } |
|
150 } |
|
151 delete file; |
|
152 return; |
|
153 } |
|
154 #endif // Q_OS_SYMBIAN |
|
155 |
|
156 #if defined(Q_OS_SYMBIAN) |
|
157 |
|
158 /*! |
|
159 \brief Changes the system UI language. |
|
160 |
|
161 \param dllExtension extension of the locale dll |
|
162 \return true if operation was successful |
|
163 */ |
|
164 bool setLocale( const QString &dllExtension ) |
|
165 { |
|
166 TExtendedLocale dummy; |
|
167 dummy.LoadSystemSettings(); |
|
168 QString name = QString( "elocl_lan." ).append( dllExtension ); |
|
169 TPtrC nameptr(name.utf16()); |
|
170 |
|
171 TInt err = dummy.LoadLocaleAspect( nameptr ); |
|
172 if( err != KErrNone ) |
|
173 return false; |
|
174 dummy.SaveSystemSettings(); |
|
175 // cause localeprivate update on next qlocale object( glp->m_language_id = 0 ) |
|
176 QSystemLocale dummy2; |
|
177 return true; |
|
178 } |
|
179 #endif //Q_OS_SYMBIAN |
|
180 |
|
181 /*! |
|
182 \brief Return identifier of the current UI language. |
|
183 |
|
184 \attention Symbian specific API |
|
185 |
|
186 \return Identifier of the language code for Symbian and empty QString for other platforms. |
|
187 */ |
|
188 QString HbLocaleUtil::currentLanguage() |
|
189 { |
|
190 #if defined(Q_OS_SYMBIAN) |
|
191 TLanguage l = User::Language(); |
|
192 |
|
193 if(mappingList.isEmpty()) { |
|
194 readMappings(); |
|
195 } |
|
196 |
|
197 for (int i = 0; i < mappingList.count(); ++i) { |
|
198 HbLocaleMapping mapping = mappingList.at(i); |
|
199 if (mapping.symLangValue == l) { |
|
200 return mapping.langName; |
|
201 } |
|
202 } |
|
203 #endif |
|
204 return QString(""); |
|
205 } |
|
206 |
|
207 /*! |
|
208 \brief Returns identifiers of languages supported in a device. |
|
209 Language identifier may be two-letter ISO 639 language code or combination of ISO 639 language code and ISO 3166 country code |
|
210 Ex: Great Britain english it returns "en". |
|
211 Ex: For U.S. english it returns "en_US" |
|
212 |
|
213 \attention Symbian specific API |
|
214 |
|
215 \return identifiers of supported languages for Symbian and empty QStringList for other platforms |
|
216 */ |
|
217 QStringList HbLocaleUtil::supportedLanguages() |
|
218 { |
|
219 #if defined(Q_OS_SYMBIAN) |
|
220 |
|
221 QStringList languages; |
|
222 CArrayFixFlat<TInt>* systemEpocLanguageCodes = 0; |
|
223 TInt error = SysLangUtil::GetInstalledLanguages( systemEpocLanguageCodes ); |
|
224 if ( error != KErrNone ) { |
|
225 delete systemEpocLanguageCodes; |
|
226 return languages; |
|
227 } |
|
228 |
|
229 if(mappingList.isEmpty()) { |
|
230 readMappings(); |
|
231 } |
|
232 |
|
233 for (int i = 0; i < systemEpocLanguageCodes->Count(); ++i) { |
|
234 int code = systemEpocLanguageCodes->At(i); |
|
235 for (int j = 0; j < mappingList.count(); ++j) { |
|
236 HbLocaleMapping map = mappingList.at(j); |
|
237 if (map.symLangValue == code) { |
|
238 languages.append(map.langName); |
|
239 break; |
|
240 } |
|
241 } |
|
242 } |
|
243 |
|
244 delete systemEpocLanguageCodes; |
|
245 return languages; |
|
246 #else |
|
247 QStringList dummy; |
|
248 return dummy; |
|
249 #endif |
|
250 } |
|
251 |
|
252 /*! |
|
253 \brief Converts two or five letter language identifier code to localised language name. |
|
254 |
|
255 \attention Symbian specific API |
|
256 |
|
257 \param language identifier |
|
258 |
|
259 \return Symbian - localised name of the language, an empty String if translation fails |
|
260 \return other platforms - empty QString |
|
261 */ |
|
262 QString HbLocaleUtil::localisedLanguageName( const QString &language ) |
|
263 { |
|
264 #if defined(Q_OS_SYMBIAN) |
|
265 QTranslator translator; |
|
266 QString path = "c:"; |
|
267 path += QString(LANGUAGE_TRANSLATOR_PATH); |
|
268 if (!translator.load(path)) { |
|
269 path = "z:"; |
|
270 path += QString(LANGUAGE_TRANSLATOR_PATH); |
|
271 if (!translator.load(path)) { |
|
272 return QString(""); |
|
273 } |
|
274 } |
|
275 |
|
276 QCoreApplication::installTranslator(&translator); |
|
277 QString languageName = QString(LANGUAGE_ID_PREFIX); |
|
278 languageName += '_'; |
|
279 languageName += language; |
|
280 QString translated = hbTrId(languageName.toAscii().constData()); |
|
281 if (translated == languageName) { |
|
282 return QString(""); |
|
283 } |
|
284 return translated; |
|
285 #else |
|
286 Q_UNUSED(language); |
|
287 return QString(""); |
|
288 #endif |
|
289 } |
|
290 |
|
291 /*! |
|
292 \brief Changes the system language. |
|
293 The language parameter should correspond with one of the identifiers returned by supportedLanguages(). |
|
294 |
|
295 \attention Symbian specific API |
|
296 |
|
297 \param language identifier of language to set active |
|
298 |
|
299 \return true if language change was successful and false for other platforms |
|
300 */ |
|
301 bool HbLocaleUtil::changeLanguage( const QString &language ) |
|
302 { |
|
303 #if defined(Q_OS_SYMBIAN) |
|
304 if(mappingList.isEmpty()) { |
|
305 readMappings(); |
|
306 } |
|
307 |
|
308 int lanCode = -1; |
|
309 QString dllExt = ""; |
|
310 for (int i = 0; i < mappingList.count(); ++i) { |
|
311 HbLocaleMapping map = mappingList.at(i); |
|
312 if (map.langName == language) { |
|
313 lanCode = map.symLangValue; |
|
314 dllExt = map.languageDllId; |
|
315 break; |
|
316 } |
|
317 } |
|
318 |
|
319 if (lanCode == -1) { |
|
320 return false; |
|
321 } |
|
322 |
|
323 CRepository* commonEngineRepository = 0; |
|
324 TRAPD( err1, commonEngineRepository = CRepository::NewL( KCRUidCommonEngineKeys ) ); |
|
325 if ( err1 != KErrNone ) { |
|
326 return false; |
|
327 } |
|
328 |
|
329 if (!setLocale(dllExt)) { |
|
330 delete commonEngineRepository; |
|
331 return false; |
|
332 } |
|
333 |
|
334 // Never set Language code 0 to HAL |
|
335 if ( language !=0 ) { |
|
336 if ( HAL::Set( HAL::ELanguageIndex, lanCode ) != KErrNone ) { |
|
337 delete commonEngineRepository; |
|
338 return false; |
|
339 } |
|
340 } |
|
341 if ( commonEngineRepository->Set( KGSDisplayTxtLang, lanCode ) != KErrNone ) { |
|
342 delete commonEngineRepository; |
|
343 return false; |
|
344 } |
|
345 delete commonEngineRepository; |
|
346 return true; |
|
347 |
|
348 #else |
|
349 Q_UNUSED(language); |
|
350 return false; |
|
351 #endif |
|
352 } |
|
353 |
|
354 #if defined(Q_OS_SYMBIAN) |
|
355 /*! |
|
356 \brief reads the regions.txt file and reads the list of symbian region codes |
|
357 */ |
|
358 void readRegions() |
|
359 { |
|
360 QFile* file = new QFile(REGION_LIST_FILE); |
|
361 if (!file->exists() ) |
|
362 { |
|
363 delete file; |
|
364 return; |
|
365 } |
|
366 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) |
|
367 { |
|
368 delete file; |
|
369 return; |
|
370 } |
|
371 QTextStream in(file); |
|
372 while (!in.atEnd()) |
|
373 { |
|
374 QString line = in.readLine(256); |
|
375 if (!line.isEmpty()) |
|
376 { |
|
377 int regCode = line.toUInt(); |
|
378 regions.append(regCode); |
|
379 } |
|
380 } |
|
381 return; |
|
382 } |
|
383 #endif |
|
384 |
|
385 /*! |
|
386 \brief Returns names supported regions in a phone. |
|
387 Region names are identified by 2 letter code(ISO 3166 standard). |
|
388 Ex: For United Kingdom it returns GB |
|
389 |
|
390 \attention Symbian specific API |
|
391 |
|
392 \return list of supported regions in a device for Symbian and empty QStringList for other platforms |
|
393 */ |
|
394 QStringList HbLocaleUtil::supportedRegions() |
|
395 { |
|
396 #if defined(Q_OS_SYMBIAN) |
|
397 if(!availRegions.isEmpty()) |
|
398 { |
|
399 return availRegions; |
|
400 } |
|
401 |
|
402 if(regions.isEmpty()) |
|
403 { |
|
404 readRegions(); |
|
405 } |
|
406 |
|
407 if(mappingList.isEmpty()) |
|
408 { |
|
409 readMappings(); |
|
410 } |
|
411 int regCount = regions.count(); |
|
412 for(int i = 0; i < regCount; i++) |
|
413 { |
|
414 int region = regions.at(i); |
|
415 int count = mappingList.count(); |
|
416 for (int j = 0; j < count; j++) |
|
417 { |
|
418 HbLocaleMapping mapping = mappingList.at(j); |
|
419 QString regCode = mapping.regionDllId; |
|
420 if(region == regCode.toUInt()) |
|
421 { |
|
422 availRegions.append(mapping.regName); |
|
423 break; |
|
424 } |
|
425 } |
|
426 } |
|
427 return availRegions; |
|
428 #else |
|
429 return QStringList(); |
|
430 #endif |
|
431 } |
|
432 |
|
433 /*! |
|
434 \brief Converts two letter region identifier to localised region name. |
|
435 |
|
436 \attention Symbian specific API |
|
437 |
|
438 \param region region identifier |
|
439 |
|
440 \return Symbian - localised name of the region, an empty String if translation fails |
|
441 \return other platforms - empty QString |
|
442 */ |
|
443 QString HbLocaleUtil::localisedRegionName( const QString ®ion ) |
|
444 { |
|
445 #if defined(Q_OS_SYMBIAN) |
|
446 if(locRegionNames.isEmpty()) |
|
447 { |
|
448 QTranslator translator; |
|
449 QString path = "c:"; |
|
450 path += QString(REGION_TRANSLATOR_PATH); |
|
451 if (!translator.load(path)) { |
|
452 path = "z:"; |
|
453 path += QString(REGION_TRANSLATOR_PATH); |
|
454 if (!translator.load(path)) { |
|
455 return QString(""); |
|
456 } |
|
457 } |
|
458 |
|
459 QCoreApplication::installTranslator(&translator); |
|
460 |
|
461 if(availRegions.isEmpty()) |
|
462 { |
|
463 readRegions(); |
|
464 } |
|
465 int cnt = availRegions.count(); |
|
466 for(int i = 0 ; i < cnt; i++ ) |
|
467 { |
|
468 QString reg = availRegions.at(i); |
|
469 QString regionName = QString(REGION_ID_PREFIX); |
|
470 regionName += '_'; |
|
471 regionName += reg; |
|
472 QString locRegName = hbTrId(regionName.toAscii().constData()); |
|
473 if(locRegName != regionName) |
|
474 locRegionNames.insert(reg, locRegName); |
|
475 } |
|
476 } |
|
477 |
|
478 return locRegionNames.value(region); |
|
479 #else |
|
480 Q_UNUSED(region); |
|
481 return QString(); |
|
482 #endif |
|
483 } |
|
484 |
|
485 /*! |
|
486 \brief Changes the system region. |
|
487 The region parameter should correspond with one of the identifiers returned by supportedRegions(). |
|
488 |
|
489 \attention Symbian specific API |
|
490 |
|
491 \param region identifier of region to set active |
|
492 |
|
493 \return true if region change was successful for Symbian and false for other platforms |
|
494 */ |
|
495 bool HbLocaleUtil::changeRegion( const QString ®ion ) |
|
496 { |
|
497 #if defined(Q_OS_SYMBIAN) |
|
498 TExtendedLocale dummy; |
|
499 QString regDllName = QString( "elocl_reg." ); |
|
500 |
|
501 if(mappingList.isEmpty()) |
|
502 { |
|
503 readMappings(); |
|
504 } |
|
505 int count = mappingList.count(); |
|
506 for (int j = 0; j < count; j++) |
|
507 { |
|
508 HbLocaleMapping mapping = mappingList.at(j); |
|
509 QString name = mapping.regName; |
|
510 if(name == region) |
|
511 { |
|
512 dummy.LoadSystemSettings(); |
|
513 regDllName += mapping.regionDllId; |
|
514 TPtrC nameptr(regDllName.utf16()); |
|
515 TInt err = dummy.LoadLocaleAspect( nameptr ); |
|
516 if( err != KErrNone ) |
|
517 return false; |
|
518 dummy.SaveSystemSettings(); |
|
519 // cause localeprivate update on next qlocale object |
|
520 QSystemLocale dummy2; |
|
521 return true; |
|
522 } |
|
523 } |
|
524 return false; |
|
525 #else |
|
526 Q_UNUSED(region); |
|
527 return false; |
|
528 #endif |
|
529 } |
|
530 |
|
531 /*! |
|
532 \brief Return identifier of the current region. |
|
533 |
|
534 \attention Symbian specific API |
|
535 |
|
536 \return identifier of the region for Symbian and empty QString for other platforms |
|
537 */ |
|
538 QString HbLocaleUtil::currentRegion() |
|
539 { |
|
540 #if defined(Q_OS_SYMBIAN) |
|
541 if(mappingList.isEmpty()) |
|
542 { |
|
543 readMappings(); |
|
544 } |
|
545 TRegionCode reg = User::RegionCode(); |
|
546 int cnt = mappingList.count(); |
|
547 for(int i = 0; i < cnt; i++) |
|
548 { |
|
549 HbLocaleMapping mapping = mappingList.at(i); |
|
550 int dllid = mapping.regionDllId.toInt(); |
|
551 if(dllid == reg) |
|
552 { |
|
553 return mapping.regName; |
|
554 } |
|
555 } |
|
556 return QString(); |
|
557 #else |
|
558 return QString(); |
|
559 #endif |
|
560 } |
|
561 |
|
562 #if defined(Q_OS_SYMBIAN) |
|
563 /*! |
|
564 \brief reads the collations.txt file and reads the list of symbian collation codes |
|
565 */ |
|
566 void readCollations() |
|
567 { |
|
568 QFile* file = new QFile(COLLATION_LIST_FILE); |
|
569 if (!file->exists() ) |
|
570 { |
|
571 delete file; |
|
572 return ; |
|
573 } |
|
574 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) |
|
575 { |
|
576 delete file; |
|
577 return ; |
|
578 } |
|
579 QTextStream in(file); |
|
580 while (!in.atEnd()) |
|
581 { |
|
582 QString line = in.readLine(256); |
|
583 if (!line.isEmpty()) |
|
584 { |
|
585 int colCode = line.toUInt(); |
|
586 collations.append(colCode); |
|
587 } |
|
588 } |
|
589 return ; |
|
590 } |
|
591 #endif |
|
592 |
|
593 /*! |
|
594 \brief Returns identifiers of collations supported in a device. |
|
595 Collation identifier may be two-letter ISO 639 language code or combination of ISO 639 language code and ISO 3166 country code |
|
596 Ex: Great Britain english it returns "en". |
|
597 Ex: For U.S. english it returns "en_US" |
|
598 |
|
599 \attention Symbian specific API |
|
600 |
|
601 \return identifiers of supported collations for Symbian and empty QStringList for other platforms |
|
602 */ |
|
603 QStringList HbLocaleUtil::supportedCollations() |
|
604 { |
|
605 #if defined(Q_OS_SYMBIAN) |
|
606 if(!availCollations.isEmpty()) |
|
607 { |
|
608 return availCollations; |
|
609 } |
|
610 |
|
611 if(collations.isEmpty()) |
|
612 { |
|
613 readCollations(); |
|
614 } |
|
615 |
|
616 if(mappingList.isEmpty()) |
|
617 { |
|
618 readMappings(); |
|
619 } |
|
620 int colCount = collations.count(); |
|
621 for(int i = 0; i < colCount; i++) |
|
622 { |
|
623 int collation = collations.at(i); |
|
624 int count = mappingList.count(); |
|
625 for (int j = 0; j < count; j++) |
|
626 { |
|
627 HbLocaleMapping mapping = mappingList.at(j); |
|
628 QString colCode = mapping.collationDllId; |
|
629 if(collation == colCode.toUInt()) |
|
630 { |
|
631 availCollations.append(mapping.collName); |
|
632 break; |
|
633 } |
|
634 } |
|
635 } |
|
636 return availCollations; |
|
637 #else |
|
638 return QStringList(); |
|
639 #endif |
|
640 } |
|
641 |
|
642 /*! |
|
643 \brief Converts collation identifier to localised collation name. |
|
644 |
|
645 \attention Symbian specific API |
|
646 |
|
647 \param collation region collation identifier |
|
648 |
|
649 \return Symbian - localised name of the collation, an empty String if translation fails |
|
650 \return other platforms - empty QString |
|
651 */ |
|
652 QString HbLocaleUtil::localisedCollationName( const QString &collation ) |
|
653 { |
|
654 #if defined(Q_OS_SYMBIAN) |
|
655 if(locCollationNames.isEmpty()) |
|
656 { |
|
657 QTranslator translator; |
|
658 QString path = "c:"; |
|
659 path += QString(COLLATION_TRANSLATOR_PATH); |
|
660 if (!translator.load(path)) { |
|
661 path = "z:"; |
|
662 path += QString(COLLATION_TRANSLATOR_PATH); |
|
663 if (!translator.load(path)) { |
|
664 return QString(""); |
|
665 } |
|
666 } |
|
667 |
|
668 QCoreApplication::installTranslator(&translator); |
|
669 |
|
670 if(availCollations.isEmpty()) |
|
671 { |
|
672 readCollations(); |
|
673 } |
|
674 int cnt = availCollations.count(); |
|
675 for(int i = 0 ; i < cnt; i++ ) |
|
676 { |
|
677 QString col = availCollations.at(i); |
|
678 QString collationName = QString(COLLATION_ID_PREFIX); |
|
679 collationName += '_'; |
|
680 collationName += col; |
|
681 QString locColName = hbTrId(collationName.toAscii().constData()); |
|
682 if(locColName != collationName) |
|
683 locCollationNames.insert(col, locColName); |
|
684 } |
|
685 } |
|
686 |
|
687 return locCollationNames.value(collation); |
|
688 #else |
|
689 Q_UNUSED(collation); |
|
690 return QString(); |
|
691 #endif |
|
692 } |
|
693 |
|
694 /*! |
|
695 \brief Changes the system collation. |
|
696 The collation parameter should correspond with one of the identifiers returned by supportedCollations(). |
|
697 |
|
698 \attention Symbian specific API |
|
699 |
|
700 \param collation identifier of collation to set active |
|
701 \return true if collation change was successful for Symbian and false for other platforms |
|
702 */ |
|
703 bool HbLocaleUtil::changeCollation( const QString &collation ) |
|
704 { |
|
705 #if defined(Q_OS_SYMBIAN) |
|
706 TExtendedLocale dummy; |
|
707 QString colDllName = QString( "elocl_col." ); |
|
708 |
|
709 if(mappingList.isEmpty()) |
|
710 { |
|
711 readMappings(); |
|
712 } |
|
713 int count = mappingList.count(); |
|
714 for (int j = 0; j < count; j++) |
|
715 { |
|
716 HbLocaleMapping mapping = mappingList.at(j); |
|
717 QString name = mapping.collName; |
|
718 if(name == collation) |
|
719 { |
|
720 dummy.LoadSystemSettings(); |
|
721 colDllName += mapping.collationDllId; |
|
722 TPtrC nameptr(colDllName.utf16()); |
|
723 TInt err = dummy.LoadLocaleAspect( nameptr ); |
|
724 if( err != KErrNone ) |
|
725 return false; |
|
726 dummy.SaveSystemSettings(); |
|
727 // cause localeprivate update on next qlocale object |
|
728 QSystemLocale dummy2; |
|
729 return true; |
|
730 } |
|
731 } |
|
732 return false; |
|
733 #else |
|
734 Q_UNUSED(collation); |
|
735 return false; |
|
736 #endif |
|
737 } |
|
738 |
|
739 /*! |
|
740 \brief Return identifier of the current collation. |
|
741 |
|
742 \attention Symbian specific API |
|
743 |
|
744 \return identifier of the collation for Symbian and empty QString for other platforms |
|
745 */ |
|
746 QString HbLocaleUtil::currentCollation() |
|
747 { |
|
748 #if defined(Q_OS_SYMBIAN) |
|
749 if(mappingList.isEmpty()) |
|
750 { |
|
751 readMappings(); |
|
752 } |
|
753 TExtendedLocale dummy; |
|
754 dummy.LoadSystemSettings(); |
|
755 TBuf<256> name; |
|
756 dummy.GetLocaleDllName(ELocaleCollateSetting,name); |
|
757 |
|
758 QString dllname; |
|
759 #ifdef QT_NO_UNICODE |
|
760 dllname = QString::fromLocal8Bit(name.Ptr(), name.Length()); |
|
761 #else |
|
762 dllname = QString::fromUtf16(name.Ptr(), name.Length()); |
|
763 #endif |
|
764 |
|
765 dllname = dllname.right(COLLATION_DLL_PREFIX_POSITION); |
|
766 int cnt = mappingList.count(); |
|
767 for(int i = 0; i < cnt; i++) |
|
768 { |
|
769 HbLocaleMapping mapping = mappingList.at(i); |
|
770 QString dllid = mapping.collationDllId; |
|
771 if(dllid == dllname) |
|
772 { |
|
773 return mapping.collName; |
|
774 } |
|
775 } |
|
776 return QString(); |
|
777 #else |
|
778 return QString(); |
|
779 #endif |
|
780 } |
|
781 |
|
782 /*! |
|
783 \brief Changes the system language, region and collation. |
|
784 The language parameter should correspond with one of the identifiers returned by supportedLanguages(). |
|
785 Proper region and collation is selected automatically according the language. |
|
786 |
|
787 \attention Symbian specific API |
|
788 |
|
789 \param language identifier of language which language, region and collation settings should set active |
|
790 |
|
791 \return Symbian - true if language, region and collation change was successful |
|
792 \return other platforms - false |
|
793 */ |
|
794 bool HbLocaleUtil::changeLocale( const QString &language ) |
|
795 { |
|
796 #if defined(Q_OS_SYMBIAN) |
|
797 if(mappingList.isEmpty()) { |
|
798 readMappings(); |
|
799 } |
|
800 |
|
801 for (int i = 0; i < mappingList.count(); ++i) { |
|
802 HbLocaleMapping map = mappingList.at(i); |
|
803 if (map.langName == language) { |
|
804 if (!changeLanguage(map.langName)) { |
|
805 return false; |
|
806 } |
|
807 if (!changeRegion(map.regName)) { |
|
808 return false; |
|
809 } |
|
810 if (!changeCollation(map.collName)) { |
|
811 return false; |
|
812 } |
|
813 return true; |
|
814 } |
|
815 } |
|
816 #else |
|
817 Q_UNUSED(language); |
|
818 #endif // Q_OS_SYMBIAN |
|
819 return false; |
|
820 } |
|
821 |