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

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

Issue 570007: Replace __MSG_some_name__ template within extension css/html files with local... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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) 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/common/extensions/extension_message_bundle.h" 5 #include "chrome/common/extensions/extension_message_bundle.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/linked_ptr.h" 12 #include "base/linked_ptr.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/singleton.h"
14 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/extensions/extension_error_utils.h" 19 #include "chrome/common/extensions/extension_error_utils.h"
19 #include "chrome/common/extensions/extension_l10n_util.h" 20 #include "chrome/common/extensions/extension_l10n_util.h"
20 21
21 namespace errors = extension_manifest_errors; 22 namespace errors = extension_manifest_errors;
22 23
23 const wchar_t* ExtensionMessageBundle::kContentKey = L"content"; 24 const wchar_t* ExtensionMessageBundle::kContentKey = L"content";
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 std::string* error) const { 203 std::string* error) const {
203 return ReplaceVariables(placeholders, 204 return ReplaceVariables(placeholders,
204 kPlaceholderBegin, 205 kPlaceholderBegin,
205 kPlaceholderEnd, 206 kPlaceholderEnd,
206 message, 207 message,
207 error); 208 error);
208 } 209 }
209 210
210 bool ExtensionMessageBundle::ReplaceMessages(std::string* text, 211 bool ExtensionMessageBundle::ReplaceMessages(std::string* text,
211 std::string* error) const { 212 std::string* error) const {
212 return ReplaceVariables(dictionary_, kMessageBegin, kMessageEnd, text, error); 213 return ReplaceMessagesWithExternalDictionary(dictionary_, text, error);
214 }
215
216 // static
217 bool ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary(
218 const SubstitutionMap& dictionary, std::string* text, std::string* error) {
219 return ReplaceVariables(dictionary, kMessageBegin, kMessageEnd, text, error);
213 } 220 }
214 221
215 // static 222 // static
216 bool ExtensionMessageBundle::ReplaceVariables( 223 bool ExtensionMessageBundle::ReplaceVariables(
217 const SubstitutionMap& variables, 224 const SubstitutionMap& variables,
218 const std::string& var_begin_delimiter, 225 const std::string& var_begin_delimiter,
219 const std::string& var_end_delimiter, 226 const std::string& var_end_delimiter,
220 std::string* message, 227 std::string* message,
221 std::string* error) { 228 std::string* error) {
222 std::string::size_type beg_index = 0; 229 std::string::size_type beg_index = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 std::string ExtensionMessageBundle::GetL10nMessage( 283 std::string ExtensionMessageBundle::GetL10nMessage(
277 const std::string& name, const SubstitutionMap& dictionary) { 284 const std::string& name, const SubstitutionMap& dictionary) {
278 SubstitutionMap::const_iterator it = 285 SubstitutionMap::const_iterator it =
279 dictionary.find(StringToLowerASCII(name)); 286 dictionary.find(StringToLowerASCII(name));
280 if (it != dictionary.end()) { 287 if (it != dictionary.end()) {
281 return it->second; 288 return it->second;
282 } 289 }
283 290
284 return ""; 291 return "";
285 } 292 }
293
294 ///////////////////////////////////////////////////////////////////////////////
295 //
296 // Renderer helper functions.
297 //
298 ///////////////////////////////////////////////////////////////////////////////
299
300 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap() {
301 return &Singleton<ExtensionToMessagesMap>()->messages_map;
302 }
303
304 L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id) {
305 ExtensionToL10nMessagesMap::iterator it =
306 Singleton<ExtensionToMessagesMap>()->messages_map.find(extension_id);
307 if (it != Singleton<ExtensionToMessagesMap>()->messages_map.end())
308 return &(it->second);
309
310 return NULL;
311 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_message_bundle.h ('k') | chrome/common/extensions/extension_message_bundle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698