363 fStream.WriteInt8L( locale.NegativeCurrencyFormat() ); |
381 fStream.WriteInt8L( locale.NegativeCurrencyFormat() ); |
364 fStream.WriteInt8L( locale.NegativeLoseSpace() ); |
382 fStream.WriteInt8L( locale.NegativeLoseSpace() ); |
365 fStream.WriteInt8L( locale.NegativeCurrencySymbolOpposite() ); |
383 fStream.WriteInt8L( locale.NegativeCurrencySymbolOpposite() ); |
366 fStream.WriteInt16L( locale.DigitType() ); |
384 fStream.WriteInt16L( locale.DigitType() ); |
367 |
385 |
368 // Then save display language independent data |
|
369 SaveIndependentDataL( locale, aPath ); |
|
370 |
|
371 // If CommitL leaves it means probably full disk. |
386 // If CommitL leaves it means probably full disk. |
372 // It is here assumed that data has not been changed if this leaves. |
387 // It is here assumed that data has not been changed if this leaves. |
373 fStream.CommitL(); |
388 fStream.CommitL(); |
374 |
389 |
375 CleanupStack::PopAndDestroy( &fStream ); |
390 CleanupStack::PopAndDestroy( &fStream ); |
376 CleanupStack::PopAndDestroy( fName ); |
391 CleanupStack::PopAndDestroy( fName ); |
377 } |
392 } |
378 |
393 |
379 |
394 |
380 // --------------------------------------------------------------------------- |
395 // --------------------------------------------------------------------------- |
381 // CSsmLocaleObserverSup::LoadLocaleL |
396 // CSsmLocaleObserverSup::LoadRegionL |
382 // --------------------------------------------------------------------------- |
397 // --------------------------------------------------------------------------- |
383 // |
398 // |
384 void CSsmLocaleObserverSup::LoadLocaleL( const TDesC& aPath ) |
399 void CSsmLocaleObserverSup::LoadRegionL( const TDesC& aPath ) |
385 { |
400 { |
386 FUNC_LOG; |
401 FUNC_LOG; |
387 INFO( "Loading locale data" ); |
402 INFO( "Loading region data" ); |
388 |
403 |
389 HBufC* fName = MakeFileNameL( aPath, KFileName, User::Language() ); |
404 TInt region = MappedRegionL(User::Language()); |
|
405 HBufC* fName = MakeFileNameL( aPath, KFileName, region); |
390 CleanupStack::PushL( fName ); |
406 CleanupStack::PushL( fName ); |
391 |
407 |
392 TLocale locale; // copy current values |
408 TLocale locale; // copy current values |
393 |
409 |
394 RFileReadStream fStream; |
410 RFileReadStream fStream; |
448 locale.SetNegativeLoseSpace( fStream.ReadInt8L() ); |
464 locale.SetNegativeLoseSpace( fStream.ReadInt8L() ); |
449 locale.SetNegativeCurrencySymbolOpposite( fStream.ReadInt8L() ); |
465 locale.SetNegativeCurrencySymbolOpposite( fStream.ReadInt8L() ); |
450 locale.SetDigitType( static_cast< TDigitType >( fStream.ReadInt16L() ) ); |
466 locale.SetDigitType( static_cast< TDigitType >( fStream.ReadInt16L() ) ); |
451 } |
467 } |
452 |
468 |
453 // Then patch data with locale independent data (code 00) |
|
454 // No changes to locale if no independent data can be found (the very first boot) |
|
455 LoadIndependentDataL( locale, aPath ); |
|
456 |
|
457 // Save changes to the system. |
469 // Save changes to the system. |
458 locale.Set(); |
470 locale.Set(); |
459 |
471 |
460 CleanupStack::PopAndDestroy( &fStream ); |
472 CleanupStack::PopAndDestroy( &fStream ); |
461 CleanupStack::PopAndDestroy( fName ); |
473 CleanupStack::PopAndDestroy( fName ); |
462 } |
474 } |
463 |
475 |
464 |
476 void CSsmLocaleObserverSup::InitializeRegionMappingL() |
465 // --------------------------------------------------------------------------- |
477 { |
466 // CSsmLocaleObserverSup::SaveIndependentDataL |
478 //Reserve the memory for the number of mappings to be appended |
467 // --------------------------------------------------------------------------- |
479 iLangRegionMappingHashSet.ReserveL( KMaxNumberOfRegions ); |
468 // |
480 |
469 void CSsmLocaleObserverSup::SaveIndependentDataL( |
481 //Insert the Language - Region mapping |
470 const TLocale& aLocale, |
482 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish, ERegGBR ) ); |
471 const TDesC& aPath ) |
483 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangFrench, ERegFRA ) ); |
472 { |
484 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangGerman, ERegDEU ) ); |
473 FUNC_LOG; |
485 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangSpanish, ERegESP ) ); |
474 |
486 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangItalian, ERegITA ) ); |
475 // Get old independent data, if any. |
487 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangSwedish, ERegSWE ) ); |
476 TLocale savedLoc; |
488 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangDanish, ERegDNK ) ); |
477 TRAPD( err, LoadIndependentDataL( savedLoc, aPath ) ); |
489 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangNorwegian, ERegNOR ) ); |
478 ERROR( err, "Failed to load locale independent data" ); |
490 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangFinnish, ERegFIN ) ); |
479 |
491 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangAmerican, ERegUSA ) ); |
480 HBufC* fName = MakeFileNameL( aPath, KCommonFileName, 0 ); |
492 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangPortuguese, ERegPRT ) ); |
481 CleanupStack::PushL( fName ); |
493 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangTurkish, ERegTUR ) ); |
482 RFileWriteStream fStream; |
494 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangIcelandic, ERegISL ) ); |
483 CleanupClosePushL( fStream ); |
495 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangRussian, ERegRUS ) ); |
484 |
496 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangHungarian, ERegHUN ) ); |
485 err = iFs.MkDirAll( *fName ); // Ignore errors |
497 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangDutch, ERegNLD ) ); |
486 err = fStream.Create( iFs, *fName, EFileWrite ); |
498 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangBelgianFlemish, ERegBEL ) ); |
487 if ( err == KErrAlreadyExists ) |
499 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangCzech, ERegCZE ) ); |
488 { |
500 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangSlovak, ERegSVK ) ); |
489 // Override |
501 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangPolish, ERegPOL ) ); |
490 err = fStream.Open( iFs, *fName, EFileWrite ); |
502 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangSlovenian, ERegSVN ) ); |
491 ERROR_1( err, "Failed to create stream %S", fName ); |
503 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangTaiwanChinese, ERegTWN ) ); |
492 } |
504 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangHongKongChinese, ERegHKG ) ); |
493 User::LeaveIfError( err ); |
505 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangPrcChinese, ERegCHN ) ); |
494 |
506 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangJapanese, ERegJPN ) ); |
495 // Write first the version number to enable support for file format changes. |
507 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangThai, ERegTHA ) ); |
496 fStream.WriteInt8L( KCurrentVersionNumber ); |
508 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangArabic, ERegARE ) ); |
497 fStream.WriteInt32L( 0 ); // Universal time offset is not part of TLocale |
509 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangTagalog, ERegPHL ) ); |
498 // any more. Write zero here to keep file structure. |
510 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangBulgarian, ERegBGR ) ); |
499 // Clock format is also common. |
511 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangCatalan, ERegESP ) ); |
500 fStream.WriteUint32L( aLocale.ClockFormat() ); |
512 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangCroatian, ERegHRV ) ); |
501 fStream.WriteUint32L( 0 ); // reserved 2 |
513 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEstonian, ERegEST ) ); |
502 fStream.WriteUint32L( 0 ); // reserved 3 |
514 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangFarsi, ERegIRN ) ); |
503 |
515 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangCanadianFrench, ERegCAN ) ); |
504 fStream.CommitL(); |
516 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangGreek, ERegGRC ) ); |
505 |
517 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangHebrew, ERegISR ) ); |
506 CleanupStack::PopAndDestroy( &fStream ); |
518 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangHindi, ERegIND ) ); |
507 CleanupStack::PopAndDestroy( fName ); |
519 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangIndonesian, ERegIDN ) ); |
508 } |
520 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangLatvian, ERegLVA ) ); |
509 |
521 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangLithuanian, ERegLTU ) ); |
510 |
522 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangMalay, ERegMYS ) ); |
511 // --------------------------------------------------------------------------- |
523 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangBrazilianPortuguese, ERegBRA ) ); |
512 // CSsmLocaleObserverSup::LoadIndependentDataL |
524 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangRomanian, ERegROU ) ); |
513 // --------------------------------------------------------------------------- |
525 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangSerbian, ERegSCG ) ); |
514 // |
526 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangLatinAmericanSpanish, ERegMEX )); |
515 void CSsmLocaleObserverSup::LoadIndependentDataL( |
527 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangUkrainian, ERegUKR ) ); |
516 TLocale& aLocale, |
528 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangUrdu, ERegPAK ) ); |
517 const TDesC& aPath ) |
529 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangVietnamese, ERegVNM ) ); |
518 { |
530 #ifdef __E32LANG_H__ |
519 FUNC_LOG; |
531 // 5.0 |
520 |
532 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangBasque, ERegESP ) ); |
521 HBufC* fName = MakeFileNameL( aPath, KCommonFileName, 0 ); |
533 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangGalician, ERegESP ) ); |
522 CleanupStack::PushL( fName ); |
534 #endif //__E32LANG_H__ |
523 |
535 #if !defined(__SERIES60_31__) |
524 RFileReadStream fStream; |
536 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_Apac, ERegGBR ) ); |
525 CleanupClosePushL( fStream ); |
537 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_Taiwan, ERegTWN ) ); |
526 TInt err = fStream.Open( iFs, *fName, EFileRead ); |
538 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_HongKong, ERegHKG ) ); |
527 if ( err != KErrNotFound && err != KErrPathNotFound ) |
539 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_Prc, ERegCHN ) ); |
528 { |
540 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_Japan, ERegJPN ) ); |
529 ERROR_1( err, "Failed to open stream %S", fName ); |
541 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangEnglish_Thailand, ERegTHA ) ); |
530 // Data file is missing upon the first boot or when switching into a |
542 iLangRegionMappingHashSet.InsertL( TLanguageRegion( ELangMalay_Apac, ERegMYS ) ); |
531 // language for the first time |
543 #endif //!defined(__SERIES60_31__) |
532 } |
544 } |
533 |
545 |
534 if ( err == KErrNotFound || err == KErrPathNotFound ) |
546 // --------------------------------------------------------------------------- |
535 { |
547 // CSsmLocaleObserverSup::MappedRegionL |
536 // File not found --> Not an error because |
548 // --------------------------------------------------------------------------- |
537 // this is a new file and older builds do not have this file. |
549 // |
538 INFO( "No locale data found" ); |
550 TInt CSsmLocaleObserverSup::MappedRegionL(const TInt aLanguage) |
539 } |
551 { |
540 else |
552 FUNC_LOG; |
541 { |
553 TLanguageRegion langRegion = iLangRegionMappingHashSet.FindL(TLanguageRegion(aLanguage)); |
542 User::LeaveIfError( err ); |
554 return langRegion.iRegion; |
543 |
555 } |
544 fStream.ReadInt8L(); // Version. |
|
545 fStream.ReadInt32L(); // Universal time offset was stored here. |
|
546 aLocale.SetClockFormat( ( TClockFormat ) fStream.ReadUint32L() ); |
|
547 fStream.ReadUint32L(); // reserved 2 |
|
548 fStream.ReadUint32L(); // reserved 3 |
|
549 } |
|
550 |
|
551 CleanupStack::PopAndDestroy( &fStream ); |
|
552 CleanupStack::PopAndDestroy( fName ); |
|
553 } |
|