Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1429)

Side by Side Diff: trunk/src/ui/base/l10n/l10n_util.cc

Issue 474483002: Revert 289312 "Move StringToUpperASCII and LowerCaseEqualsASCII ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/pdf/document_loader.cc ('k') | trunk/src/ui/base/l10n/l10n_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/l10n/l10n_util.h" 5 #include "ui/base/l10n/l10n_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <iterator> 9 #include <iterator>
10 #include <string> 10 #include <string>
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 "zh_hans_cn", 193 "zh_hans_cn",
194 "zh_hant_hk", 194 "zh_hant_hk",
195 "zh_hant_mo", 195 "zh_hant_mo",
196 "zh_hans_sg", 196 "zh_hans_sg",
197 "zh_hant_tw" 197 "zh_hant_tw"
198 }; 198 };
199 199
200 // Skip all 'es_RR'. Currently, we use 'es' for es-ES (Spanish in Spain). 200 // Skip all 'es_RR'. Currently, we use 'es' for es-ES (Spanish in Spain).
201 // 'es-419' (Spanish in Latin America) is not available in ICU so that it 201 // 'es-419' (Spanish in Latin America) is not available in ICU so that it
202 // has to be added manually in GetAvailableLocales(). 202 // has to be added manually in GetAvailableLocales().
203 if (base::LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) 203 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_"))
204 return true; 204 return true;
205 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { 205 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) {
206 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) 206 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0)
207 return true; 207 return true;
208 } 208 }
209 return false; 209 return false;
210 } 210 }
211 211
212 // We added 30+ minimally populated locales with only a few entries 212 // We added 30+ minimally populated locales with only a few entries
213 // (exemplar character set, script, writing direction and its own 213 // (exemplar character set, script, writing direction and its own
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // and to which Chrome is not localized. 279 // and to which Chrome is not localized.
280 if (IsLocalePartiallyPopulated(locale_name)) 280 if (IsLocalePartiallyPopulated(locale_name))
281 continue; 281 continue;
282 if (!l10n_util::IsLocaleSupportedByOS(locale_name)) 282 if (!l10n_util::IsLocaleSupportedByOS(locale_name))
283 continue; 283 continue;
284 // Normalize underscores to hyphens because that's what our locale files 284 // Normalize underscores to hyphens because that's what our locale files
285 // use. 285 // use.
286 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); 286 std::replace(locale_name.begin(), locale_name.end(), '_', '-');
287 287
288 // Map the Chinese locale names over to zh-CN and zh-TW. 288 // Map the Chinese locale names over to zh-CN and zh-TW.
289 if (base::LowerCaseEqualsASCII(locale_name, "zh-hans")) { 289 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) {
290 locale_name = "zh-CN"; 290 locale_name = "zh-CN";
291 } else if (base::LowerCaseEqualsASCII(locale_name, "zh-hant")) { 291 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) {
292 locale_name = "zh-TW"; 292 locale_name = "zh-TW";
293 } 293 }
294 locales->push_back(locale_name); 294 locales->push_back(locale_name);
295 } 295 }
296 296
297 // Manually add 'es-419' to the list. See the comment in IsDuplicateName(). 297 // Manually add 'es-419' to the list. See the comment in IsDuplicateName().
298 locales->push_back("es-419"); 298 locales->push_back("es-419");
299 return locales; 299 return locales;
300 } 300 }
301 }; 301 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // does not support but available on Windows. We fall 334 // does not support but available on Windows. We fall
335 // back to en-US in GetApplicationLocale so that it's a not critical, 335 // back to en-US in GetApplicationLocale so that it's a not critical,
336 // but we can do better. 336 // but we can do better.
337 std::string::size_type hyphen_pos = locale.find('-'); 337 std::string::size_type hyphen_pos = locale.find('-');
338 std::string lang(locale, 0, hyphen_pos); 338 std::string lang(locale, 0, hyphen_pos);
339 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { 339 if (hyphen_pos != std::string::npos && hyphen_pos > 0) {
340 std::string region(locale, hyphen_pos + 1); 340 std::string region(locale, hyphen_pos + 1);
341 std::string tmp_locale(lang); 341 std::string tmp_locale(lang);
342 // Map es-RR other than es-ES to es-419 (Chrome's Latin American 342 // Map es-RR other than es-ES to es-419 (Chrome's Latin American
343 // Spanish locale). 343 // Spanish locale).
344 if (base::LowerCaseEqualsASCII(lang, "es") && 344 if (LowerCaseEqualsASCII(lang, "es") &&
345 !base::LowerCaseEqualsASCII(region, "es")) { 345 !LowerCaseEqualsASCII(region, "es")) {
346 tmp_locale.append("-419"); 346 tmp_locale.append("-419");
347 } else if (base::LowerCaseEqualsASCII(lang, "zh")) { 347 } else if (LowerCaseEqualsASCII(lang, "zh")) {
348 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. 348 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN.
349 if (base::LowerCaseEqualsASCII(region, "hk") || 349 if (LowerCaseEqualsASCII(region, "hk") ||
350 base::LowerCaseEqualsASCII(region, "mo")) { // Macao 350 LowerCaseEqualsASCII(region, "mo")) { // Macao
351 tmp_locale.append("-TW"); 351 tmp_locale.append("-TW");
352 } else { 352 } else {
353 tmp_locale.append("-CN"); 353 tmp_locale.append("-CN");
354 } 354 }
355 } else if (base::LowerCaseEqualsASCII(lang, "en")) { 355 } else if (LowerCaseEqualsASCII(lang, "en")) {
356 // Map Australian, Canadian, New Zealand and South African English 356 // Map Australian, Canadian, New Zealand and South African English
357 // to British English for now. 357 // to British English for now.
358 // TODO(jungshik): en-CA may have to change sides once 358 // TODO(jungshik): en-CA may have to change sides once
359 // we have OS locale separate from app locale (Chrome's UI language). 359 // we have OS locale separate from app locale (Chrome's UI language).
360 if (base::LowerCaseEqualsASCII(region, "au") || 360 if (LowerCaseEqualsASCII(region, "au") ||
361 base::LowerCaseEqualsASCII(region, "ca") || 361 LowerCaseEqualsASCII(region, "ca") ||
362 base::LowerCaseEqualsASCII(region, "nz") || 362 LowerCaseEqualsASCII(region, "nz") ||
363 base::LowerCaseEqualsASCII(region, "za")) { 363 LowerCaseEqualsASCII(region, "za")) {
364 tmp_locale.append("-GB"); 364 tmp_locale.append("-GB");
365 } else { 365 } else {
366 tmp_locale.append("-US"); 366 tmp_locale.append("-US");
367 } 367 }
368 } 368 }
369 if (IsLocaleAvailable(tmp_locale)) { 369 if (IsLocaleAvailable(tmp_locale)) {
370 resolved_locale->swap(tmp_locale); 370 resolved_locale->swap(tmp_locale);
371 return true; 371 return true;
372 } 372 }
373 } 373 }
374 374
375 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US. 375 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US.
376 struct { 376 struct {
377 const char* source; 377 const char* source;
378 const char* dest; 378 const char* dest;
379 } alias_map[] = { 379 } alias_map[] = {
380 {"no", "nb"}, 380 {"no", "nb"},
381 {"tl", "fil"}, 381 {"tl", "fil"},
382 {"iw", "he"}, 382 {"iw", "he"},
383 {"en", "en-US"}, 383 {"en", "en-US"},
384 }; 384 };
385 385
386 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) { 386 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) {
387 if (base::LowerCaseEqualsASCII(lang, alias_map[i].source)) { 387 if (LowerCaseEqualsASCII(lang, alias_map[i].source)) {
388 std::string tmp_locale(alias_map[i].dest); 388 std::string tmp_locale(alias_map[i].dest);
389 if (IsLocaleAvailable(tmp_locale)) { 389 if (IsLocaleAvailable(tmp_locale)) {
390 resolved_locale->swap(tmp_locale); 390 resolved_locale->swap(tmp_locale);
391 return true; 391 return true;
392 } 392 }
393 } 393 }
394 } 394 }
395 395
396 return false; 396 return false;
397 #endif 397 #endif
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } 871 }
872 872
873 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { 873 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) {
874 int width = 0; 874 int width = 0;
875 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); 875 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width);
876 DCHECK_GT(width, 0); 876 DCHECK_GT(width, 0);
877 return width; 877 return width;
878 } 878 }
879 879
880 } // namespace l10n_util 880 } // namespace l10n_util
OLDNEW
« no previous file with comments | « trunk/src/pdf/document_loader.cc ('k') | trunk/src/ui/base/l10n/l10n_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698