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

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

Issue 7552028: Injected CSS localization fix (see bug no.) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated. Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/extensions/extension_file_util.h" 19 #include "chrome/common/extensions/extension_file_util.h"
20 #include "chrome/common/extensions/extension_messages.h"
20 #include "chrome/common/extensions/extension_message_bundle.h" 21 #include "chrome/common/extensions/extension_message_bundle.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "content/common/json_value_serializer.h" 23 #include "content/common/json_value_serializer.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "unicode/uloc.h" 25 #include "unicode/uloc.h"
25 26
26 namespace errors = extension_manifest_errors; 27 namespace errors = extension_manifest_errors;
27 namespace keys = extension_manifest_keys; 28 namespace keys = extension_manifest_keys;
28 29
29 static std::string* GetProcessLocale() { 30 static std::string* GetProcessLocale() {
(...skipping 24 matching lines...) Expand all
54 return false; 55 return false;
55 56
56 if (!manifest->HasKey(keys::kDefaultLocale)) 57 if (!manifest->HasKey(keys::kDefaultLocale))
57 return false; 58 return false;
58 59
59 std::string manifest_current_locale; 60 std::string manifest_current_locale;
60 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale); 61 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale);
61 return manifest_current_locale != CurrentLocaleOrDefault(); 62 return manifest_current_locale != CurrentLocaleOrDefault();
62 } 63 }
63 64
65 void LocalizeCSSScript(const Extension* extension, std::string& css_script) {
66 std::string error;
67 scoped_ptr<SubstitutionMap> localization_messages(
68 extension_file_util::LoadExtensionMessageBundleSubstitutionMap(
69 extension->path(), extension->id(), extension->default_locale()));
70 ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary(
71 *localization_messages, &css_script, &error);
72 }
73
64 // Localizes manifest value for a given key. 74 // Localizes manifest value for a given key.
65 static bool LocalizeManifestValue(const std::string& key, 75 static bool LocalizeManifestValue(const std::string& key,
66 const ExtensionMessageBundle& messages, 76 const ExtensionMessageBundle& messages,
67 DictionaryValue* manifest, 77 DictionaryValue* manifest,
68 std::string* error) { 78 std::string* error) {
69 std::string result; 79 std::string result;
70 if (!manifest->GetString(key, &result)) 80 if (!manifest->GetString(key, &result))
71 return true; 81 return true;
72 82
73 if (!messages.ReplaceMessages(&result, error)) 83 if (!messages.ReplaceMessages(&result, error))
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) 316 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end())
307 return true; 317 return true;
308 318
309 if (all_locales.find(subdir) == all_locales.end()) 319 if (all_locales.find(subdir) == all_locales.end())
310 return true; 320 return true;
311 321
312 return false; 322 return false;
313 } 323 }
314 324
315 } // namespace extension_l10n_util 325 } // namespace extension_l10n_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698