src/hbcore/i18n/hblocaleutil.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
       
     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     QStringList languages; 
       
   221     CArrayFixFlat<TInt>* systemEpocLanguageCodes = 0;
       
   222     TInt error = SysLangUtil::GetInstalledLanguages( systemEpocLanguageCodes );
       
   223     if ( error != KErrNone ) {
       
   224         delete systemEpocLanguageCodes;
       
   225         return languages;
       
   226     }
       
   227     
       
   228     if(mappingList.isEmpty()) {
       
   229         readMappings();
       
   230     }
       
   231     
       
   232     for (int i = 0; i < systemEpocLanguageCodes->Count(); ++i) {
       
   233         int code = systemEpocLanguageCodes->At(i);
       
   234         for (int j = 0; j < mappingList.count(); ++j) {
       
   235             HbLocaleMapping map = mappingList.at(j);
       
   236             if (map.symLangValue == code) {
       
   237                 languages.append(map.langName);
       
   238                 break;
       
   239             }
       
   240         }
       
   241     }
       
   242     
       
   243     delete systemEpocLanguageCodes;
       
   244     return languages;
       
   245 #else 
       
   246     return QStringList();
       
   247 #endif
       
   248 }
       
   249 
       
   250 /*!
       
   251     \brief Converts two or five letter language identifier code to localised language name. 
       
   252     
       
   253     \attention Symbian specific API
       
   254     
       
   255     \param language identifier 
       
   256     
       
   257     \return Symbian - localised name of the language, an empty String if translation fails
       
   258     \return other platforms - empty QString    
       
   259 */ 
       
   260 QString HbLocaleUtil::localisedLanguageName( const QString &language )
       
   261 {
       
   262 #if defined(Q_OS_SYMBIAN)   
       
   263     QTranslator translator;
       
   264     QString path = "c:";
       
   265     path += QString(LANGUAGE_TRANSLATOR_PATH);
       
   266     if (!translator.load(path)) {
       
   267         path = "z:";
       
   268         path += QString(LANGUAGE_TRANSLATOR_PATH);
       
   269         if (!translator.load(path)) {
       
   270             return QString("");
       
   271         } 
       
   272     } 
       
   273     
       
   274     QCoreApplication::installTranslator(&translator);
       
   275     QString languageName = QString(LANGUAGE_ID_PREFIX);
       
   276     languageName += '_';
       
   277     languageName += language;
       
   278     QString translated = hbTrId(languageName.toAscii().constData());  
       
   279     if (translated == languageName) {
       
   280         return QString("");
       
   281     }
       
   282     return translated;
       
   283 #else 
       
   284     Q_UNUSED(language); 
       
   285     return QString();
       
   286 #endif
       
   287 }
       
   288 
       
   289 /*!
       
   290     \brief Changes the system language.  
       
   291     The language parameter should correspond with one of the identifiers returned by supportedLanguages(). 
       
   292     
       
   293     \attention Symbian specific API
       
   294   
       
   295     \param language identifier of language to set active
       
   296     
       
   297     \return true if language change was successful and false for other platforms
       
   298 */ 
       
   299 bool HbLocaleUtil::changeLanguage( const QString &language )
       
   300 {
       
   301 #if defined(Q_OS_SYMBIAN)
       
   302     if(mappingList.isEmpty()) {
       
   303         readMappings();
       
   304     }
       
   305 	
       
   306     int lanCode = -1;
       
   307     QString dllExt = "";
       
   308     for (int i = 0;  i < mappingList.count(); ++i) {
       
   309         HbLocaleMapping map = mappingList.at(i);
       
   310         if (map.langName == language) {
       
   311             lanCode = map.symLangValue;
       
   312             dllExt = map.languageDllId;
       
   313             break;
       
   314         }
       
   315     }
       
   316     
       
   317     if (lanCode == -1) {
       
   318         return false;
       
   319     }
       
   320     
       
   321     CRepository* commonEngineRepository = 0;
       
   322     TRAPD( err1, commonEngineRepository = CRepository::NewL( KCRUidCommonEngineKeys ) );    
       
   323     if ( err1 != KErrNone ) { 
       
   324         return false;
       
   325     }
       
   326     
       
   327     if (!setLocale(dllExt)) {
       
   328         delete commonEngineRepository;
       
   329         return false;
       
   330     }
       
   331         
       
   332     // Never set Language code 0 to HAL
       
   333     if ( language !=0 ) {
       
   334         if ( HAL::Set( HAL::ELanguageIndex, lanCode ) != KErrNone ) {
       
   335             delete commonEngineRepository;
       
   336             return false;
       
   337         }
       
   338     }
       
   339     if ( commonEngineRepository->Set( KGSDisplayTxtLang, lanCode ) != KErrNone ) {
       
   340         delete commonEngineRepository;
       
   341         return false;
       
   342     }
       
   343     delete commonEngineRepository;
       
   344     return true;
       
   345 
       
   346 #else
       
   347     Q_UNUSED(language);
       
   348     return false;
       
   349 #endif
       
   350 }
       
   351 
       
   352 #if defined(Q_OS_SYMBIAN)  
       
   353 /*!
       
   354     \brief reads the regions.txt file and reads the list of symbian region codes 
       
   355 */
       
   356 void readRegions()
       
   357 {
       
   358     QFile* file = new QFile(REGION_LIST_FILE);
       
   359     if (!file->exists() ) 
       
   360     {
       
   361         delete file;
       
   362         return;
       
   363     }
       
   364     if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
       
   365     {
       
   366         delete file;
       
   367         return;
       
   368     } 
       
   369     QTextStream in(file);
       
   370     while (!in.atEnd())
       
   371     {
       
   372         QString line = in.readLine(256);
       
   373         if (!line.isEmpty())
       
   374         {
       
   375             int regCode = line.toUInt();
       
   376             regions.append(regCode);
       
   377         }
       
   378     }
       
   379     return;
       
   380 }
       
   381 #endif
       
   382 
       
   383 /*!
       
   384     \brief Returns names supported regions in a phone. 
       
   385     Region names are identified by 2 letter code(ISO 3166 standard).
       
   386     Ex: For United Kingdom it returns GB 
       
   387     
       
   388     \attention Symbian specific API
       
   389 
       
   390     \return list of supported regions in a device for Symbian and empty QStringList for other platforms 
       
   391 */
       
   392 QStringList HbLocaleUtil::supportedRegions()
       
   393 {
       
   394 #if defined(Q_OS_SYMBIAN)
       
   395     if(!availRegions.isEmpty())
       
   396     {
       
   397         return availRegions;
       
   398     }
       
   399 
       
   400     if(regions.isEmpty())
       
   401     {
       
   402         readRegions();
       
   403     }
       
   404     
       
   405     if(mappingList.isEmpty())
       
   406     {
       
   407         readMappings();
       
   408     }
       
   409     int regCount = regions.count();
       
   410     for(int i = 0; i < regCount; i++)
       
   411     {
       
   412         int region = regions.at(i);
       
   413         int count = mappingList.count();
       
   414         for (int j = 0; j < count; j++)
       
   415         {
       
   416             HbLocaleMapping mapping = mappingList.at(j);
       
   417             QString regCode = mapping.regionDllId;
       
   418             if(region == regCode.toUInt())
       
   419             {
       
   420                 availRegions.append(mapping.regName);
       
   421                 break;
       
   422             }
       
   423         }
       
   424     }
       
   425     return availRegions;
       
   426 #else
       
   427     return QStringList();
       
   428 #endif
       
   429 }
       
   430 
       
   431 /*!
       
   432     \brief Converts two letter region identifier to localised region name. 
       
   433     
       
   434     \attention Symbian specific API
       
   435     
       
   436     \param region region identifier 
       
   437     
       
   438     \return Symbian - localised name of the region, an empty String if translation fails
       
   439     \return other platforms - empty QString    
       
   440 */ 
       
   441 QString HbLocaleUtil::localisedRegionName( const QString &region ) 
       
   442 {
       
   443 #if defined(Q_OS_SYMBIAN)       
       
   444     if(locRegionNames.isEmpty())
       
   445     {
       
   446         QTranslator translator;
       
   447         QString path = "c:";
       
   448         path += QString(REGION_TRANSLATOR_PATH);
       
   449         if (!translator.load(path)) {
       
   450             path = "z:";
       
   451             path += QString(REGION_TRANSLATOR_PATH);
       
   452             if (!translator.load(path)) {
       
   453                 return QString("");
       
   454             } 
       
   455         } 
       
   456 
       
   457         QCoreApplication::installTranslator(&translator);
       
   458             
       
   459         if(mappingList.isEmpty()) 
       
   460         {
       
   461             readMappings();
       
   462         }
       
   463         int cnt = mappingList.count();
       
   464         for(int i = 0 ; i < cnt; i++ )
       
   465         {
       
   466             HbLocaleMapping map = mappingList.at(i);
       
   467             QString regionName = QString(REGION_ID_PREFIX);
       
   468             regionName += '_';
       
   469             regionName += map.regName;
       
   470             QString locRegName = hbTrId(regionName.toAscii().constData());
       
   471             if(locRegName != regionName)
       
   472                 locRegionNames.insert(map.regName, locRegName);
       
   473         }
       
   474     }
       
   475     
       
   476     return locRegionNames.value(region);
       
   477 #else
       
   478     Q_UNUSED(region);
       
   479     return QString();
       
   480 #endif    
       
   481 }
       
   482 
       
   483 /*!
       
   484     \brief Changes the system region.  
       
   485     The region parameter should correspond with one of the identifiers returned by supportedRegions(). 
       
   486   
       
   487     \attention Symbian specific API
       
   488 
       
   489     \param region identifier of region to set active
       
   490     
       
   491     \return true if region change was successful for Symbian and false for other platforms
       
   492 */ 
       
   493 bool HbLocaleUtil::changeRegion( const QString &region )
       
   494 {
       
   495 #if defined(Q_OS_SYMBIAN)   
       
   496     TExtendedLocale dummy;
       
   497     QString regDllName = QString( "elocl_reg." );
       
   498     
       
   499     if(mappingList.isEmpty())
       
   500     {
       
   501         readMappings();
       
   502     }
       
   503     int count = mappingList.count();
       
   504     for (int j = 0; j < count; j++)
       
   505     {
       
   506         HbLocaleMapping mapping = mappingList.at(j);
       
   507         QString name = mapping.regName;
       
   508         if(name == region)
       
   509         {
       
   510             dummy.LoadSystemSettings();
       
   511             regDllName += mapping.regionDllId;
       
   512             TPtrC nameptr(regDllName.utf16());
       
   513             TInt err = dummy.LoadLocaleAspect( nameptr );
       
   514             if( err != KErrNone )
       
   515                 return false;
       
   516             dummy.SaveSystemSettings();
       
   517             // cause localeprivate update on next qlocale object
       
   518             QSystemLocale dummy2;
       
   519             return true; 
       
   520         }
       
   521     }
       
   522     return false;
       
   523 #else
       
   524     Q_UNUSED(region);
       
   525     return false;
       
   526 #endif    
       
   527 }
       
   528 
       
   529 /*!
       
   530     \brief Return identifier of the current region.
       
   531 
       
   532     \attention Symbian specific API
       
   533 
       
   534     \return identifier of the region for Symbian and empty QString for other platforms
       
   535 */ 
       
   536 QString HbLocaleUtil::currentRegion()
       
   537 {
       
   538 #if defined(Q_OS_SYMBIAN)      
       
   539     if(mappingList.isEmpty())
       
   540     {
       
   541         readMappings();
       
   542     }
       
   543     TRegionCode reg = User::RegionCode();
       
   544     int cnt = mappingList.count();
       
   545     for(int i = 0; i < cnt; i++)
       
   546     {
       
   547         HbLocaleMapping mapping = mappingList.at(i);
       
   548         int dllid = mapping.regionDllId.toInt();
       
   549         if(dllid == reg)
       
   550         {
       
   551             return mapping.regName;
       
   552         }
       
   553     }
       
   554 #endif    
       
   555     return QString();
       
   556 }
       
   557 
       
   558 #if defined(Q_OS_SYMBIAN)      
       
   559 /*!
       
   560     \brief reads the collations.txt file and reads the list of symbian collation codes 
       
   561 */
       
   562 void readCollations()
       
   563 {
       
   564     QFile* file = new QFile(COLLATION_LIST_FILE);
       
   565     if (!file->exists() ) 
       
   566     {
       
   567         delete file;
       
   568         return ;
       
   569     }
       
   570     if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
       
   571     {
       
   572         delete file;
       
   573         return ;
       
   574     } 
       
   575     QTextStream in(file);
       
   576     while (!in.atEnd())
       
   577     {
       
   578         QString line = in.readLine(256);
       
   579         if (!line.isEmpty())
       
   580         {
       
   581             int colCode = line.toUInt();
       
   582             collations.append(colCode);
       
   583         }
       
   584     }
       
   585     return ;
       
   586 }
       
   587 #endif
       
   588 
       
   589 /*!
       
   590     \brief Returns identifiers of collations supported in a device. 
       
   591     Collation identifier may be two-letter ISO 639 language code or combination of ISO 639 language code and ISO 3166 country code 
       
   592     Ex: Great Britain english it returns "en".
       
   593     Ex: For U.S. english it returns "en_US"  
       
   594     
       
   595     \attention Symbian specific API
       
   596 
       
   597     \return identifiers of supported collations for Symbian and empty QStringList for other platforms 
       
   598 */
       
   599 QStringList HbLocaleUtil::supportedCollations()
       
   600 {
       
   601 #if defined(Q_OS_SYMBIAN)
       
   602     if(!availCollations.isEmpty())
       
   603     {
       
   604         return availCollations;
       
   605     }
       
   606 
       
   607     if(collations.isEmpty())
       
   608     {
       
   609         readCollations();
       
   610     }
       
   611     
       
   612     if(mappingList.isEmpty())
       
   613     {
       
   614         readMappings();
       
   615     }
       
   616     int colCount = collations.count();
       
   617     for(int i = 0; i < colCount; i++)
       
   618     {
       
   619         int collation = collations.at(i);
       
   620         int count = mappingList.count();
       
   621         for (int j = 0; j < count; j++)
       
   622         {
       
   623             HbLocaleMapping mapping = mappingList.at(j);
       
   624             QString colCode = mapping.collationDllId;
       
   625             if(collation == colCode.toUInt())
       
   626             {
       
   627                 availCollations.append(mapping.collName);
       
   628                 break;
       
   629             }
       
   630         }
       
   631     }
       
   632     return availCollations;
       
   633 #else
       
   634     return QStringList();
       
   635 #endif
       
   636 }
       
   637 
       
   638 /*!
       
   639     \brief Converts collation identifier to localised collation name. 
       
   640     
       
   641     \attention Symbian specific API
       
   642     
       
   643     \param collation region collation identifier 
       
   644     
       
   645     \return Symbian - localised name of the collation, an empty String if translation fails
       
   646     \return other platforms - empty QString    
       
   647 */ 
       
   648 QString HbLocaleUtil::localisedCollationName( const QString &collation ) 
       
   649 {
       
   650 #if defined(Q_OS_SYMBIAN)       
       
   651     if(locCollationNames.isEmpty())
       
   652     {
       
   653         QTranslator translator;
       
   654         QString path = "c:";
       
   655         path += QString(COLLATION_TRANSLATOR_PATH);
       
   656         if (!translator.load(path)) {
       
   657             path = "z:";
       
   658             path += QString(COLLATION_TRANSLATOR_PATH);
       
   659             if (!translator.load(path)) {
       
   660                 return QString("");
       
   661             } 
       
   662         } 
       
   663 
       
   664         QCoreApplication::installTranslator(&translator);
       
   665             
       
   666         if(mappingList.isEmpty()) 
       
   667         {
       
   668             readMappings();
       
   669         }
       
   670         int cnt = mappingList.count();
       
   671         for(int i = 0 ; i < cnt; i++ )
       
   672         {
       
   673             HbLocaleMapping map = mappingList.at(i);
       
   674             QString collationName = QString(COLLATION_ID_PREFIX);
       
   675             collationName += '_';
       
   676             collationName += map.collName;
       
   677             QString locColName = hbTrId(collationName.toAscii().constData());
       
   678             if(locColName != collationName)
       
   679                 locCollationNames.insert(map.collName, locColName);
       
   680         }
       
   681     }
       
   682     
       
   683     return locCollationNames.value(collation);
       
   684 #else
       
   685     Q_UNUSED(collation);
       
   686     return QString();
       
   687 #endif    
       
   688 }
       
   689 
       
   690 /*!
       
   691     \brief Changes the system collation.  
       
   692     The collation parameter should correspond with one of the identifiers returned by supportedCollations(). 
       
   693   
       
   694     \attention Symbian specific API
       
   695     
       
   696     \param collation identifier of collation to set active
       
   697     \return true if collation change was successful for Symbian and false for other platforms
       
   698 */ 
       
   699 bool HbLocaleUtil::changeCollation( const QString &collation )
       
   700 {
       
   701 #if defined(Q_OS_SYMBIAN) 
       
   702     TExtendedLocale dummy;
       
   703     QString colDllName = QString( "elocl_col." );
       
   704     
       
   705     if(mappingList.isEmpty())
       
   706     {
       
   707         readMappings();
       
   708     }
       
   709     int count = mappingList.count();
       
   710     for (int j = 0; j < count; j++)
       
   711     {
       
   712         HbLocaleMapping mapping = mappingList.at(j);
       
   713         QString name = mapping.collName;
       
   714         if(name == collation)
       
   715         {
       
   716             dummy.LoadSystemSettings();
       
   717             colDllName += mapping.collationDllId;
       
   718             TPtrC nameptr(colDllName.utf16());
       
   719             TInt err = dummy.LoadLocaleAspect( nameptr );
       
   720             if( err != KErrNone )
       
   721                 return false;
       
   722             dummy.SaveSystemSettings();
       
   723             // cause localeprivate update on next qlocale object
       
   724             QSystemLocale dummy2;
       
   725             return true; 
       
   726         }
       
   727     }
       
   728     return false;
       
   729 #else
       
   730     Q_UNUSED(collation);
       
   731     return false;
       
   732 #endif    
       
   733 }
       
   734 
       
   735 /*!
       
   736     \brief Return identifier of the current collation.
       
   737 
       
   738     \attention Symbian specific API
       
   739     
       
   740     \return identifier of the collation for Symbian and empty QString for other platforms
       
   741 */ 
       
   742 QString HbLocaleUtil::currentCollation()
       
   743 {
       
   744 #if defined(Q_OS_SYMBIAN)      
       
   745     if(mappingList.isEmpty())
       
   746     {
       
   747         readMappings();
       
   748     }
       
   749     TExtendedLocale dummy;
       
   750     dummy.LoadSystemSettings();
       
   751     TBuf<256> name;
       
   752     dummy.GetLocaleDllName(ELocaleCollateSetting,name);
       
   753 
       
   754     QString dllname;
       
   755 #ifdef QT_NO_UNICODE
       
   756     dllname = QString::fromLocal8Bit(name.Ptr(), name.Length());
       
   757 #else
       
   758     dllname = QString::fromUtf16(name.Ptr(), name.Length());
       
   759 #endif    
       
   760     
       
   761     dllname = dllname.right(COLLATION_DLL_PREFIX_POSITION);
       
   762     int cnt = mappingList.count();
       
   763     for(int i = 0; i < cnt; i++)
       
   764     {
       
   765         HbLocaleMapping mapping = mappingList.at(i);
       
   766         QString dllid = mapping.collationDllId;
       
   767         if(dllid == dllname)
       
   768         {
       
   769             return mapping.collName;
       
   770         }
       
   771     }
       
   772 #endif    
       
   773     return QString();    
       
   774 }
       
   775 
       
   776 /*!
       
   777     \brief Changes the system language, region and collation.  
       
   778     The language parameter should correspond with one of the identifiers returned by supportedLanguages(). 
       
   779     Proper region and collation is selected automatically according the language.  
       
   780   
       
   781     \attention Symbian specific API
       
   782     
       
   783     \param language identifier of language which language, region and collation settings should set active  
       
   784     
       
   785     \return Symbian - true if language, region and collation change was successful
       
   786     \return other platforms - false    
       
   787 */ 
       
   788 bool HbLocaleUtil::changeLocale( const QString &language )
       
   789 {
       
   790 #if defined(Q_OS_SYMBIAN) 
       
   791     if(mappingList.isEmpty()) {
       
   792         readMappings();
       
   793     }
       
   794 
       
   795     for (int i = 0;  i < mappingList.count(); ++i) {
       
   796         HbLocaleMapping map = mappingList.at(i);
       
   797         if (map.langName == language) {
       
   798             if (!changeLanguage(map.langName)) {
       
   799                 return false;
       
   800             } 
       
   801             if (!changeRegion(map.regName)) {
       
   802                 return false;
       
   803             } 
       
   804             if (!changeCollation(map.collName)) {
       
   805                 return false;
       
   806             } 
       
   807             return true;
       
   808         }
       
   809     }
       
   810 #else
       
   811     Q_UNUSED(language);
       
   812 #endif // Q_OS_SYMBIAN
       
   813     return false;   
       
   814 }
       
   815