47 #include <hblocaleutil.h> |
47 #include <hblocaleutil.h> |
48 |
48 |
49 #if defined(Q_OS_SYMBIAN) |
49 #if defined(Q_OS_SYMBIAN) |
50 #define LANGUAGE_LIST_FILE "/resource/hbi18n/translations/language_list.txt" |
50 #define LANGUAGE_LIST_FILE "/resource/hbi18n/translations/language_list.txt" |
51 #define LANGUAGE_MAPPINGS_FILE "/resource/hbi18n/translations/locale_mappings.txt" |
51 #define LANGUAGE_MAPPINGS_FILE "/resource/hbi18n/translations/locale_mappings.txt" |
52 #define LANGUAGE_ID_PREFIX "language" |
52 #define LANGUAGE_ID_PREFIX "txt_language" |
53 #define LANGUAGE_TRANSLATOR_PATH "/resource/hbi18n/translations/languages" |
53 #define LANGUAGE_TRANSLATOR_PATH "/resource/hbi18n/translations/languages" |
54 |
54 |
55 #define REGION_LIST_FILE "z:/resource/bootdata/regions.txt" |
55 #define REGION_LIST_FILE "z:/resource/bootdata/regions.txt" |
56 #define REGION_ID_PREFIX "region" |
56 #define REGION_ID_PREFIX "txt_region" |
57 #define REGION_TRANSLATOR_PATH "/resource/hbi18n/translations/regions" |
57 #define REGION_TRANSLATOR_PATH "/resource/hbi18n/translations/regions" |
58 #define REGION_DLL_PREFIX "elocl_reg." |
58 #define REGION_DLL_PREFIX "elocl_reg." |
59 |
59 |
60 #define COLLATION_LIST_FILE "z:/resource/bootdata/collations.txt" |
60 #define COLLATION_LIST_FILE "z:/resource/bootdata/collations.txt" |
61 #define COLLATION_ID_PREFIX "collation" |
61 #define COLLATION_ID_PREFIX "txt_collation" |
62 #define COLLATION_TRANSLATOR_PATH "/resource/hbi18n/translations/collations" |
62 #define COLLATION_TRANSLATOR_PATH "/resource/hbi18n/translations/collations" |
63 #define COLLATION_DLL_PREFIX "elocl_col." |
63 #define COLLATION_DLL_PREFIX "elocl_col." |
64 #define COLLATION_DLL_PREFIX_POSITION 3 |
64 #define COLLATION_DLL_PREFIX_POSITION 3 |
65 #endif // Q_OS_SYMBIAN |
65 #endif // Q_OS_SYMBIAN |
66 |
66 |
67 /*! |
67 /*! |
68 @beta |
68 @beta |
69 @hbcore |
69 @hbcore |
70 \class HbLocaleUtil |
70 \class HbLocaleUtil |
71 \brief HbLocaleUtil provides functions for quering supported languages, regions and collations and activing them. |
71 \brief The HbLocaleUtil class supports querying the supported languages, regions and collations, and activating them. |
72 |
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. |
73 With HbLocaleUtil, you can query the supported languages, regions and |
74 Region identifiers always corresponds with two-letter ISO 3166 country code. |
74 collations from the device, and the ones currently set in the device. You |
75 |
75 can then use this data to activate the language, region and collation in the |
76 HbLocaleUtil also provides functions for converting language, region and collation identifiers to their localised names. |
76 device; either individually, or as a set determined by the specified |
|
77 language. |
|
78 |
|
79 HbLocaleUtil returns the data from the device as identifiers. |
|
80 The language and collation identifiers typically correspond to two-letter ISO 639 language codes. |
|
81 However, some languages and collations use a combination of an ISO 639 language code |
|
82 and an ISO 3166 country code which are separated by the underscore character. |
|
83 Region identifiers always correspond to a two-letter ISO 3166 country code. |
|
84 |
|
85 HbLocaleUtil also provides functions for converting language, region and |
|
86 collation identifiers to their localized names. |
|
87 |
|
88 Example: |
|
89 \snippet{unittest_hblocaleutil/unittest_hblocaleutil.cpp,1} |
|
90 |
|
91 |
|
92 \sa HbStringUtil, HbExtendedLocale |
|
93 |
77 */ |
94 */ |
78 |
95 |
79 #if defined(Q_OS_SYMBIAN) |
96 #if defined(Q_OS_SYMBIAN) |
80 |
97 |
81 struct HbLocaleMapping |
98 struct HbLocaleMapping |
154 #endif // Q_OS_SYMBIAN |
173 #endif // Q_OS_SYMBIAN |
155 |
174 |
156 #if defined(Q_OS_SYMBIAN) |
175 #if defined(Q_OS_SYMBIAN) |
157 |
176 |
158 /*! |
177 /*! |
159 \brief Changes the system UI language. |
178 \relates HbLocaleUtil |
160 |
179 |
161 \param dllExtension extension of the locale dll |
180 Changes the system UI language. |
162 \return true if operation was successful |
181 |
|
182 \param dllExtension The extension of the locale DLL. |
|
183 |
|
184 \return True if successful, otherwise false. |
|
185 |
163 */ |
186 */ |
164 bool setLocale( const QString &dllExtension ) |
187 bool setLocale( const QString &dllExtension ) |
165 { |
188 { |
166 TExtendedLocale dummy; |
189 TExtendedLocale dummy; |
167 dummy.LoadSystemSettings(); |
190 dummy.LoadSystemSettings(); |
177 return true; |
200 return true; |
178 } |
201 } |
179 #endif //Q_OS_SYMBIAN |
202 #endif //Q_OS_SYMBIAN |
180 |
203 |
181 /*! |
204 /*! |
182 \brief Return identifier of the current UI language. |
205 |
183 |
206 Returns the identifier of the current UI language. |
184 \attention Symbian specific API |
207 Identifier is typically two-letter ISO 639 code, like "en" for universal english, |
185 |
208 but for some languages such United States english it is combination of an ISO 639 code and an ISO 3166 code ("en_US") |
186 \return Identifier of the language code for Symbian and empty QString for other platforms. |
209 |
|
210 \attention Only fully implemented on the Symbian platform. For other |
|
211 platforms, always returns an empty QString. |
|
212 |
|
213 \sa supportedLanguages(), localisedLanguageName(), changeLanguage() |
|
214 |
187 */ |
215 */ |
188 QString HbLocaleUtil::currentLanguage() |
216 QString HbLocaleUtil::currentLanguage() |
189 { |
217 { |
190 #if defined(Q_OS_SYMBIAN) |
218 #if defined(Q_OS_SYMBIAN) |
191 TLanguage l = User::Language(); |
219 TLanguage l = User::Language(); |
203 #endif |
231 #endif |
204 return QString(); |
232 return QString(); |
205 } |
233 } |
206 |
234 |
207 /*! |
235 /*! |
208 \brief Returns identifiers of languages supported in a device. |
236 |
209 Language identifier may be two-letter ISO 639 language code or combination of ISO 639 language code and ISO 3166 country code |
237 Returns the identifiers of the languages supported on the device. The |
210 Ex: Great Britain english it returns "en". |
238 language identifier can be either a two-letter ISO 639 language code, or a |
211 Ex: For U.S. english it returns "en_US" |
239 combination of an ISO 639 language code and an ISO 3166 country code. For |
212 |
240 example, for UK English, this returns "en", and for US English, this returns |
213 \attention Symbian specific API |
241 "en_US". |
214 |
242 |
215 \return identifiers of supported languages for Symbian and empty QStringList for other platforms |
243 \attention Only fully implemented on the Symbian platform. For other |
|
244 platforms, always returns an empty QStringList. |
|
245 |
|
246 \sa localisedLanguageName(), currentLanguage(), changeLanguage(), changeLocale() |
|
247 |
216 */ |
248 */ |
217 QStringList HbLocaleUtil::supportedLanguages() |
249 QStringList HbLocaleUtil::supportedLanguages() |
218 { |
250 { |
219 #if defined(Q_OS_SYMBIAN) |
251 #if defined(Q_OS_SYMBIAN) |
220 QStringList languages; |
252 QStringList languages; |
246 return QStringList(); |
278 return QStringList(); |
247 #endif |
279 #endif |
248 } |
280 } |
249 |
281 |
250 /*! |
282 /*! |
251 \brief Converts two or five letter language identifier code to localised language name. |
283 |
252 |
284 Returns the localised language name for the specified language identifier. |
253 \attention Symbian specific API |
285 If the translation fails, returns an empty QString. |
254 |
286 |
255 \param language identifier |
287 \param language The two- or five-letter language identifier that correspond to an identifier returned by supportedLanguages() |
256 |
288 |
257 \return Symbian - localised name of the language, an empty String if translation fails |
289 \attention Only fully implemented on the Symbian platform. For other |
258 \return other platforms - empty QString |
290 platforms, always returns an empty QString. |
|
291 |
|
292 \sa changeLanguage(), currentLanguage() |
|
293 |
259 */ |
294 */ |
260 QString HbLocaleUtil::localisedLanguageName( const QString &language ) |
295 QString HbLocaleUtil::localisedLanguageName( const QString &language ) |
261 { |
296 { |
262 #if defined(Q_OS_SYMBIAN) |
297 #if defined(Q_OS_SYMBIAN) |
263 QTranslator translator; |
298 QTranslator translator; |
285 return QString(); |
320 return QString(); |
286 #endif |
321 #endif |
287 } |
322 } |
288 |
323 |
289 /*! |
324 /*! |
290 \brief Changes the system language. |
325 |
291 The language parameter should correspond with one of the identifiers returned by supportedLanguages(). |
326 Changes the system language to the one specified in \a language. |
292 |
|
293 \attention Symbian specific API |
|
294 |
327 |
295 \param language identifier of language to set active |
328 \param language The language identifier. This must correspond to an |
296 |
329 identifier returned by supportedLanguages(). |
297 \return true if language change was successful and false for other platforms |
330 |
|
331 \return True if successful, otherwise false. |
|
332 |
|
333 \attention Only fully implemented on the Symbian platform. For other |
|
334 platforms, always returns false. |
|
335 |
|
336 \sa localisedLanguageName(), currentLanguage() |
|
337 |
298 */ |
338 */ |
299 bool HbLocaleUtil::changeLanguage( const QString &language ) |
339 bool HbLocaleUtil::changeLanguage( const QString &language ) |
300 { |
340 { |
301 #if defined(Q_OS_SYMBIAN) |
341 #if defined(Q_OS_SYMBIAN) |
302 if(mappingList.isEmpty()) { |
342 if(mappingList.isEmpty()) { |
379 return; |
419 return; |
380 } |
420 } |
381 #endif |
421 #endif |
382 |
422 |
383 /*! |
423 /*! |
384 \brief Returns names supported regions in a phone. |
424 |
385 Region names are identified by 2 letter code(ISO 3166 standard). |
425 Returns the identifiers of regions supported on the device. The region |
386 Ex: For United Kingdom it returns GB |
426 identifier is a two-letter ISO 3166 code, for example, "GB" for United |
387 |
427 Kingdom. |
388 \attention Symbian specific API |
428 |
389 |
429 \attention Only fully implemented on the Symbian platform. For other |
390 \return list of supported regions in a device for Symbian and empty QStringList for other platforms |
430 platforms, always returns an empty QStringList. |
|
431 |
|
432 \sa localisedRegionName(), currentRegion(), changeRegion() |
|
433 |
391 */ |
434 */ |
392 QStringList HbLocaleUtil::supportedRegions() |
435 QStringList HbLocaleUtil::supportedRegions() |
393 { |
436 { |
394 #if defined(Q_OS_SYMBIAN) |
437 #if defined(Q_OS_SYMBIAN) |
395 if(!availRegions.isEmpty()) |
438 if(!availRegions.isEmpty()) |
427 return QStringList(); |
470 return QStringList(); |
428 #endif |
471 #endif |
429 } |
472 } |
430 |
473 |
431 /*! |
474 /*! |
432 \brief Converts two letter region identifier to localised region name. |
475 |
433 |
476 Returns the localised region name for the given two-letter region |
434 \attention Symbian specific API |
477 identifier. If the translation fails, returns an empty String. ###QString? |
435 |
478 |
436 \param region region identifier |
479 \param region The region identifier that correspond to an identifier |
437 |
480 returned by supportedRegions() |
438 \return Symbian - localised name of the region, an empty String if translation fails |
481 |
439 \return other platforms - empty QString |
482 \attention Only fully implemented on the Symbian platform. For other |
|
483 platforms, always returns an empty QString. |
|
484 |
|
485 \sa currentRegion(), changeRegion() |
|
486 |
440 */ |
487 */ |
441 QString HbLocaleUtil::localisedRegionName( const QString ®ion ) |
488 QString HbLocaleUtil::localisedRegionName( const QString ®ion ) |
442 { |
489 { |
443 #if defined(Q_OS_SYMBIAN) |
490 #if defined(Q_OS_SYMBIAN) |
444 if(locRegionNames.isEmpty()) |
491 if(locRegionNames.isEmpty()) |
479 return QString(); |
526 return QString(); |
480 #endif |
527 #endif |
481 } |
528 } |
482 |
529 |
483 /*! |
530 /*! |
484 \brief Changes the system region. |
531 Changes the system region to the one specified in \a region. |
485 The region parameter should correspond with one of the identifiers returned by supportedRegions(). |
532 |
486 |
533 \param region The region identifier. This must correspond to an identifier |
487 \attention Symbian specific API |
534 returned by supportedRegions(). |
488 |
535 |
489 \param region identifier of region to set active |
536 \return True if successful, otherwise false. |
490 |
537 |
491 \return true if region change was successful for Symbian and false for other platforms |
538 \attention Only fully implemented on the Symbian platform. For other |
|
539 platforms, always returns false. |
|
540 |
|
541 \sa localisedRegionName(), currentRegion() |
|
542 |
492 */ |
543 */ |
493 bool HbLocaleUtil::changeRegion( const QString ®ion ) |
544 bool HbLocaleUtil::changeRegion( const QString ®ion ) |
494 { |
545 { |
495 #if defined(Q_OS_SYMBIAN) |
546 #if defined(Q_OS_SYMBIAN) |
496 TExtendedLocale dummy; |
547 TExtendedLocale dummy; |
545 return false; |
596 return false; |
546 #endif |
597 #endif |
547 } |
598 } |
548 |
599 |
549 /*! |
600 /*! |
550 \brief Return identifier of the current region. |
601 |
551 |
602 Returns the identifier of the current region. |
552 \attention Symbian specific API |
603 |
553 |
604 \attention Only fully implemented on the Symbian platform. For other |
554 \return identifier of the region for Symbian and empty QString for other platforms |
605 platforms, always returns an empty QString. |
|
606 |
|
607 \sa supportedRegions(), localisedRegionName(), changeRegion() |
|
608 |
555 */ |
609 */ |
556 QString HbLocaleUtil::currentRegion() |
610 QString HbLocaleUtil::currentRegion() |
557 { |
611 { |
558 #if defined(Q_OS_SYMBIAN) |
612 #if defined(Q_OS_SYMBIAN) |
559 if(mappingList.isEmpty()) |
613 if(mappingList.isEmpty()) |
605 return ; |
659 return ; |
606 } |
660 } |
607 #endif |
661 #endif |
608 |
662 |
609 /*! |
663 /*! |
610 \brief Returns identifiers of collations supported in a device. |
664 |
611 Collation identifier may be two-letter ISO 639 language code or combination of ISO 639 language code and ISO 3166 country code |
665 Returns the identifiers of the collations supported on a device. The |
612 Ex: Great Britain english it returns "en". |
666 collation identifier is either an ISO 639 language code, or a combination of |
613 Ex: For U.S. english it returns "en_US" |
667 an ISO 639 language code and an ISO 3166 country code. |
614 |
668 |
615 \attention Symbian specific API |
669 \attention Only fully implemented on the Symbian platform. For other |
616 |
670 platforms, always returns an empty QStringList. |
617 \return identifiers of supported collations for Symbian and empty QStringList for other platforms |
671 |
|
672 \sa localisedCollationName(), currentCollation(), changeCollation() |
|
673 |
618 */ |
674 */ |
619 QStringList HbLocaleUtil::supportedCollations() |
675 QStringList HbLocaleUtil::supportedCollations() |
620 { |
676 { |
621 #if defined(Q_OS_SYMBIAN) |
677 #if defined(Q_OS_SYMBIAN) |
622 if(!availCollations.isEmpty()) |
678 if(!availCollations.isEmpty()) |
654 return QStringList(); |
710 return QStringList(); |
655 #endif |
711 #endif |
656 } |
712 } |
657 |
713 |
658 /*! |
714 /*! |
659 \brief Converts collation identifier to localised collation name. |
715 |
660 |
716 Returns the localised collation name for the given collation identifier. If |
661 \attention Symbian specific API |
717 the translation fails, returns an empty QString. |
662 |
718 |
663 \param collation region collation identifier |
719 \param collation The region collation identifier corresponding to an |
664 |
720 identifier returned by supportedCollations(). |
665 \return Symbian - localised name of the collation, an empty String if translation fails |
721 |
666 \return other platforms - empty QString |
722 \attention Only fully implemented on the Symbian platform. For other |
|
723 platforms, always returns an empty QString. |
|
724 |
|
725 \sa currentCollation(), changeCollation() |
|
726 |
667 */ |
727 */ |
668 QString HbLocaleUtil::localisedCollationName( const QString &collation ) |
728 QString HbLocaleUtil::localisedCollationName( const QString &collation ) |
669 { |
729 { |
670 #if defined(Q_OS_SYMBIAN) |
730 #if defined(Q_OS_SYMBIAN) |
671 if(locCollationNames.isEmpty()) |
731 if(locCollationNames.isEmpty()) |
706 return QString(); |
766 return QString(); |
707 #endif |
767 #endif |
708 } |
768 } |
709 |
769 |
710 /*! |
770 /*! |
711 \brief Changes the system collation. |
771 |
712 The collation parameter should correspond with one of the identifiers returned by supportedCollations(). |
772 Changes the system collation to the one specified \a collation. |
713 |
773 |
714 \attention Symbian specific API |
774 \param collation The collation identifier. This must correspond to an |
715 |
775 identifier returned by supportedCollations(). |
716 \param collation identifier of collation to set active |
776 |
717 \return true if collation change was successful for Symbian and false for other platforms |
777 \return True if successful, otherwise false. |
|
778 |
|
779 \attention Only fully implemented on the Symbian platform. For other |
|
780 platforms, always returns false. |
|
781 |
|
782 \sa localisedCollationName(), currentCollation() |
718 */ |
783 */ |
719 bool HbLocaleUtil::changeCollation( const QString &collation ) |
784 bool HbLocaleUtil::changeCollation( const QString &collation ) |
720 { |
785 { |
721 #if defined(Q_OS_SYMBIAN) |
786 #if defined(Q_OS_SYMBIAN) |
722 TExtendedLocale dummy; |
787 TExtendedLocale dummy; |
770 return false; |
835 return false; |
771 #endif |
836 #endif |
772 } |
837 } |
773 |
838 |
774 /*! |
839 /*! |
775 \brief Return identifier of the current collation. |
840 |
776 |
841 Returns the identifier of the current collation. |
777 \attention Symbian specific API |
842 Typically an identifier is ISO 639 code. |
778 |
843 |
779 \return identifier of the collation for Symbian and empty QString for other platforms |
844 \attention Only fully implemented on the Symbian platform. For other |
|
845 platforms, always returns an empty QString. |
|
846 |
|
847 \sa supportedCollations(), localisedCollationName(), changeCollation() |
780 */ |
848 */ |
781 QString HbLocaleUtil::currentCollation() |
849 QString HbLocaleUtil::currentCollation() |
782 { |
850 { |
783 #if defined(Q_OS_SYMBIAN) |
851 #if defined(Q_OS_SYMBIAN) |
784 if(mappingList.isEmpty()) |
852 if(mappingList.isEmpty()) |
811 #endif |
879 #endif |
812 return QString(); |
880 return QString(); |
813 } |
881 } |
814 |
882 |
815 /*! |
883 /*! |
816 \brief Changes the system language, region and collation. |
884 |
817 The language parameter should correspond with one of the identifiers returned by supportedLanguages(). |
885 Changes the system language, region and collation as specified by \a |
818 Proper region and collation is selected automatically according the language. |
886 language. The region and collation are selected automatically based on the |
|
887 specified language. |
|
888 |
|
889 \param language The language identifier. This must correspond to an |
|
890 identifier returned by supportedLanguages(). |
819 |
891 |
820 \attention Symbian specific API |
892 \return True if successful, otherwise false. |
821 |
893 |
822 \param language identifier of language which language, region and collation settings should set active |
894 \attention Only fully implemented on the Symbian platform. For other |
823 |
895 platforms, always returns false. |
824 \return Symbian - true if language, region and collation change was successful |
896 |
825 \return other platforms - false |
897 \sa supportedRegions(), supportedCollations() |
|
898 |
826 */ |
899 */ |
827 bool HbLocaleUtil::changeLocale( const QString &language ) |
900 bool HbLocaleUtil::changeLocale( const QString &language ) |
828 { |
901 { |
829 #if defined(Q_OS_SYMBIAN) |
902 #if defined(Q_OS_SYMBIAN) |
830 if(mappingList.isEmpty()) { |
903 if(mappingList.isEmpty()) { |
850 Q_UNUSED(language); |
923 Q_UNUSED(language); |
851 #endif // Q_OS_SYMBIAN |
924 #endif // Q_OS_SYMBIAN |
852 return false; |
925 return false; |
853 } |
926 } |
854 |
927 |
|
928 /*! |
|
929 Returns list of language, region and collation ID mappings. |
|
930 For example for UK english entry have "en" as language, "GB" as region and "en" as collation. |
|
931 Similar values for US english are "en_US", "US" and "en_US" |
|
932 |
|
933 Returned list may contain languages which does not have corresponding region, then HbLanguageRegionMapping struct has an empty region QString. |
|
934 List may also contain regions which does not have corresponding language and collation, then HbLanguageRegionMapping struct contains an empty language and collation QStrings. |
|
935 |
|
936 Example: |
|
937 \snippet{unittest_hblocaleutil/unittest_hblocaleutil.cpp,2} |
|
938 |
|
939 \attention Symbian specific API |
|
940 |
|
941 \param onlySupported Should return mappings only for those languages, regions and collations which are supported on the device |
|
942 true - returns mappings only for those languages, regions and collations which are available on device. |
|
943 false - returns all know languages, regions and collations. |
|
944 |
|
945 \return Symbian - list of language, region and collation mappings |
|
946 \return other platforms - an empty list |
|
947 */ |
|
948 QList<HbLanguageRegionMapping> HbLocaleUtil::languageRegionMappings( bool onlySupported ) |
|
949 { |
|
950 QList<HbLanguageRegionMapping> mps; |
|
951 #if defined(Q_OS_SYMBIAN) |
|
952 if (mappingList.isEmpty()) { |
|
953 readMappings(); |
|
954 } |
|
955 |
|
956 QStringList supportedLanguages; |
|
957 QStringList supportedRegions; |
|
958 if (onlySupported) { |
|
959 supportedLanguages = HbLocaleUtil::supportedLanguages(); |
|
960 supportedRegions = HbLocaleUtil::supportedRegions(); |
|
961 } |
|
962 |
|
963 for (int i = 0; i < mappingList.count(); ++i) { |
|
964 |
|
965 HbLocaleMapping map = mappingList.at(i); |
|
966 |
|
967 HbLanguageRegionMapping mapping; |
|
968 mapping.languageId = map.langName; |
|
969 mapping.regionId = map.regName; |
|
970 mapping.collationId = map.collName; |
|
971 |
|
972 if (onlySupported) { |
|
973 bool langSupported = supportedLanguages.contains(map.langName); |
|
974 bool regSupported = supportedRegions.contains(map.regName); |
|
975 if (!langSupported && !regSupported) { |
|
976 continue; |
|
977 } |
|
978 if (!langSupported) { |
|
979 mapping.languageId = ""; |
|
980 } |
|
981 if (!regSupported) { |
|
982 mapping.regionId = ""; |
|
983 } |
|
984 } |
|
985 |
|
986 mps.append(mapping); |
|
987 |
|
988 } |
|
989 #else |
|
990 Q_UNUSED(onlySupported); |
|
991 #endif // Q_OS_SYMBIAN |
|
992 return mps; |
|
993 } |
|
994 |