summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/base/l10n/l10n_util.cc24
-rw-r--r--ui/base/resource/resource_bundle.cc5
-rw-r--r--ui/base/resource/resource_bundle.h3
-rw-r--r--ui/base/resource/resource_bundle_unittest.cc6
4 files changed, 21 insertions, 17 deletions
diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc
index ee4bb7c..26faf95 100644
--- a/ui/base/l10n/l10n_util.cc
+++ b/ui/base/l10n/l10n_util.cc
@@ -36,9 +36,6 @@
namespace {
-static const FilePath::CharType kLocaleFileExtension[] =
- FILE_PATH_LITERAL(".pak");
-
static const char* const kAcceptLanguageList[] = {
"af", // Afrikaans
"am", // Amharic
@@ -228,8 +225,7 @@ bool IsLocalePartiallyPopulated(const std::string& locale_name) {
}
#if !defined(OS_MACOSX)
-bool IsLocaleAvailable(const std::string& locale,
- const FilePath& locale_path) {
+bool IsLocaleAvailable(const std::string& locale) {
// If locale has any illegal characters in it, we don't want to try to
// load it because it may be pointing outside the locale data file directory.
if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale)))
@@ -243,16 +239,12 @@ bool IsLocaleAvailable(const std::string& locale,
if (!l10n_util::IsLocaleSupportedByOS(locale))
return false;
- FilePath test_path = locale_path;
- test_path =
- test_path.AppendASCII(locale).ReplaceExtension(kLocaleFileExtension);
- return file_util::PathExists(test_path);
+ return ResourceBundle::LocaleDataPakExists(locale);
}
bool CheckAndResolveLocale(const std::string& locale,
- const FilePath& locale_path,
std::string* resolved_locale) {
- if (IsLocaleAvailable(locale, locale_path)) {
+ if (IsLocaleAvailable(locale)) {
*resolved_locale = locale;
return true;
}
@@ -287,7 +279,7 @@ bool CheckAndResolveLocale(const std::string& locale,
tmp_locale.append("-CN");
}
}
- if (IsLocaleAvailable(tmp_locale, locale_path)) {
+ if (IsLocaleAvailable(tmp_locale)) {
resolved_locale->swap(tmp_locale);
return true;
}
@@ -308,7 +300,7 @@ bool CheckAndResolveLocale(const std::string& locale,
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) {
if (LowerCaseEqualsASCII(locale, alias_map[i].source)) {
std::string tmp_locale(alias_map[i].dest);
- if (IsLocaleAvailable(tmp_locale, locale_path)) {
+ if (IsLocaleAvailable(tmp_locale)) {
resolved_locale->swap(tmp_locale);
return true;
}
@@ -367,8 +359,6 @@ std::string GetApplicationLocale(const std::string& pref_locale) {
#else
- FilePath locale_path;
- PathService::Get(ui::DIR_LOCALES, &locale_path);
std::string resolved_locale;
std::vector<std::string> candidates;
@@ -421,7 +411,7 @@ std::string GetApplicationLocale(const std::string& pref_locale) {
std::vector<std::string>::const_iterator i = candidates.begin();
for (; i != candidates.end(); ++i) {
- if (CheckAndResolveLocale(*i, locale_path, &resolved_locale)) {
+ if (CheckAndResolveLocale(*i, &resolved_locale)) {
base::i18n::SetICUDefaultLocale(resolved_locale);
return resolved_locale;
}
@@ -429,7 +419,7 @@ std::string GetApplicationLocale(const std::string& pref_locale) {
// Fallback on en-US.
const std::string fallback_locale("en-US");
- if (IsLocaleAvailable(fallback_locale, locale_path)) {
+ if (IsLocaleAvailable(fallback_locale)) {
base::i18n::SetICUDefaultLocale(fallback_locale);
return fallback_locale;
}
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 6a68f20..04cf392 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -119,6 +119,11 @@ ResourceBundle& ResourceBundle::GetSharedInstance() {
return *g_shared_instance_;
}
+/* static */
+bool ResourceBundle::LocaleDataPakExists(const std::string& locale) {
+ return !GetLocaleFilePath(locale).empty();
+}
+
#if !defined(OS_MACOSX)
/* static */
FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) {
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index 7076a6e..45edb38 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -107,6 +107,9 @@ class UI_EXPORT ResourceBundle {
// Return the global resource loader instance.
static ResourceBundle& GetSharedInstance();
+ // Check if the .pak for the given locale exists.
+ static bool LocaleDataPakExists(const std::string& locale);
+
// Gets the bitmap with the specified resource_id from the current module
// data. Returns a pointer to a shared instance of the SkBitmap. This shared
// bitmap is owned by the resource bundle and should not be freed.
diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc
index 9e4f12c..f778588 100644
--- a/ui/base/resource/resource_bundle_unittest.cc
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -35,4 +35,10 @@ TEST(ResourceBundle, LoadDataResourceBytes) {
EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId));
}
+TEST(ResourceBundle, LocaleDataPakExists) {
+ // Check that ResourceBundle::LocaleDataPakExists returns the correct results.
+ EXPECT_TRUE(ResourceBundle::LocaleDataPakExists("en-US"));
+ EXPECT_FALSE(ResourceBundle::LocaleDataPakExists("not_a_real_locale"));
+}
+
} // namespace ui