Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <memory> | 10 #include <memory> |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 "zh_hant_hk", | 208 "zh_hant_hk", |
| 209 "zh_hant_mo", | 209 "zh_hant_mo", |
| 210 "zh_hans_sg", | 210 "zh_hans_sg", |
| 211 "zh_hant_tw" | 211 "zh_hant_tw" |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 // Skip all the es_Foo other than es_419 for now. | 214 // Skip all the es_Foo other than es_419 for now. |
| 215 if (base::StartsWith(locale_name, "es_", | 215 if (base::StartsWith(locale_name, "es_", |
| 216 base::CompareCase::INSENSITIVE_ASCII)) | 216 base::CompareCase::INSENSITIVE_ASCII)) |
| 217 return !base::EndsWith(locale_name, "419", base::CompareCase::SENSITIVE); | 217 return !base::EndsWith(locale_name, "419", base::CompareCase::SENSITIVE); |
| 218 | 218 for (const char* kduplicatename : kDuplicateNames) { |
|
jungshik at Google
2016/11/10 00:16:10
nit: perhaps, |duplicate_name| would be better.
| |
| 219 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { | 219 if (base::EqualsCaseInsensitiveASCII(kduplicatename, locale_name)) |
| 220 if (base::EqualsCaseInsensitiveASCII(kDuplicateNames[i], locale_name)) | |
| 221 return true; | 220 return true; |
| 222 } | 221 } |
| 223 return false; | 222 return false; |
| 224 } | 223 } |
| 225 | 224 |
| 226 // We added 30+ minimally populated locales with only a few entries | 225 // We added 30+ minimally populated locales with only a few entries |
| 227 // (exemplar character set, script, writing direction and its own | 226 // (exemplar character set, script, writing direction and its own |
| 228 // lanaguage name). These locales have to be distinguished from the | 227 // lanaguage name). These locales have to be distinguished from the |
| 229 // fully populated locales to which Chrome is localized. | 228 // fully populated locales to which Chrome is localized. |
| 230 bool IsLocalePartiallyPopulated(const std::string& locale_name) { | 229 bool IsLocalePartiallyPopulated(const std::string& locale_name) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US. | 389 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US. |
| 391 struct { | 390 struct { |
| 392 const char* source; | 391 const char* source; |
| 393 const char* dest; | 392 const char* dest; |
| 394 } alias_map[] = { | 393 } alias_map[] = { |
| 395 {"no", "nb"}, | 394 {"no", "nb"}, |
| 396 {"tl", "fil"}, | 395 {"tl", "fil"}, |
| 397 {"iw", "he"}, | 396 {"iw", "he"}, |
| 398 {"en", "en-US"}, | 397 {"en", "en-US"}, |
| 399 }; | 398 }; |
| 400 | 399 for (const auto& amap : alias_map) { |
|
jungshik at Google
2016/11/10 00:16:10
nit: alias instead of amap ?
| |
| 401 for (size_t i = 0; i < arraysize(alias_map); ++i) { | 400 if (base::LowerCaseEqualsASCII(lang, amap.source)) { |
| 402 if (base::LowerCaseEqualsASCII(lang, alias_map[i].source)) { | 401 std::string tmp_locale(amap.dest); |
| 403 std::string tmp_locale(alias_map[i].dest); | |
| 404 if (IsLocaleAvailable(tmp_locale)) { | 402 if (IsLocaleAvailable(tmp_locale)) { |
| 405 resolved_locale->swap(tmp_locale); | 403 resolved_locale->swap(tmp_locale); |
| 406 return true; | 404 return true; |
| 407 } | 405 } |
| 408 } | 406 } |
| 409 } | 407 } |
| 410 | 408 |
| 411 return false; | 409 return false; |
| 412 #endif | 410 #endif |
| 413 } | 411 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 std::vector<base::string16>* strings) { | 853 std::vector<base::string16>* strings) { |
| 856 SortVectorWithStringKey(locale, strings, false); | 854 SortVectorWithStringKey(locale, strings, false); |
| 857 } | 855 } |
| 858 | 856 |
| 859 const std::vector<std::string>& GetAvailableLocales() { | 857 const std::vector<std::string>& GetAvailableLocales() { |
| 860 return g_available_locales.Get(); | 858 return g_available_locales.Get(); |
| 861 } | 859 } |
| 862 | 860 |
| 863 void GetAcceptLanguagesForLocale(const std::string& display_locale, | 861 void GetAcceptLanguagesForLocale(const std::string& display_locale, |
| 864 std::vector<std::string>* locale_codes) { | 862 std::vector<std::string>* locale_codes) { |
| 865 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 863 for (const char* kaccept_language : kAcceptLanguageList) { |
|
jungshik at Google
2016/11/10 00:16:10
nit: |accept_language| instead of |kaccept_languag
| |
| 866 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], | 864 if (!l10n_util::IsLocaleNameTranslated(kaccept_language, display_locale)) { |
| 867 display_locale)) { | |
| 868 // TODO(jungshik) : Put them at the end of the list with language codes | 865 // TODO(jungshik) : Put them at the end of the list with language codes |
| 869 // enclosed by brackets instead of skipping. | 866 // enclosed by brackets instead of skipping. |
| 870 continue; | 867 continue; |
| 871 } | 868 } |
| 872 locale_codes->push_back(kAcceptLanguageList[i]); | 869 locale_codes->push_back(kaccept_language); |
| 873 } | 870 } |
| 874 } | 871 } |
| 875 | 872 |
| 876 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { | 873 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { |
| 877 int width = 0; | 874 int width = 0; |
| 878 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); | 875 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); |
| 879 DCHECK_GT(width, 0); | 876 DCHECK_GT(width, 0); |
| 880 return width; | 877 return width; |
| 881 } | 878 } |
| 882 | 879 |
| 883 const char* const* GetAcceptLanguageListForTesting() { | 880 const char* const* GetAcceptLanguageListForTesting() { |
| 884 return kAcceptLanguageList; | 881 return kAcceptLanguageList; |
| 885 } | 882 } |
| 886 | 883 |
| 887 size_t GetAcceptLanguageListSizeForTesting() { | 884 size_t GetAcceptLanguageListSizeForTesting() { |
| 888 return arraysize(kAcceptLanguageList); | 885 return arraysize(kAcceptLanguageList); |
| 889 } | 886 } |
| 890 | 887 |
| 891 } // namespace l10n_util | 888 } // namespace l10n_util |
| OLD | NEW |