18 |
18 |
19 #include <e32std.h> |
19 #include <e32std.h> |
20 #include <hal.h> |
20 #include <hal.h> |
21 |
21 |
22 #include "ssmlanguageloader.h" |
22 #include "ssmlanguageloader.h" |
23 #include "ssmcommonlocale.h" |
|
24 #include "trace.h" |
23 #include "trace.h" |
25 |
24 |
|
25 _LIT( KLocaleDllNameBase, "ELOCL" ); |
|
26 _LIT( KLocaleDllExtensionFormat, ".%u" ); |
|
27 _LIT( KLocaleDllExtensionPadding, "0" ); |
|
28 _LIT( KDefaultLocaleDllNameExtension, ".LOC" ); |
|
29 const TInt KMaxLocaleDllNameLength = 16; |
|
30 const TInt KMaxLocaleDllExtensionLength = 6; |
|
31 const TInt KMinLocaleDllExtensionLength = 3; |
|
32 const TInt KLocaleDllExtensionPaddingPosition = 1; |
|
33 |
26 // ======== MEMBER FUNCTIONS ======== |
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // SsmLanguageLoader::LoadLanguage |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 TInt SsmLanguageLoader::LoadLanguage( const TInt aLanguage ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 INFO_1( "Loading language %d", aLanguage ); |
|
45 |
|
46 TInt errorCode = StoreLanguageToHal( aLanguage ); |
|
47 ERROR( errorCode, "Failed to store language code to HAL" ); |
|
48 |
|
49 errorCode = LoadLocaleDll( aLanguage ); |
|
50 ERROR( errorCode, "Failed to load locale DLL" ); |
|
51 |
|
52 return errorCode; |
|
53 } |
|
54 |
27 |
55 |
28 // ----------------------------------------------------------------------------- |
56 // ----------------------------------------------------------------------------- |
29 // SsmLanguageLoader::StoreLanguageToHal |
57 // SsmLanguageLoader::StoreLanguageToHal |
30 // |
58 // |
31 // ----------------------------------------------------------------------------- |
59 // ----------------------------------------------------------------------------- |
37 TInt errorCode = HAL::Set( HAL::ELanguageIndex, aLanguage ); |
65 TInt errorCode = HAL::Set( HAL::ELanguageIndex, aLanguage ); |
38 return errorCode; |
66 return errorCode; |
39 } |
67 } |
40 |
68 |
41 |
69 |
42 // --------------------------------------------------------------------------- |
70 // ----------------------------------------------------------------------------- |
43 // SsmLanguageLoader::LoadLocale |
71 // SsmLanguageLoader::LoadLocaleDll |
44 // |
72 // |
45 // --------------------------------------------------------------------------- |
73 // ----------------------------------------------------------------------------- |
46 // |
74 // |
47 TInt SsmLanguageLoader::LoadLocale( const TInt aLanguage, const TInt aRegion, const TInt aCollation) |
75 TInt SsmLanguageLoader::LoadLocaleDll( const TInt aLanguage ) |
48 { |
76 { |
49 FUNC_LOG; |
77 FUNC_LOG; |
50 |
78 |
51 TInt errorCode = StoreLanguageToHal( aLanguage ); |
79 // Dot plus five digit locale |
52 ERROR( errorCode, "Failed to store language code to HAL" ); |
80 TBuf<KMaxLocaleDllExtensionLength> extension; |
|
81 extension.Format( KLocaleDllExtensionFormat, aLanguage ); |
|
82 |
|
83 // Padd ".1" to ".01" for compatibility. |
|
84 if ( extension.Length() < KMinLocaleDllExtensionLength ) |
|
85 { |
|
86 extension.Insert( KLocaleDllExtensionPaddingPosition, |
|
87 KLocaleDllExtensionPadding ); |
|
88 } |
|
89 |
|
90 TBuf<KMaxLocaleDllNameLength> localeDllName; |
|
91 localeDllName = KLocaleDllNameBase; |
|
92 localeDllName.Append( extension ); |
53 |
93 |
54 //Format the language dll to be loaded |
94 INFO_1( "Loading DLL named '%S'", &localeDllName ); |
55 //Dot plus four to six digit locale |
|
56 TBuf<KMaxDllExtensionLength> extension; |
|
57 extension.Format( KDllExtensionFormat, aLanguage ); |
|
58 |
95 |
59 //Padd with zero to make the file extension length to be minimum of four |
96 TInt errorCode = ChangeLocale( localeDllName ); |
60 for( ; extension.Length() < KMinDllExtensionLength ;) |
97 |
|
98 if ( errorCode == KErrNotFound ) // Try default locale |
61 { |
99 { |
62 extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding ); |
100 INFO( "SsmLanguageLoader: Loading default locale" ); |
|
101 |
|
102 localeDllName = KLocaleDllNameBase; |
|
103 localeDllName.Append( KDefaultLocaleDllNameExtension ); |
|
104 |
|
105 errorCode = ChangeLocale( localeDllName ); |
63 } |
106 } |
64 |
107 |
65 TBuf<KMaxDllNameLength> languageDllName( KLanguageDllNameBase ); |
|
66 languageDllName.Append( extension ); |
|
67 INFO_1( "Loading language DLL named '%S'", &languageDllName ); |
|
68 |
|
69 //Format the region dll to be loaded |
|
70 //Dot plus four to six digit locale |
|
71 extension.Zero(); |
|
72 extension.Format( KDllExtensionFormat, aRegion ); |
|
73 |
|
74 //Padd with zero to make the file extension length to be minimum of four |
|
75 for( ; extension.Length() < KMinDllExtensionLength ;) |
|
76 { |
|
77 extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding ); |
|
78 } |
|
79 |
|
80 TBuf<KMaxDllNameLength> regionDllName( KRegionDllNameBase ); |
|
81 regionDllName.Append( extension ); |
|
82 INFO_1( "Loading Region DLL named '%S'", ®ionDllName ); |
|
83 |
|
84 |
|
85 //Format the collation file to be loaded |
|
86 //Dot plus four to six digit locale |
|
87 extension.Zero(); |
|
88 extension.Format( KDllExtensionFormat, aCollation ); |
|
89 |
|
90 //Padd with zero to make the file extension length to be minimum of four |
|
91 for( ; extension.Length() < KMinDllExtensionLength ;) |
|
92 { |
|
93 extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding ); |
|
94 } |
|
95 |
|
96 TBuf<KMaxDllNameLength> collationDllName( KCollationDllNameBase ); |
|
97 collationDllName.Append( extension ); |
|
98 INFO_1( "Loading Collation DLL named '%S'", &collationDllName ); |
|
99 |
|
100 //Load the given Language, Region and Collation dlls |
|
101 errorCode = ChangeLocale( languageDllName, regionDllName, collationDllName ); |
|
102 if ( errorCode == KErrNone ) |
108 if ( errorCode == KErrNone ) |
103 { |
109 { |
104 TLocale().Set(); |
110 TLocale().Set(); |
105 } |
111 } |
|
112 |
106 return errorCode; |
113 return errorCode; |
107 } |
114 } |
108 |
115 |
109 // --------------------------------------------------------------------------- |
116 |
|
117 // ----------------------------------------------------------------------------- |
110 // SsmLanguageLoader::ChangeLocale |
118 // SsmLanguageLoader::ChangeLocale |
111 // |
119 // |
112 // --------------------------------------------------------------------------- |
120 // ----------------------------------------------------------------------------- |
113 // |
121 // |
114 TInt SsmLanguageLoader::ChangeLocale( const TDesC& aLanguageDllName, const TDesC& aRegionDllName, const TDesC& aCollationDllName ) |
122 TInt SsmLanguageLoader::ChangeLocale( const TDesC& aLocaleDllName ) |
115 { |
123 { |
116 FUNC_LOG; |
124 FUNC_LOG; |
|
125 |
117 TExtendedLocale extLocale; |
126 TExtendedLocale extLocale; |
|
127 TInt errorCode = extLocale.LoadLocale( aLocaleDllName ); |
|
128 ERROR( errorCode, "Failed to load locale" ); |
118 |
129 |
119 INFO_3( "Loading Language dll '%S', Region dll '%S' and Collation dll '%S'", |
|
120 &aLanguageDllName, &aRegionDllName, &aCollationDllName ); |
|
121 TInt errorCode = extLocale.LoadLocale( aLanguageDllName, aRegionDllName, aCollationDllName); |
|
122 if ( errorCode == KErrNone ) |
130 if ( errorCode == KErrNone ) |
123 { |
131 { |
124 //Save the loaded locale settings |
|
125 errorCode = extLocale.SaveSystemSettings(); |
132 errorCode = extLocale.SaveSystemSettings(); |
126 ERROR( errorCode, "Failed to save locale settings" ); |
133 ERROR( errorCode, "Failed to set locale" ); |
127 } |
|
128 else |
|
129 { |
|
130 INFO_3( "Failed to load Language dll '%S', Region dll '%S' and Collation dll '%S'", |
|
131 &aLanguageDllName, &aRegionDllName, &aCollationDllName ); |
|
132 } |
134 } |
133 |
135 |
134 return errorCode; |
136 return errorCode; |
135 } |
137 } |