OLD | NEW |
| (Empty) |
1 // Copyright 2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #include "omaha/common/lang.h" | |
17 #include <windows.h> | |
18 #include <set> | |
19 #include <map> | |
20 #include <vector> | |
21 #include "omaha/base/constants.h" | |
22 #include "omaha/base/commontypes.h" | |
23 #include "omaha/base/error.h" | |
24 #include "omaha/base/file.h" | |
25 #include "omaha/base/file_ver.h" | |
26 #include "omaha/base/logging.h" | |
27 #include "omaha/base/debug.h" | |
28 #include "omaha/base/path.h" | |
29 #include "omaha/base/utils.h" | |
30 #include "omaha/common/goopdate_utils.h" | |
31 | |
32 namespace omaha { | |
33 | |
34 namespace lang { | |
35 | |
36 namespace { | |
37 | |
38 const LANGID kFallbackLangID = 0x0409; | |
39 const TCHAR* const kFallbackLanguage = _T("en"); | |
40 | |
41 // This is the structure of the table which contains the language identifier | |
42 // and the associated language string. | |
43 struct LangIDAndPath { | |
44 LANGID langid; | |
45 TCHAR lang[12]; | |
46 }; | |
47 const LangIDAndPath kLanguageTranslationTable[] = { | |
48 // First we collect all main languages here which need special treatment. | |
49 // Special treatment might be necessary because of: | |
50 // 1.) Google has a special region code which is "Google specific". They | |
51 // trump everything and should be at the beginning. (e.g. "iw") | |
52 // 2.) Usually a lot of languages are like "en-US", "en-GB",... and start | |
53 // with the main language. However some languages like Norwegian do not | |
54 // follow this scheme and we put them therefore at the top. | |
55 // The matching algorithm will look first for the full match, but at the same | |
56 // time it will look for a partial match. We want to add therefore the partial | |
57 // matches as high as possible to get them as a fallback. | |
58 { 0x0409, _T("en") }, // _T("English (United States)") | |
59 { 0x040d, _T("iw") }, // _T("Hebrew") | |
60 { 0x0464, _T("fil") }, // _T("Tagalog") | |
61 { 0x0414, _T("no") }, // _T("Norwegian (Bokmal, Norway)") | |
62 | |
63 // and then we have all dialects here: | |
64 // { 0x041c, _T("sq-AL") }, // _T("Albanian (Albania)")") | |
65 // { 0x0484, _T("gsw-FR") }, // _T("Alsatian (France)") | |
66 { 0x045e, _T("am") }, // _T("am-ET") }, // _T("Amharic (Ethiopia)") | |
67 { 0x1401, _T("ar") }, // _T("ar-DZ") }, // _T("Arabic (Algeria)") | |
68 { 0x3c01, _T("ar") }, // _T("ar-BH") }, // _T("Arabic (Bahrain)") | |
69 { 0x0c01, _T("ar") }, // _T("ar-EG") }, // _T("Arabic (Egypt)") | |
70 { 0x0801, _T("ar") }, // _T("ar-IQ") }, // _T("Arabic (Iraq)") | |
71 { 0x2c01, _T("ar") }, // _T("ar-JO") }, // _T("Arabic (Jordan)") | |
72 { 0x3401, _T("ar") }, // _T("ar-KW") }, // _T("Arabic (Kuwait)") | |
73 { 0x3001, _T("ar") }, // _T("ar-LB") }, // _T("Arabic (Lebanon)") | |
74 { 0x1001, _T("ar") }, // _T("ar-LY") }, // _T("Arabic (Libya)") | |
75 { 0x1801, _T("ar") }, // _T("ar-MA") }, // _T("Arabic (Morocco)") | |
76 { 0x2001, _T("ar") }, // _T("ar-OM") }, // _T("Arabic (Oman)") | |
77 { 0x4001, _T("ar") }, // _T("ar-QA") }, // _T("Arabic (Qatar)") | |
78 { 0x0401, _T("ar") }, // _T("ar-SA") }, // _T("Arabic (Saudi Arabia)") | |
79 { 0x2801, _T("ar") }, // _T("ar-SY") }, // _T("Arabic (Syria)") | |
80 { 0x1c01, _T("ar") }, // _T("ar-TN") }, // _T("Arabic (Tunisia)") | |
81 { 0x3801, _T("ar") }, // _T("ar-AE") }, // _T("Arabic (U.A.E.)") | |
82 { 0x2401, _T("ar") }, // _T("ar-YE") }, // _T("Arabic (Yemen)") | |
83 { 0x042b, _T("ar") }, // _T("hy-AM") }, // _T("Armenian (Armenia)") | |
84 // { 0x044d, _T("as-IN") }, // _T("Assamese (India)") | |
85 // { 0x082c, _T("az-Cyrl-AZ") }, // _T("Azeri (Azerbaijan, Cyrillic)") | |
86 // { 0x042c, _T("az-Latn-AZ") }, // _T("Azeri (Azerbaijan, Latin)") | |
87 // { 0x046d, _T("ba-RU") }, // _T("Bashkir (Russia)") | |
88 // { 0x042d, _T("eu-ES") }, // _T("Basque (Basque)") | |
89 // { 0x0423, _T("be-BY") }, // _T("Belarusian (Belarus)") | |
90 { 0x0445, _T("bn") }, // _T("bn-IN") }, // _T("Bengali (India)") | |
91 // { 0x201a, _T("bs-Cyrl-BA") }, // _T("Bosnian (Bosnia and Herzegovina, | |
92 // Cyrillic)") | |
93 // { 0x141a, _T("bs-Latn-BA") }, // _T("Bosnian (Bosnia and Herzegovina, | |
94 // Latin)") | |
95 // { 0x047e, _T("br-FR") }, // _T("Breton (France)") | |
96 { 0x0402, _T("bg") }, // _T("bg-BG") }, // _T("Bulgarian (Bulgaria)") | |
97 { 0x0403, _T("ca") }, // _T("ca-ES") }, // _T("Catalan (Catalan)") | |
98 { 0x0c04, _T("zh-HK") }, // _T("zh-HK") // _T("Chinese | |
99 // (Hong Kong SAR, PRC)") | |
100 { 0x1404, _T("zh-TW") }, // _T("zh-MO") }, // _T("Chinese (Macao SAR)") | |
101 { 0x0804, _T("zh-CN") }, // _T("zh-CN") }, // _T("Chinese (PRC)") | |
102 { 0x1004, _T("zh-CN") }, // _T("zh-SG") }, // _T("Chinese (Singapore)") | |
103 { 0x0404, _T("zh-TW") }, // _T("Chinese (Taiwan)") | |
104 { 0x101a, _T("hr") }, // _T("hr-BA") }, // _T("Croatian | |
105 // (Bosnia and Herzegovina, Latin)") | |
106 { 0x041a, _T("hr") }, // _T("hr-HR") }, // _T("Croatian (Croatia)") | |
107 { 0x0405, _T("cs") }, // _T("cs-CZ") }, // _T("Czech (Czech Republic)") | |
108 { 0x0406, _T("da") }, // _T("da-DK") }, // _T("Danish (Denmark)") | |
109 // { 0x048c, _T("gbz-AF") }, // _T("Dari (Afghanistan)") | |
110 // { 0x0465, _T("dv-MV") }, // _T("Divehi (Maldives)") | |
111 { 0x0813, _T("nl") }, // _T("nl-BE") }, // _T("Dutch (Belgium)") | |
112 { 0x0413, _T("nl") }, // _T("nl-NL") }, // _T("Dutch (Netherlands)") | |
113 { 0x0c09, _T("en") }, // _T("en-AU") }, // _T("English (Australia)") | |
114 { 0x2809, _T("en") }, // _T("en-BZ") }, // _T("English (Belize)") | |
115 { 0x1009, _T("en") }, // _T("en-CA") }, // _T("English (Canada)") | |
116 { 0x2409, _T("en") }, // _T("en-029") }, // _T("English (Caribbean)") | |
117 { 0x4009, _T("en") }, // _T("en-IN") }, // _T("English (India)") | |
118 { 0x1809, _T("en") }, // _T("en-IE") }, // _T("English (Ireland)") | |
119 { 0x2009, _T("en") }, // _T("en-JM") }, // _T("English (Jamaica)") | |
120 { 0x4409, _T("en") }, // _T("en-MY") }, // _T("English (Malaysia)") | |
121 { 0x1409, _T("en") }, // _T("en-NZ") }, // _T("English (New Zealand)") | |
122 { 0x3409, _T("en") }, // _T("en-PH") }, // _T("English (Philippines)") | |
123 { 0x4809, _T("en") }, // _T("en-SG") }, // _T("English (Singapore)") | |
124 { 0x1c09, _T("en") }, // _T("en-ZA") }, // _T("English (South Africa)") | |
125 { 0x2c09, _T("en") }, // _T("en-TT") }, // _T("English | |
126 // (Trinidad and Tobago)") | |
127 { 0x0809, _T("en-GB") }, // _T("English (United Kingdom)") | |
128 { 0x3009, _T("en") }, // _T("en-ZW") }, // _T("English (Zimbabwe)") | |
129 { 0x0425, _T("et") }, // _T("et-EE") }, // _T("Estonian (Estonia)") | |
130 // { 0x0438, _T("fo-FO") }, // _T("Faroese (Faroe Islands)") | |
131 { 0x0464, _T("fil") }, // _T("fil-PH") }, // _T("Filipino (Philippines)") | |
132 { 0x040b, _T("fi") }, // _T("fi-FI") }, // _T("Finnish (Finland)") | |
133 { 0x080c, _T("fr") }, // _T("fr-BE") }, // _T("French (Belgium)") | |
134 { 0x0c0c, _T("fr") }, // _T("fr-CA") }, // _T("French (Canada)") | |
135 { 0x040c, _T("fr") }, // _T("fr-FR") }, // _T("French (France)") | |
136 { 0x140c, _T("fr") }, // _T("fr-LU") }, // _T("French (Luxembourg)") | |
137 { 0x180c, _T("fr") }, // _T("fr-MC") }, // _T("French (Monaco)") | |
138 { 0x100c, _T("fr") }, // _T("fr-CH") }, // _T("French (Switzerland)") | |
139 // { 0x0462, _T("fy-NL") }, // _T("Frisian (Netherlands)") | |
140 // { 0x0456, _T("gl-ES") }, // _T("Galician (Spain)") | |
141 // { 0x0437, _T("ka-GE") }, // _T("Georgian (Georgia)") | |
142 { 0x0c07, _T("de") }, // _T("de-AT") }, // _T("German (Austria)") | |
143 { 0x0407, _T("de") }, // _T("de-DE") }, // _T("German (Germany)") | |
144 { 0x1407, _T("de") }, // _T("de-LI") }, // _T("German (Liechtenstein)") | |
145 { 0x1007, _T("de") }, // _T("de-LU") }, // _T("German (Luxembourg)") | |
146 { 0x0807, _T("de") }, // _T("de-CH") }, // _T("German (Switzerland)") | |
147 { 0x0408, _T("el") }, // _T("el-GR") }, // _T("Greek (Greece)") | |
148 // { 0x046f, _T("kl-GL") }, // _T("Greenlandic (Greenland)") | |
149 { 0x0447, _T("gu") }, // _T("gu-IN") }, // _T("Gujarati (India)") | |
150 // { 0x0468, _T("ha-Latn-NG") }, // _T("Hausa (Nigeria, Latin)") | |
151 // { 0x040d, _T("he-IL") }, // _T("Hebrew (Israel)") | |
152 { 0x0439, _T("hi") }, // _T("hi-IN") }, // _T("Hindi (India)") | |
153 { 0x040e, _T("hu") }, // _T("hu-HU") }, // _T("Hungarian (Hungary)") | |
154 { 0x040f, _T("is") }, // _T("is-IS") }, // _T("Icelandic (Iceland)") | |
155 // { 0x0470, _T("ig-NG") }, // _T("Igbo (Nigeria)") | |
156 { 0x0421, _T("id") }, // _T("id-ID") }, // _T("Indonesian (Indonesia)") | |
157 // { 0x085d, _T("iu-Latn-CA") }, // _T("Inuktitut (Canada, Latin)") | |
158 // { 0x045d, _T("iu-Cans-CA") }, // _T("Inuktitut (Canada, Syllabics)") | |
159 // { 0x083c, _T("ga-IE") }, // _T("Irish (Ireland)") | |
160 { 0x0410, _T("it") }, // _T("it-IT") }, // _T("Italian (Italy)") | |
161 { 0x0810, _T("it") }, // _T("it-CH") }, // _T("Italian (Switzerland)") | |
162 { 0x0411, _T("ja") }, // _T("ja-JP") }, // _T("Japanese (Japan)") | |
163 { 0x044b, _T("kn") }, // _T("kn-IN") }, // _T("Kannada (India)") | |
164 // { 0x043f, _T("kk-KZ") }, // _T("Kazakh (Kazakhstan)") | |
165 // { 0x0453, _T("kh-KH") }, // _T("Khmer (Cambodia)") | |
166 // { 0x0486, _T("qut-GT") }, // _T("K'iche (Guatemala)") | |
167 // { 0x0487, _T("rw-RW") }, // _T("Kinyarwanda (Rwanda)") | |
168 // { 0x0457, _T("kok-IN") }, // _T("Konkani (India)") | |
169 { 0x0812, _T("ko") }, // _T("ko-Jo") }, // _T("Korean (Johab)") | |
170 { 0x0412, _T("ko") }, // _T("ko-KR") }, // _T("Korean (Korea)") | |
171 // { 0x0440, _T("ky-KG") }, // _T("Kyrgyz (Kyrgyzstan)") | |
172 // { 0x0454, _T("lo-LA") }, // _T("Lao (Lao PDR)") | |
173 { 0x0426, _T("lv") }, // _T("lv-LV") }, // _T("Latvian (Latvia)") | |
174 { 0x0427, _T("lt") }, // _T("lt-LT") }, // _T("Lithuanian (Lithuania)") | |
175 // { 0x082e, _T("dsb-DE") }, // _T("Lower Sorbian (Germany)") | |
176 // { 0x046e, _T("lb-LU") }, // _T("Luxembourgish (Luxembourg)") | |
177 // { 0x042f, _T("mk-MK") }, // _T("Macedonian (Macedonia, FYROM)") | |
178 { 0x083e, _T("ms") }, // _T("ms-BN") }, // _T("Malay (Brunei Darussalam)") | |
179 { 0x043e, _T("ms") }, // _T("ms-MY") }, // _T("Malay (Malaysia)") | |
180 { 0x044c, _T("ml") }, // _T("ml-IN") }, // _T("Malayalam (India)") | |
181 // { 0x043a, _T("mt-MT") }, // _T("Maltese (Malta)") | |
182 // { 0x0481, _T("mi-NZ") }, // _T("Maori (New Zealand)") | |
183 // { 0x047a, _T("arn-CL") }, // _T("Mapudungun (Chile)") | |
184 { 0x044e, _T("mr") }, // _T("mr-IN") }, // _T("Marathi (India)") | |
185 // { 0x047c, _T("moh-CA") }, // _T("Mohawk (Canada)") | |
186 // { 0x0450, _T("mn-Cyrl-MN") }, // _T("Mongolian (Mongolia)") | |
187 // { 0x0850, _T("mn-Mong-CN") }, // _T("Mongolian (PRC)") | |
188 // { 0x0461, _T("ne-NP") }, // _T("Nepali (Nepal)") | |
189 // { 0x0414, _T("nb-NO") }, // _T("Norwegian (Bokmal, Norway)") | |
190 // { 0x0814, _T("nn-NO") }, // _T("Norwegian (Nynorsk, Norway)") | |
191 // { 0x0482, _T("oc-FR") }, // _T("Occitan (France)") | |
192 // { 0x0448, _T("or-IN") }, // _T("Oriya (India)") | |
193 // { 0x0463, _T("ps-AF") }, // _T("Pashto (Afghanistan)") | |
194 { 0x0429, _T("fa") }, // _T("fa-IR") }, // _T("Persian (Iran)") | |
195 { 0x0415, _T("pl") }, // _T("pl-PL") }, // _T("Polish (Poland)") | |
196 { 0x0416, _T("pt-BR") }, // _T("Portuguese (Brazil)") | |
197 { 0x0816, _T("pt-PT") }, // _T("Portuguese (Portugal)") | |
198 // { 0x0446, _T("pa-IN") }, // _T("Punjabi (India)") | |
199 // { 0x046b, _T("quz-BO") }, // _T("Quechua (Bolivia)") | |
200 // { 0x086b, _T("quz-EC") }, // _T("Quechua (Ecuador)") | |
201 // { 0x0c6b, _T("quz-PE") }, // _T("Quechua (Peru)") | |
202 { 0x0418, _T("ro") }, // _T("ro-RO") }, // _T("Romanian (Romania)") | |
203 // { 0x0417, _T("rm-CH") }, // _T("Romansh (Switzerland)") | |
204 { 0x0419, _T("ru") }, // _T("ru-RU") }, // _T("Russian (Russia)") | |
205 // { 0x243b, _T("smn-FI") }, // _T("Sami (Inari, Finland)") | |
206 // { 0x103b, _T("smj-NO") }, // _T("Sami (Lule, Norway)") | |
207 // { 0x143b, _T("smj-SE") }, // _T("Sami (Lule, Sweden)") | |
208 // { 0x0c3b, _T("se-FI") }, // _T("Sami (Northern, Finland)") | |
209 // { 0x043b, _T("se-NO") }, // _T("Sami (Northern, Norway)") | |
210 // { 0x083b, _T("se-SE") }, // _T("Sami (Northern, Sweden)") | |
211 // { 0x203b, _T("sms-FI") }, // _T("Sami (Skolt, Finland)") | |
212 // { 0x183b, _T("sma-NO") }, // _T("Sami (Southern, Norway)") | |
213 // { 0x1c3b, _T("sma-SE") }, // _T("Sami (Southern, Sweden)") | |
214 // { 0x044f, _T("sa-IN") }, // _T("Sanskrit (India)") | |
215 { 0x1c1a, _T("sr") }, // _T("sr-Cyrl-BA") }, // _T("Serbian | |
216 // (Bosnia and Herzegovina, Cyrillic)") | |
217 { 0x181a, _T("sr") }, // _T("sr-Latn-BA") }, // _T("Serbian | |
218 // (Bosnia and Herzegovina, Latin)") | |
219 { 0x0c1a, _T("sr") }, // _T("sr-Cyrl-CS") }, // _T("Serbian | |
220 // (Serbia and Montenegro, Cyrillic)") | |
221 { 0x081a, _T("sr") }, // _T("sr-Latn-CS") }, // _T("Serbian | |
222 // (Serbia and Montenegro, Latin)") | |
223 // { 0x046c, _T("ns-ZA") }, // _T("Sesotho sa Leboa/Northern Sotho | |
224 // (South Africa)") | |
225 // { 0x0432, _T("tn-ZA") }, // _T("Setswana/Tswana (South Africa)") | |
226 // { 0x045b, _T("si-LK") }, // _T("Sinhala (Sri Lanka)") | |
227 { 0x041b, _T("sk") }, // _T("sk-SK") }, // _T("Slovak (Slovakia)") | |
228 { 0x0424, _T("sl") }, // _T("sl-SI") }, // _T("Slovenian (Slovenia)") | |
229 { 0x2c0a, _T("es-419") }, // _T("es-AR") }, // _T("Spanish (Argentina)") | |
230 { 0x400a, _T("es-419") }, // _T("es-BO") }, // _T("Spanish (Bolivia)") | |
231 { 0x340a, _T("es-419") }, // _T("es-CL") }, // _T("Spanish (Chile)") | |
232 { 0x240a, _T("es-419") }, // _T("es-CO") }, // _T("Spanish (Colombia)") | |
233 { 0x140a, _T("es-419") }, // _T("es-CR") }, // _T("Spanish (Costa Rica)") | |
234 { 0x1c0a, _T("es-419") }, // _T("es-DO") }, // _T("Spanish | |
235 // (Dominican Republic)") | |
236 { 0x300a, _T("es-419") }, // _T("es-EC") }, // _T("Spanish (Ecuador)") | |
237 { 0x440a, _T("es-419") }, // _T("es-SV") }, // _T("Spanish (El Salvador)") | |
238 { 0x100a, _T("es-419") }, // _T("es-GT") }, // _T("Spanish (Guatemala)") | |
239 { 0x480a, _T("es-419") }, // _T("es-HN") }, // _T("Spanish (Honduras)") | |
240 { 0x080a, _T("es-419") }, // _T("es-MX") }, // _T("Spanish (Mexico)") | |
241 { 0x4c0a, _T("es-419") }, // _T("es-NI") }, // _T("Spanish (Nicaragua)") | |
242 { 0x180a, _T("es-419") }, // _T("es-PA") }, // _T("Spanish (Panama)") | |
243 { 0x3c0a, _T("es-419") }, // _T("es-PY") }, // _T("Spanish (Paraguay)") | |
244 { 0x280a, _T("es-419") }, // _T("es-PE") }, // _T("Spanish (Peru)") | |
245 { 0x500a, _T("es-419") }, // _T("es-PR") }, // _T("Spanish (Puerto Rico)") | |
246 { 0x0c0a, _T("es") }, // _T("es-ES") }, // _T("Spanish (Spain)") | |
247 { 0x040a, _T("es") }, // _T("es-ES_tradnl") }, | |
248 // _T("Spanish (Spain, Traditional Sort)") | |
249 { 0x540a, _T("es-419") }, // _T("es-US") }, // _T("Spanish | |
250 // (United States)") | |
251 { 0x380a, _T("es-419") }, // _T("es-UY") }, // _T("Spanish (Uruguay)") | |
252 { 0x200a, _T("es-419") }, // _T("es-VE") }, // _T("Spanish (Venezuela)") | |
253 { 0x0441, _T("sw") }, // _T("sw-KE") }, // _T("Swahili (Kenya)") | |
254 { 0x081d, _T("sv") }, // _T("sv-FI") }, // _T("Swedish (Finland)") | |
255 { 0x041d, _T("sv") }, // _T("sv-SE") }, // _T("Swedish (Sweden)") | |
256 // { 0x045a, _T("syr-SY") }, // _T("Syriac (Syria)") | |
257 // { 0x0428, _T("tg-Cyrl-TJ") }, // _T("Tajik (Tajikistan)") | |
258 // { 0x085f, _T("tmz-Latn-DZ")}, // _T("Tamazight (Algeria, Latin)") | |
259 { 0x0449, _T("ta") }, // _T("ta-IN") }, // _T("Tamil (India)") | |
260 // { 0x0444, _T("tt-RU") }, // _T("Tatar (Russia)") | |
261 { 0x044a, _T("te") }, // _T("te-IN") }, // _T("Telugu (India)") | |
262 { 0x041e, _T("th") }, // _T("th-TH") }, // _T("Thai (Thailand)") | |
263 // { 0x0851, _T("bo-BT") }, // _T("Tibetan (Bhutan)") | |
264 // { 0x0451, _T("bo-CN") }, // _T("Tibetan (PRC)") | |
265 { 0x041f, _T("tr") }, // _T("tr-TR") }, // _T("Turkish (Turkey)") | |
266 // { 0x0442, _T("tk-TM") }, // _T("Turkmen (Turkmenistan)") | |
267 // { 0x0480, _T("ug-CN") }, // _T("Uighur (PRC)") | |
268 { 0x0422, _T("uk") }, // _T("uk-UA") }, // _T("Ukrainian (Ukraine)") | |
269 // { 0x042e, _T("wen-DE") }, // _T("Upper Sorbian (Germany)") | |
270 // { 0x0820, _T("tr-IN") }, // _T("Urdu(India)") | |
271 { 0x0420, _T("ur") }, // _T("ur-PK") }, // _T("Urdu (Pakistan)") | |
272 // { 0x0843, _T("uz-Cyrl-UZ") }, // _T("Uzbek (Uzbekistan, Cyrillic)") | |
273 // { 0x0443, _T("uz-Latn-UZ") }, // _T("Uzbek (Uzbekistan, Latin)") | |
274 { 0x042a, _T("vi") }, // _T("vi-VN") }, // _T("Vietnamese (Vietnam)") | |
275 // { 0x0452, _T("cy-GB") }, // _T("Welsh (United Kingdom)") | |
276 // { 0x0488, _T("wo-SN") }, // _T("Wolof (Senegal)") | |
277 // { 0x0434, _T("xh-ZA") }, // _T("Xhosa/isiXhosa (South Africa)") | |
278 // { 0x0485, _T("sah-RU") }, // _T("Yakut (Russia)") | |
279 // { 0x0478, _T("ii-CN") }, // _T("Yi (PRC)") | |
280 // { 0x046a, _T("yo-NG") }, // _T("Yoruba (Nigeria)") | |
281 // { 0x0435, _T("zu-ZA") }, // _T("Zulu/isiZulu (South Africa)") | |
282 { 0x0000, _T("") } // The list termination. | |
283 }; | |
284 } | |
285 | |
286 CString GetDefaultLanguage(bool is_system) { | |
287 return GetLanguageForLangID(GetDefaultLanguageID(is_system)); | |
288 } | |
289 | |
290 LANGID GetDefaultLanguageID(bool is_system) { | |
291 LANGID langid = is_system ? ::GetSystemDefaultLangID() | |
292 : ::GetUserDefaultLangID(); | |
293 if (IsLanguageIDSupported(langid)) { | |
294 return langid; | |
295 } | |
296 | |
297 return kFallbackLangID; | |
298 } | |
299 | |
300 // If an exact match is not found, returns "en". | |
301 CString GetLanguageForLangID(LANGID langid) { | |
302 ASSERT1(langid != 0); | |
303 | |
304 for (int i = 0; kLanguageTranslationTable[i].langid; ++i) { | |
305 if (kLanguageTranslationTable[i].langid == langid) { | |
306 return kLanguageTranslationTable[i].lang; | |
307 } | |
308 } | |
309 | |
310 return kFallbackLanguage; | |
311 } | |
312 | |
313 bool IsLanguageIDSupported(LANGID langid) { | |
314 for (int i = 0; kLanguageTranslationTable[i].langid; ++i) { | |
315 if (langid == kLanguageTranslationTable[i].langid) { | |
316 return true; | |
317 } | |
318 } | |
319 | |
320 return false; | |
321 } | |
322 | |
323 bool IsLanguageSupported(const CString& language) { | |
324 for (int i = 0; kLanguageTranslationTable[i].langid; ++i) { | |
325 if (language.CompareNoCase(kLanguageTranslationTable[i].lang) == 0) { | |
326 return true; | |
327 } | |
328 } | |
329 | |
330 return false; | |
331 } | |
332 | |
333 void GetSupportedLanguages(std::vector<CString>* codes) { | |
334 ASSERT1(codes); | |
335 std::set<CString> languages; | |
336 | |
337 for (int i = 0; kLanguageTranslationTable[i].langid; ++i) { | |
338 languages.insert(CString(kLanguageTranslationTable[i].lang)); | |
339 } | |
340 | |
341 for (std::set<CString>::const_iterator it = languages.begin(); | |
342 it != languages.end(); | |
343 ++it) { | |
344 codes->push_back(*it); | |
345 } | |
346 } | |
347 | |
348 // Returns user default language if requested language is not supported. | |
349 CString GetLanguageForProcess(const CString& requested_language) { | |
350 if (!requested_language.IsEmpty() && | |
351 IsLanguageSupported(requested_language)) { | |
352 return requested_language; | |
353 } | |
354 | |
355 return GetDefaultLanguage(false); | |
356 } | |
357 | |
358 CString GetWrittenLanguage(const CString& requested_language) { | |
359 CString written_language(requested_language); | |
360 | |
361 // Handle specific special cases | |
362 // * Chinese (Hong Kong) - separate language but uses the zh-TW as written | |
363 // language. | |
364 // * Hebrew synonyms - convert he to iw. | |
365 if (!requested_language.CompareNoCase(_T("zh-HK"))) { | |
366 written_language = _T("zh-TW"); | |
367 } else if (!requested_language.CompareNoCase(_T("he"))) { | |
368 written_language = _T("iw"); | |
369 } | |
370 | |
371 ASSERT1(IsLanguageSupported(written_language)); | |
372 return written_language; | |
373 } | |
374 | |
375 bool DoesSupportedLanguageUseDifferentId(const CString& requested_language) { | |
376 return (requested_language.CompareNoCase(_T("zh-HK")) == 0); | |
377 } | |
378 | |
379 } // namespace lang | |
380 | |
381 } // namespace omaha | |
OLD | NEW |