src/hbcore/i18n/hblanguageutil.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
   110     \return true if operation was successful
   110     \return true if operation was successful
   111 */
   111 */
   112 bool setLocale( int language )
   112 bool setLocale( int language )
   113 {
   113 {
   114     TExtendedLocale dummy;
   114     TExtendedLocale dummy;
       
   115     dummy.LoadSystemSettings();
       
   116    
       
   117     // Try to load new locale model dll
   115     QString no;
   118     QString no;
   116     no = QString( "%1" ).arg( language, 2, 10, QLatin1Char( '0' ) );
   119     if ( language < 10 ) {
   117     QString name = QString( "elocl." ).append( no );
   120         no = QString( "00%1" ).arg(language);
       
   121     } else if ( language < 100 ) {
       
   122         no = QString( "0%1" ).arg(language);
       
   123     } else {
       
   124         no = QString( "%1" ).arg(language);
       
   125     }
       
   126     
       
   127     QString name = QString("elocl_lan.").append(no);
   118     TPtrC nameptr(name.utf16());
   128     TPtrC nameptr(name.utf16());
   119     
   129     
   120     TInt err = dummy.LoadLocale( nameptr );
   130     TInt err = dummy.LoadLocaleAspect(nameptr);    
   121     if( err != KErrNone )
   131     if( err != KErrNone ) {
   122         return false;
   132         // Loading new locale model dll fails
       
   133         // Try to load old locale model dll
       
   134         no = QString("%1").arg(language, 2, 10, QLatin1Char( '0' ));
       
   135         QString name2 = QString("elocl.").append(no);
       
   136         TPtrC nameptr2(name2.utf16());
       
   137         
       
   138         TInt err2 = dummy.LoadLocale(nameptr2);
       
   139         if ( err2 != KErrNone ) {
       
   140             return false;
       
   141         }
       
   142     }
       
   143     
   123     dummy.SaveSystemSettings();
   144     dummy.SaveSystemSettings();
   124     // cause localeprivate update on next qlocale object( glp->m_language_id = 0 )
   145     // cause localeprivate update on next qlocale object( glp->m_language_id = 0 )
   125     QSystemLocale dummy2;
   146     QSystemLocale dummy2;
   126     return true;
   147     return true;
   127 }
   148 }
   132     \brief Returns names and identifiers of supported languages in a phone.
   153     \brief Returns names and identifiers of supported languages in a phone.
   133  
   154  
   134     Language names are localized according the language's native presentation.
   155     Language names are localized according the language's native presentation.
   135     Language ID's returned by this functions may be used as language parameter for changeLanguage(int language) function.
   156     Language ID's returned by this functions may be used as language parameter for changeLanguage(int language) function.
   136     Language IDs and names are OS specific and may vary across the platforms and releases.
   157     Language IDs and names are OS specific and may vary across the platforms and releases.
   137      
   158     
   138     \return localized names and integer identifiers of languages supported in a device  
   159     \attention Symbian specific API
       
   160     
       
   161     \return Symbian - localized names and integer identifiers of languages supported in a device  
       
   162     \return other platforms - empty QHash    
   139 */
   163 */
   140 QHash<int, QString> HbLanguageUtil::supportedLanguages()
   164 QHash<int, QString> HbLanguageUtil::supportedLanguages()
   141 {
   165 {
   142 #if defined(Q_OS_SYMBIAN)   
   166 #if defined(Q_OS_SYMBIAN)   
   143     QHash<int, QString> languages; 
   167     QHash<int, QString> languages; 
   144     
   168     
   145     QTranslator translator;
   169     QTranslator translator;
   146     if (!translator.load(TRANSLATOR_PATH)) {
   170     QString path = "c:";
   147         return languages;
   171     path += QString(TRANSLATOR_PATH);
       
   172     if (!translator.load(path)) {
       
   173         path = "z:";
       
   174         path += QString(TRANSLATOR_PATH);
       
   175         if (!translator.load(path)) {
       
   176             return languages;
       
   177         } 
   148     } 
   178     } 
       
   179 
   149     QCoreApplication::installTranslator(&translator);
   180     QCoreApplication::installTranslator(&translator);
   150     QHash<int, QString> hashLanguageNames = readLanguageList();
   181     QHash<int, QString> hashLanguageNames = readLanguageList();
   151  
   182  
   152     CArrayFixFlat<TInt>* systemEpocLanguageCodes = 0;
   183     CArrayFixFlat<TInt>* systemEpocLanguageCodes = 0;
   153     TInt error = SysLangUtil::GetInstalledLanguages( systemEpocLanguageCodes );
   184     TInt error = SysLangUtil::GetInstalledLanguages( systemEpocLanguageCodes );
   180  
   211  
   181     Language names are localized according the language's native presentation.
   212     Language names are localized according the language's native presentation.
   182     Language ID's returned by this functions may be used as language parameter for changeLanguage(int language) function.
   213     Language ID's returned by this functions may be used as language parameter for changeLanguage(int language) function.
   183     Language IDs and names are OS specific and may vary across the platforms and releases.
   214     Language IDs and names are OS specific and may vary across the platforms and releases.
   184      
   215      
   185     \return localized names and integer identifiers of known languages 
   216     \attention Symbian specific API
       
   217      
       
   218     \return Symbian - localized names and integer identifiers of known languages 
       
   219     \return other platforms - empty QHash    
   186 */
   220 */
   187 QHash<int, QString> HbLanguageUtil::allLanguages()
   221 QHash<int, QString> HbLanguageUtil::allLanguages()
   188 {
   222 {
   189 #if defined(Q_OS_SYMBIAN)  
   223 #if defined(Q_OS_SYMBIAN)  
   190     QHash<int, QString> langs; 
   224     QHash<int, QString> langs; 
   191     
   225     
   192     QTranslator translator;
   226     QTranslator translator;
   193     if (!translator.load(TRANSLATOR_PATH)) {
   227     QString path = "c:";
   194         return langs;
   228     path += QString(TRANSLATOR_PATH);
       
   229     if (!translator.load(path)) {
       
   230         path = "z:";
       
   231         path += QString(TRANSLATOR_PATH);
       
   232         if (!translator.load(path)) {
       
   233             return langs;
       
   234         } 
   195     } 
   235     } 
       
   236 
   196     QCoreApplication::installTranslator(&translator);
   237     QCoreApplication::installTranslator(&translator);
   197     
   238     
   198     QHash<int, QString> languageNameList = readLanguageList();
   239     QHash<int, QString> languageNameList = readLanguageList();
   199     QHashIterator<int, QString> i(languageNameList);
   240     QHashIterator<int, QString> i(languageNameList);
   200     while (i.hasNext()) {
   241     while (i.hasNext()) {
   215 #endif
   256 #endif
   216 }
   257 }
   217 
   258 
   218 /*!
   259 /*!
   219     \brief Changes the device system language.  
   260     \brief Changes the device system language.  
   220   
   261      
       
   262     \attention Symbian specific API
       
   263      
   221     \param identifier of language to set active
   264     \param identifier of language to set active
   222     \return true if language change was successful
   265     \return true for Symbian if succesfull and false for other platforms
   223 */ 
   266 */ 
   224 bool HbLanguageUtil::changeLanguage( int language )
   267 bool HbLanguageUtil::changeLanguage( int language )
   225 {
   268 {
   226 #if defined(Q_OS_SYMBIAN)
   269 #if defined(Q_OS_SYMBIAN)
   227     if ( !HbFeatureManager::instance()->featureStatus(HbFeatureManager::LanguageSwitch) ) {
   270     if ( !HbFeatureManager::instance()->featureStatus(HbFeatureManager::LanguageSwitch) ) {
   260 }
   303 }
   261 
   304 
   262 /*!
   305 /*!
   263     \brief Returns ID of current language. 
   306     \brief Returns ID of current language. 
   264   
   307   
   265     \return identifier of current system language
   308     \attention Symbian specific API
       
   309      
       
   310     \return identifier of current system language for Symbian and '0' for other platforms
   266 */ 
   311 */ 
   267 int HbLanguageUtil::currentLanguage()
   312 int HbLanguageUtil::currentLanguage()
   268 {
   313 {
   269     #if defined(Q_OS_SYMBIAN)
   314     #if defined(Q_OS_SYMBIAN)
   270         TLanguage l = User::Language();
   315         TLanguage l = User::Language();