OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/extensions/extension_l10n_util.h" | 5 #include "chrome/browser/extensions/extension_l10n_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 valid_locales->insert(locale_name); | 55 valid_locales->insert(locale_name); |
56 } else { | 56 } else { |
57 *error = StringPrintf("Catalog file is missing for locale %s.", | 57 *error = StringPrintf("Catalog file is missing for locale %s.", |
58 locale_name.c_str()); | 58 locale_name.c_str()); |
59 return false; | 59 return false; |
60 } | 60 } |
61 | 61 |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 // Converts all - into _, to be consistent with ICU and file system names. | 65 std::string NormalizeLocale(const std::string& locale) { |
66 static std::string NormalizeLocale(const std::string& locale) { | |
67 std::string normalized_locale(locale); | 66 std::string normalized_locale(locale); |
68 std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_'); | 67 std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_'); |
69 | 68 |
70 return normalized_locale; | 69 return normalized_locale; |
71 } | 70 } |
72 | 71 |
73 // Produce a vector of parent locales for given locale. | 72 void GetParentLocales(const std::string& current_locale, |
74 // It includes the current locale in the result. | 73 std::vector<std::string>* parent_locales) { |
75 // sr_Cyrl_RS generates sr_Cyrl_RS, sr_Cyrl and sr. | |
76 static void GetParentLocales(const std::string& current_locale, | |
77 std::vector<std::string>* parent_locales) { | |
78 std::string locale(NormalizeLocale(current_locale)); | 74 std::string locale(NormalizeLocale(current_locale)); |
79 | 75 |
80 const int kNameCapacity = 256; | 76 const int kNameCapacity = 256; |
81 char parent[kNameCapacity]; | 77 char parent[kNameCapacity]; |
82 strncpy(parent, locale.c_str(), kNameCapacity); | 78 strncpy(parent, locale.c_str(), kNameCapacity); |
83 parent_locales->push_back(parent); | 79 parent_locales->push_back(parent); |
84 UErrorCode err = U_ZERO_ERROR; | 80 UErrorCode err = U_ZERO_ERROR; |
85 while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) { | 81 while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) { |
86 if (err != U_ZERO_ERROR) | 82 if (err != U_ZERO_ERROR) |
87 break; | 83 break; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // an error. | 176 // an error. |
181 return false; | 177 return false; |
182 } else { | 178 } else { |
183 catalogs.push_back(catalog); | 179 catalogs.push_back(catalog); |
184 } | 180 } |
185 } | 181 } |
186 | 182 |
187 return ExtensionMessageBundle::Create(catalogs, error); | 183 return ExtensionMessageBundle::Create(catalogs, error); |
188 } | 184 } |
189 | 185 |
190 FilePath GetL10nRelativePath(const FilePath& relative_resource_path) { | 186 void GetL10nRelativePaths(const FilePath& relative_resource_path, |
191 // Get locale relative path. | 187 std::vector<FilePath>* l10n_paths) { |
192 static std::string current_locale = l10n_util::GetApplicationLocale(L""); | 188 DCHECK(NULL != l10n_paths); |
193 std::replace(current_locale.begin(), current_locale.end(), '-', '_'); | 189 |
| 190 std::vector<std::string> locales; |
| 191 static const std::string current_locale = |
| 192 l10n_util::GetApplicationLocale(L""); |
| 193 GetParentLocales(current_locale, &locales); |
194 | 194 |
195 FilePath locale_relative_path; | 195 FilePath locale_relative_path; |
196 return locale_relative_path | 196 for (size_t i = 0; i < locales.size(); ++i) { |
197 .AppendASCII(Extension::kLocaleFolder) | 197 l10n_paths->push_back(locale_relative_path |
198 .AppendASCII(current_locale) | 198 .AppendASCII(Extension::kLocaleFolder) |
199 .Append(relative_resource_path); | 199 .AppendASCII(locales[i]) |
| 200 .Append(relative_resource_path)); |
| 201 } |
200 } | 202 } |
201 | 203 |
202 } // namespace extension_l10n_util | 204 } // namespace extension_l10n_util |
OLD | NEW |