summaryrefslogtreecommitdiffstats
path: root/app/l10n_util_unittest.cc
diff options
context:
space:
mode:
authorsuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 14:26:59 +0000
committersuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 14:26:59 +0000
commitc7c9b8ff8028602c0f39f4e12af4976f06cc1f30 (patch)
tree2d0e1f89c47c7ca4594c0373bb1822d98e076b01 /app/l10n_util_unittest.cc
parent2474031c9712cceaa0925aef2226e2acf82b579a (diff)
downloadchromium_src-c7c9b8ff8028602c0f39f4e12af4976f06cc1f30.zip
chromium_src-c7c9b8ff8028602c0f39f4e12af4976f06cc1f30.tar.gz
chromium_src-c7c9b8ff8028602c0f39f4e12af4976f06cc1f30.tar.bz2
[Linux] Supports the LANGUAGE environment variable.
This CL adds the support for the LANGUAGE environment variable, which is supported by gettext based applications for specifying a priority list of user prefered locales for UI messages translation. Unlike gettext based applications, which support using different locales for messages translation and other locale categories, like LC_CTYPE, LC_COLLATE, LC_TIME, etc., chromium supports only one application locale for all localization operations. This CL adds the support of specifying the application locale by LANGUAGE env variable, but doesn't make chromium to support above mentioned behavior of gettext based applications. BUG=21080: chromium doesn't honor locale fallbacks TEST=Launch chrome with LANGUAGE=br:fr_FR:fr, French locale shall be used by chrome, as br is not supported by chrome yet. Review URL: http://codereview.chromium.org/236001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/l10n_util_unittest.cc')
-rw-r--r--app/l10n_util_unittest.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/app/l10n_util_unittest.cc b/app/l10n_util_unittest.cc
index c9409fe..0298988 100644
--- a/app/l10n_util_unittest.cc
+++ b/app/l10n_util_unittest.cc
@@ -4,6 +4,10 @@
#include "build/build_config.h"
+#if defined(OS_LINUX)
+#include <cstdlib>
+#endif
+
#include "app/app_paths.h"
#include "app/l10n_util.h"
#if !defined(OS_MACOSX)
@@ -136,6 +140,33 @@ TEST_F(L10nUtilTest, GetAppLocale) {
// Keep a copy of ICU's default locale before we overwrite it.
icu::Locale locale = icu::Locale::getDefault();
+#if defined(OS_LINUX)
+ // Test the support of LANGUAGE environment variable.
+ SetICUDefaultLocale("en-US");
+ ::setenv("LANGUAGE", "xx:fr_CA", 1);
+ EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L""));
+
+ ::setenv("LANGUAGE", "xx:yy:en_gb.utf-8@quot", 1);
+ EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L""));
+
+ ::setenv("LANGUAGE", "xx:zh-hk", 1);
+ EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(L""));
+
+ // We emulate gettext's behavior here, which ignores LANG/LC_MESSAGES/LC_ALL
+ // when LANGUAGE is specified. If no language specified in LANGUAGE is valid,
+ // then just fallback to the default language, which is en-US for us.
+ SetICUDefaultLocale("fr-FR");
+ ::setenv("LANGUAGE", "xx:yy", 1);
+ EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L""));
+
+ ::setenv("LANGUAGE", "/fr:zh_CN", 1);
+ EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(L""));
+
+ // Make sure the follow tests won't be affected by LANGUAGE environment
+ // variable.
+ ::unsetenv("LANGUAGE");
+#endif
+
SetICUDefaultLocale("en-US");
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L""));
@@ -479,4 +510,3 @@ TEST_F(L10nUtilTest, UpperLower) {
result = l10n_util::ToUpper(mixed);
EXPECT_EQ(result, expected_upper);
}
-