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

Unified Diff: ui/base/l10n/l10n_util.cc

Issue 23095006: If user profile doesn't contain language setting, default to his Google account settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/l10n_util.cc
diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc
index 96dfa8e868b31890c83b9842e33e865da5efc2f2..8e8253fbae87117ffc23cc8003514652a199b70b 100644
--- a/ui/base/l10n/l10n_util.cc
+++ b/ui/base/l10n/l10n_util.cc
@@ -246,9 +246,78 @@ bool IsLocaleAvailable(const std::string& locale) {
// See crbug.com/230432: CHECK failure in GetUserDataDir().
return ResourceBundle::GetSharedInstance().LocaleDataPakExists(locale);
}
+#endif
+
+// On Linux, the text layout engine Pango determines paragraph directionality
+// by looking at the first strongly-directional character in the text. This
+// means text such as "Google Chrome foo bar..." will be layed out LTR even
+// if "foo bar" is RTL. So this function prepends the necessary RLM in such
+// cases.
+void AdjustParagraphDirectionality(string16* paragraph) {
+#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
+ if (base::i18n::IsRTL() &&
+ base::i18n::StringContainsStrongRTLChars(*paragraph)) {
+ paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark));
+ }
+#endif
+}
+
+#if defined(OS_WIN)
+std::string GetCanonicalLocale(const std::string& locale) {
+ return base::i18n::GetCanonicalLocale(locale.c_str());
+}
+#endif
+
+struct AvailableLocalesTraits
+ : base::DefaultLazyInstanceTraits<std::vector<std::string> > {
+ static std::vector<std::string>* New(void* instance) {
+ std::vector<std::string>* locales =
+ base::DefaultLazyInstanceTraits<std::vector<std::string> >::New(
+ instance);
+ int num_locales = uloc_countAvailable();
+ for (int i = 0; i < num_locales; ++i) {
+ std::string locale_name = uloc_getAvailable(i);
+ // Filter out the names that have aliases.
+ if (IsDuplicateName(locale_name))
+ continue;
+ // Filter out locales for which we have only partially populated data
+ // and to which Chrome is not localized.
+ if (IsLocalePartiallyPopulated(locale_name))
+ continue;
+ if (!l10n_util::IsLocaleSupportedByOS(locale_name))
+ continue;
+ // Normalize underscores to hyphens because that's what our locale files
+ // use.
+ std::replace(locale_name.begin(), locale_name.end(), '_', '-');
+
+ // Map the Chinese locale names over to zh-CN and zh-TW.
+ if (LowerCaseEqualsASCII(locale_name, "zh-hans")) {
+ locale_name = "zh-CN";
+ } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) {
+ locale_name = "zh-TW";
+ }
+ locales->push_back(locale_name);
+ }
+
+ // Manually add 'es-419' to the list. See the comment in IsDuplicateName().
+ locales->push_back("es-419");
+ return locales;
+ }
+};
+
+base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
+ g_available_locales = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+namespace l10n_util {
bool CheckAndResolveLocale(const std::string& locale,
std::string* resolved_locale) {
+#if defined(OS_MACOSX)
+ NOTIMPLEMENTED();
+ return false;
+#else
if (IsLocaleAvailable(locale)) {
*resolved_locale = locale;
return true;
@@ -326,73 +395,9 @@ bool CheckAndResolveLocale(const std::string& locale,
}
return false;
-}
-#endif
-
-// On Linux, the text layout engine Pango determines paragraph directionality
-// by looking at the first strongly-directional character in the text. This
-// means text such as "Google Chrome foo bar..." will be layed out LTR even
-// if "foo bar" is RTL. So this function prepends the necessary RLM in such
-// cases.
-void AdjustParagraphDirectionality(string16* paragraph) {
-#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
- if (base::i18n::IsRTL() &&
- base::i18n::StringContainsStrongRTLChars(*paragraph)) {
- paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark));
- }
#endif
}
-#if defined(OS_WIN)
-std::string GetCanonicalLocale(const std::string& locale) {
- return base::i18n::GetCanonicalLocale(locale.c_str());
-}
-#endif
-
-struct AvailableLocalesTraits :
- base::DefaultLazyInstanceTraits<std::vector<std::string> > {
- static std::vector<std::string>* New(void* instance) {
- std::vector<std::string>* locales =
- base::DefaultLazyInstanceTraits<std::vector<std::string> >::New(
- instance);
- int num_locales = uloc_countAvailable();
- for (int i = 0; i < num_locales; ++i) {
- std::string locale_name = uloc_getAvailable(i);
- // Filter out the names that have aliases.
- if (IsDuplicateName(locale_name))
- continue;
- // Filter out locales for which we have only partially populated data
- // and to which Chrome is not localized.
- if (IsLocalePartiallyPopulated(locale_name))
- continue;
- if (!l10n_util::IsLocaleSupportedByOS(locale_name))
- continue;
- // Normalize underscores to hyphens because that's what our locale files
- // use.
- std::replace(locale_name.begin(), locale_name.end(), '_', '-');
-
- // Map the Chinese locale names over to zh-CN and zh-TW.
- if (LowerCaseEqualsASCII(locale_name, "zh-hans")) {
- locale_name = "zh-CN";
- } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) {
- locale_name = "zh-TW";
- }
- locales->push_back(locale_name);
- }
-
- // Manually add 'es-419' to the list. See the comment in IsDuplicateName().
- locales->push_back("es-419");
- return locales;
- }
-};
-
-base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits >
- g_available_locales = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-namespace l10n_util {
-
std::string GetApplicationLocale(const std::string& pref_locale) {
#if defined(OS_MACOSX)
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698