Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/common/extensions/extension_l10n_util.cc

Issue 10790087: [Web Intents] Localization of intent titles for CWS suggestions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
Greg Billock 2012/07/20 15:58:30 Should GetParentLocales not append "all" already?
groby-ooo-7-16 2012/07/20 22:59:54 No - see use in LoadMessageCatalogs. On 2012/07/2
246 all_fallback_locales->push_back(default_locale);
247 }
248
240 bool GetValidLocales(const FilePath& locale_path, 249 bool GetValidLocales(const FilePath& locale_path,
241 std::set<std::string>* valid_locales, 250 std::set<std::string>* valid_locales,
242 std::string* error) { 251 std::string* error) {
243 std::set<std::string> chrome_locales; 252 std::set<std::string> chrome_locales;
244 GetAllLocales(&chrome_locales); 253 GetAllLocales(&chrome_locales);
245 254
246 // Enumerate all supplied locales in the extension. 255 // Enumerate all supplied locales in the extension.
247 file_util::FileEnumerator locales(locale_path, 256 file_util::FileEnumerator locales(locale_path,
248 false, 257 false,
249 file_util::FileEnumerator::DIRECTORIES); 258 file_util::FileEnumerator::DIRECTORIES);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 300
292 return static_cast<DictionaryValue*>(dictionary); 301 return static_cast<DictionaryValue*>(dictionary);
293 } 302 }
294 303
295 ExtensionMessageBundle* LoadMessageCatalogs( 304 ExtensionMessageBundle* LoadMessageCatalogs(
296 const FilePath& locale_path, 305 const FilePath& locale_path,
297 const std::string& default_locale, 306 const std::string& default_locale,
298 const std::string& application_locale, 307 const std::string& application_locale,
299 const std::set<std::string>& valid_locales, 308 const std::set<std::string>& valid_locales,
300 std::string* error) { 309 std::string* error) {
301 // Order locales to load as current_locale, first_parent, ..., default_locale.
302 std::vector<std::string> all_fallback_locales; 310 std::vector<std::string> all_fallback_locales;
303 if (!application_locale.empty() && application_locale != default_locale) 311 GetAllFallbackLocales(application_locale, default_locale,
304 l10n_util::GetParentLocales(application_locale, &all_fallback_locales); 312 &all_fallback_locales);
305 all_fallback_locales.push_back(default_locale);
306 313
307 std::vector<linked_ptr<DictionaryValue> > catalogs; 314 std::vector<linked_ptr<DictionaryValue> > catalogs;
308 for (size_t i = 0; i < all_fallback_locales.size(); ++i) { 315 for (size_t i = 0; i < all_fallback_locales.size(); ++i) {
309 // Skip all parent locales that are not supplied. 316 // Skip all parent locales that are not supplied.
310 if (valid_locales.find(all_fallback_locales[i]) == valid_locales.end()) 317 if (valid_locales.find(all_fallback_locales[i]) == valid_locales.end())
311 continue; 318 continue;
312 linked_ptr<DictionaryValue> catalog( 319 linked_ptr<DictionaryValue> catalog(
313 LoadMessageFile(locale_path, all_fallback_locales[i], error)); 320 LoadMessageFile(locale_path, all_fallback_locales[i], error));
314 if (!catalog.get()) { 321 if (!catalog.get()) {
315 // If locale is valid, but messages.json is corrupted or missing, return 322 // If locale is valid, but messages.json is corrupted or missing, return
(...skipping 25 matching lines...) Expand all
341 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) 348 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end())
342 return true; 349 return true;
343 350
344 if (all_locales.find(subdir) == all_locales.end()) 351 if (all_locales.find(subdir) == all_locales.end())
345 return true; 352 return true;
346 353
347 return false; 354 return false;
348 } 355 }
349 356
350 } // namespace extension_l10n_util 357 } // namespace extension_l10n_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698