summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorgrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 15:28:45 +0000
committergrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 15:28:45 +0000
commit337ca0791390f606472d7530abf7603ad2f24ca8 (patch)
tree660625c6c058dab2acee91549ba258258bdc70f5 /app
parent40519596601f58e38c22b3ff9f2d8a47301e7c25 (diff)
downloadchromium_src-337ca0791390f606472d7530abf7603ad2f24ca8.zip
chromium_src-337ca0791390f606472d7530abf7603ad2f24ca8.tar.gz
chromium_src-337ca0791390f606472d7530abf7603ad2f24ca8.tar.bz2
The UI language rather than the locale is now used to pick Chrome's language on Windows. (Also fixed some unrelated lint errors.) With this change, l10n_util::GetApplicationLocale first checks for an override of the "configured locale" (in base::i18n) containing the list of preferred Windows UI languages. The browser triggers an override early in startup before the ApplicationLocale is determined. In effect, the browser no longer uses ICU on Windows for language detection. (This locale override mechanism is borrowed from the OS X port.)
Changes in Chrome Frame are largely a refactor, as some Win32 code in there has been moved into base/win. Also cleaned up language selection in installer_util so that the proper language is chosen for the EULA, installer messages, and shortcuts. In so doing, replaced hand-crafted lists of supported languages with either auto-generated lists (static consts) or logic so that the addition of translations in the future doesn't require code motion (that being said, there may be reason to update the alias and/or wildcard tables in language_selector.cc). In so doing, this change unlocks Amharic, Farsi, and Swahili translations for installer messages and shortcuts. BUG=39986,40496,26470 TEST=New MUI/Win32 calls are tested in base/win/i18n_unittest.cc. To test the overall functionality, uninstall Chrome, remove intl.app_locale user pref, switch to a supported display language (via the "Keyboards and Languages" tab of Win7's "Regional and Language" control panel, and install with { "distribution": { "require_eula": true } } in master_preferences (via -installerdata arg to setup.exe). If all goes well, both EULA and outer frame are in the same language as Windows. Also, from gwilson: "Install system-level Chrome in audit mode on a new machine, then go through the out-of-box-experience, select a language, and the in -product EULA (triggered by "require_eula" : true) and Chrome's UI should be in the language that the user selected." Review URL: http://codereview.chromium.org/4139010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/l10n_util.cc20
-rw-r--r--app/l10n_util_win.cc41
-rw-r--r--app/l10n_util_win.h11
3 files changed, 67 insertions, 5 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 375f3b6..d86f082 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -8,7 +8,9 @@
#include <glib/gutils.h>
#endif
+#include <algorithm>
#include <cstdlib>
+#include <iterator>
#include "app/app_paths.h"
#include "app/l10n_util_collator.h"
@@ -30,6 +32,8 @@
#if defined(OS_MACOSX)
#include "app/l10n_util_mac.h"
+#elif defined(OS_WIN)
+#include "app/l10n_util_win.h"
#endif
namespace {
@@ -325,6 +329,10 @@ void AdjustParagraphDirectionality(string16* paragraph) {
#endif
}
+std::string GetCanonicalLocale(const std::string& locale) {
+ return base::i18n::GetCanonicalLocale(locale.c_str());
+}
+
} // namespace
namespace l10n_util {
@@ -369,8 +377,16 @@ std::string GetApplicationLocale(const std::string& pref_locale) {
if (!pref_locale.empty())
candidates.push_back(pref_locale);
- // Next, try the system locale.
- candidates.push_back(base::i18n::GetConfiguredLocale());
+ // Next, try the overridden locale.
+ const std::vector<std::string>& languages = l10n_util::GetLocaleOverrides();
+ if (!languages.empty()) {
+ candidates.reserve(candidates.size() + languages.size());
+ std::transform(languages.begin(), languages.end(),
+ std::back_inserter(candidates), &GetCanonicalLocale);
+ } else {
+ // If no override was set, defer to ICU
+ candidates.push_back(base::i18n::GetConfiguredLocale());
+ }
#elif defined(OS_CHROMEOS)
diff --git a/app/l10n_util_win.cc b/app/l10n_util_win.cc
index 2f1f627..eacdb35 100644
--- a/app/l10n_util_win.cc
+++ b/app/l10n_util_win.cc
@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "app/l10n_util.h"
+#include "app/l10n_util_win.h"
-#include <algorithm>
#include <windowsx.h>
+#include <algorithm>
+#include <iterator>
-#include "app/l10n_util_win.h"
+#include "app/l10n_util.h"
#include "base/i18n/rtl.h"
+#include "base/lazy_instance.h"
#include "base/string_number_conversions.h"
+#include "base/win/i18n.h"
#include "base/win/windows_version.h"
#include "grit/app_locale_settings.h"
@@ -52,6 +55,21 @@ bool IsFontPresent(const wchar_t* font_name) {
return wcscmp(font_name, actual_font_name) == 0;
}
+class OverrideLocaleHolder {
+ public:
+ OverrideLocaleHolder() {}
+ const std::vector<std::string>& value() const { return value_; }
+ void swap_value(std::vector<std::string>* override_value) {
+ value_.swap(*override_value);
+ }
+ private:
+ std::vector<std::string> value_;
+ DISALLOW_COPY_AND_ASSIGN(OverrideLocaleHolder);
+};
+
+base::LazyInstance<OverrideLocaleHolder>
+ override_locale_holder(base::LINKER_INITIALIZED);
+
} // namespace
namespace l10n_util {
@@ -147,4 +165,21 @@ void AdjustUIFontForWindow(HWND hwnd) {
}
}
+void OverrideLocaleWithUILanguageList() {
+ std::vector<std::wstring> ui_languages;
+ if (base::win::i18n::GetThreadPreferredUILanguageList(&ui_languages)) {
+ std::vector<std::string> ascii_languages;
+ ascii_languages.reserve(ui_languages.size());
+ std::transform(ui_languages.begin(), ui_languages.end(),
+ std::back_inserter(ascii_languages), &WideToASCII);
+ override_locale_holder.Get().swap_value(&ascii_languages);
+ } else {
+ NOTREACHED() << "Failed to determine the UI language for locale override.";
+ }
+}
+
+const std::vector<std::string>& GetLocaleOverrides() {
+ return override_locale_holder.Get().value();
+}
+
} // namespace l10n_util
diff --git a/app/l10n_util_win.h b/app/l10n_util_win.h
index 99a9df3..7a1dda5 100644
--- a/app/l10n_util_win.h
+++ b/app/l10n_util_win.h
@@ -7,6 +7,8 @@
#pragma once
#include <windows.h>
+#include <string>
+#include <vector>
namespace l10n_util {
@@ -47,6 +49,15 @@ void AdjustUIFont(LOGFONT* logfont);
// stored in the per-locale resource.
void AdjustUIFontForWindow(HWND hwnd);
+// Allow processes to override the configured locale with the user's Windows UI
+// languages. This function should generally be called once early in
+// Application startup.
+void OverrideLocaleWithUILanguageList();
+
+// Retrieve the locale override, or an empty vector if the locale has not been
+// or failed to be overridden.
+const std::vector<std::string>& GetLocaleOverrides();
+
} // namespace l10n_util
#endif // APP_L10N_UTIL_WIN_H_