OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/extensions/extension_l10n_util.h" | 5 #include "chrome/common/extensions/extension_l10n_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 l10n_util::GetAvailableLocales(); | 230 l10n_util::GetAvailableLocales(); |
231 // Add all parents of the current locale to the available locales set. | 231 // Add all parents of the current locale to the available locales set. |
232 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr. | 232 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr. |
233 for (size_t i = 0; i < available_locales.size(); ++i) { | 233 for (size_t i = 0; i < available_locales.size(); ++i) { |
234 std::vector<std::string> result; | 234 std::vector<std::string> result; |
235 l10n_util::GetParentLocales(available_locales[i], &result); | 235 l10n_util::GetParentLocales(available_locales[i], &result); |
236 all_locales->insert(result.begin(), result.end()); | 236 all_locales->insert(result.begin(), result.end()); |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 void GetAllFallbackLocales(const std::string& application_locale, | |
241 const std::string& default_locale, | |
242 std::vector<std::string>* all_fallback_locales) { | |
243 DCHECK(all_fallback_locales); | |
244 if (!application_locale.empty() && application_locale != default_locale) | |
245 l10n_util::GetParentLocales(application_locale, all_fallback_locales); | |
246 all_fallback_locales->push_back(default_locale); | |
247 } | |
248 | |
249 bool GetValidLocales(const FilePath& locale_path, | 240 bool GetValidLocales(const FilePath& locale_path, |
250 std::set<std::string>* valid_locales, | 241 std::set<std::string>* valid_locales, |
251 std::string* error) { | 242 std::string* error) { |
252 std::set<std::string> chrome_locales; | 243 std::set<std::string> chrome_locales; |
253 GetAllLocales(&chrome_locales); | 244 GetAllLocales(&chrome_locales); |
254 | 245 |
255 // Enumerate all supplied locales in the extension. | 246 // Enumerate all supplied locales in the extension. |
256 file_util::FileEnumerator locales(locale_path, | 247 file_util::FileEnumerator locales(locale_path, |
257 false, | 248 false, |
258 file_util::FileEnumerator::DIRECTORIES); | 249 file_util::FileEnumerator::DIRECTORIES); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 291 |
301 return static_cast<DictionaryValue*>(dictionary); | 292 return static_cast<DictionaryValue*>(dictionary); |
302 } | 293 } |
303 | 294 |
304 extensions::MessageBundle* LoadMessageCatalogs( | 295 extensions::MessageBundle* LoadMessageCatalogs( |
305 const FilePath& locale_path, | 296 const FilePath& locale_path, |
306 const std::string& default_locale, | 297 const std::string& default_locale, |
307 const std::string& application_locale, | 298 const std::string& application_locale, |
308 const std::set<std::string>& valid_locales, | 299 const std::set<std::string>& valid_locales, |
309 std::string* error) { | 300 std::string* error) { |
| 301 // Order locales to load as current_locale, first_parent, ..., default_locale. |
310 std::vector<std::string> all_fallback_locales; | 302 std::vector<std::string> all_fallback_locales; |
311 GetAllFallbackLocales(application_locale, default_locale, | 303 if (!application_locale.empty() && application_locale != default_locale) |
312 &all_fallback_locales); | 304 l10n_util::GetParentLocales(application_locale, &all_fallback_locales); |
| 305 all_fallback_locales.push_back(default_locale); |
313 | 306 |
314 std::vector<linked_ptr<DictionaryValue> > catalogs; | 307 std::vector<linked_ptr<DictionaryValue> > catalogs; |
315 for (size_t i = 0; i < all_fallback_locales.size(); ++i) { | 308 for (size_t i = 0; i < all_fallback_locales.size(); ++i) { |
316 // Skip all parent locales that are not supplied. | 309 // Skip all parent locales that are not supplied. |
317 if (valid_locales.find(all_fallback_locales[i]) == valid_locales.end()) | 310 if (valid_locales.find(all_fallback_locales[i]) == valid_locales.end()) |
318 continue; | 311 continue; |
319 linked_ptr<DictionaryValue> catalog( | 312 linked_ptr<DictionaryValue> catalog( |
320 LoadMessageFile(locale_path, all_fallback_locales[i], error)); | 313 LoadMessageFile(locale_path, all_fallback_locales[i], error)); |
321 if (!catalog.get()) { | 314 if (!catalog.get()) { |
322 // If locale is valid, but messages.json is corrupted or missing, return | 315 // If locale is valid, but messages.json is corrupted or missing, return |
(...skipping 25 matching lines...) Expand all Loading... |
348 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) | 341 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) |
349 return true; | 342 return true; |
350 | 343 |
351 if (all_locales.find(subdir) == all_locales.end()) | 344 if (all_locales.find(subdir) == all_locales.end()) |
352 return true; | 345 return true; |
353 | 346 |
354 return false; | 347 return false; |
355 } | 348 } |
356 | 349 |
357 } // namespace extension_l10n_util | 350 } // namespace extension_l10n_util |
OLD | NEW |