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

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

Issue 1172753003: Move LowerCaseEqualsASCII to base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util
Patch Set: Created 5 years, 6 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
« no previous file with comments | « ui/accessibility/ax_node_data.cc ('k') | 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // and to which Chrome is not localized. 281 // and to which Chrome is not localized.
282 if (IsLocalePartiallyPopulated(locale_name)) 282 if (IsLocalePartiallyPopulated(locale_name))
283 continue; 283 continue;
284 if (!l10n_util::IsLocaleSupportedByOS(locale_name)) 284 if (!l10n_util::IsLocaleSupportedByOS(locale_name))
285 continue; 285 continue;
286 // Normalize underscores to hyphens because that's what our locale files 286 // Normalize underscores to hyphens because that's what our locale files
287 // use. 287 // use.
288 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); 288 std::replace(locale_name.begin(), locale_name.end(), '_', '-');
289 289
290 // Map the Chinese locale names over to zh-CN and zh-TW. 290 // Map the Chinese locale names over to zh-CN and zh-TW.
291 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { 291 if (base::LowerCaseEqualsASCII(locale_name, "zh-hans")) {
292 locale_name = "zh-CN"; 292 locale_name = "zh-CN";
293 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { 293 } else if (base::LowerCaseEqualsASCII(locale_name, "zh-hant")) {
294 locale_name = "zh-TW"; 294 locale_name = "zh-TW";
295 } 295 }
296 locales->push_back(locale_name); 296 locales->push_back(locale_name);
297 } 297 }
298 298
299 return locales; 299 return locales;
300 } 300 }
301 }; 301 };
302 302
303 base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits> 303 base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
(...skipping 30 matching lines...) Expand all
334 // TODO(jungshik) : Nothing is done about languages that Chrome 334 // TODO(jungshik) : Nothing is done about languages that Chrome
335 // does not support but available on Windows. We fall 335 // does not support but available on Windows. We fall
336 // back to en-US in GetApplicationLocale so that it's a not critical, 336 // back to en-US in GetApplicationLocale so that it's a not critical,
337 // but we can do better. 337 // but we can do better.
338 const std::string lang(GetLanguage(locale)); 338 const std::string lang(GetLanguage(locale));
339 if (lang.size() < locale.size()) { 339 if (lang.size() < locale.size()) {
340 std::string region(locale, lang.size() + 1); 340 std::string region(locale, lang.size() + 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 (LowerCaseEqualsASCII(lang, "es") && 344 if (base::LowerCaseEqualsASCII(lang, "es") &&
345 !LowerCaseEqualsASCII(region, "es")) { 345 !base::LowerCaseEqualsASCII(region, "es")) {
346 tmp_locale.append("-419"); 346 tmp_locale.append("-419");
347 } else if (LowerCaseEqualsASCII(lang, "zh")) { 347 } else if (base::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 (LowerCaseEqualsASCII(region, "hk") || 349 if (base::LowerCaseEqualsASCII(region, "hk") ||
350 LowerCaseEqualsASCII(region, "mo")) { // Macao 350 base::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 (LowerCaseEqualsASCII(lang, "en")) { 355 } else if (base::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 (LowerCaseEqualsASCII(region, "au") || 360 if (base::LowerCaseEqualsASCII(region, "au") ||
361 LowerCaseEqualsASCII(region, "ca") || 361 base::LowerCaseEqualsASCII(region, "ca") ||
362 LowerCaseEqualsASCII(region, "nz") || 362 base::LowerCaseEqualsASCII(region, "nz") ||
363 LowerCaseEqualsASCII(region, "za")) { 363 base::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(alias_map); ++i) { 386 for (size_t i = 0; i < arraysize(alias_map); ++i) {
387 if (LowerCaseEqualsASCII(lang, alias_map[i].source)) { 387 if (base::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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 873
874 const char* const* GetAcceptLanguageListForTesting() { 874 const char* const* GetAcceptLanguageListForTesting() {
875 return kAcceptLanguageList; 875 return kAcceptLanguageList;
876 } 876 }
877 877
878 size_t GetAcceptLanguageListSizeForTesting() { 878 size_t GetAcceptLanguageListSizeForTesting() {
879 return arraysize(kAcceptLanguageList); 879 return arraysize(kAcceptLanguageList);
880 } 880 }
881 881
882 } // namespace l10n_util 882 } // namespace l10n_util
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node_data.cc ('k') | ui/base/l10n/l10n_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698