| 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/renderer/extensions/i18n_custom_bindings.h" | 5 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/common/extensions/extension_messages.h" | 8 #include "chrome/common/extensions/extension_messages.h" |
| 9 #include "chrome/common/extensions/message_bundle.h" | 9 #include "chrome/common/extensions/message_bundle.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 extension_id, &messages)); | 50 extension_id, &messages)); |
| 51 | 51 |
| 52 // Save messages we got. | 52 // Save messages we got. |
| 53 ExtensionToL10nMessagesMap& l10n_messages_map = | 53 ExtensionToL10nMessagesMap& l10n_messages_map = |
| 54 *GetExtensionToL10nMessagesMap(); | 54 *GetExtensionToL10nMessagesMap(); |
| 55 l10n_messages_map[extension_id] = messages; | 55 l10n_messages_map[extension_id] = messages; |
| 56 | 56 |
| 57 l10n_messages = GetL10nMessagesMap(extension_id); | 57 l10n_messages = GetL10nMessagesMap(extension_id); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string message_name = *v8::String::AsciiValue(args[0]); | 60 std::string message_name = *v8::String::Utf8Value(args[0]); |
| 61 std::string message = | 61 std::string message = |
| 62 MessageBundle::GetL10nMessage(message_name, *l10n_messages); | 62 MessageBundle::GetL10nMessage(message_name, *l10n_messages); |
| 63 | 63 |
| 64 std::vector<std::string> substitutions; | 64 std::vector<std::string> substitutions; |
| 65 if (args[1]->IsArray()) { | 65 if (args[1]->IsArray()) { |
| 66 // chrome.i18n.getMessage("message_name", ["more", "params"]); | 66 // chrome.i18n.getMessage("message_name", ["more", "params"]); |
| 67 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); | 67 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); |
| 68 uint32_t count = placeholders->Length(); | 68 uint32_t count = placeholders->Length(); |
| 69 if (count > 9) | 69 if (count > 9) |
| 70 return; | 70 return; |
| 71 for (uint32_t i = 0; i < count; ++i) { | 71 for (uint32_t i = 0; i < count; ++i) { |
| 72 substitutions.push_back( | 72 substitutions.push_back( |
| 73 *v8::String::Utf8Value( | 73 *v8::String::Utf8Value( |
| 74 placeholders->Get(v8::Integer::New(i))->ToString())); | 74 placeholders->Get(v8::Integer::New(i))->ToString())); |
| 75 } | 75 } |
| 76 } else if (args[1]->IsString()) { | 76 } else if (args[1]->IsString()) { |
| 77 // chrome.i18n.getMessage("message_name", "one param"); | 77 // chrome.i18n.getMessage("message_name", "one param"); |
| 78 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); | 78 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 args.GetReturnValue().Set( | 81 args.GetReturnValue().Set( |
| 82 v8::String::NewFromUtf8(args.GetIsolate(), ReplaceStringPlaceholders( | 82 v8::String::NewFromUtf8(args.GetIsolate(), ReplaceStringPlaceholders( |
| 83 message, substitutions, NULL).c_str())); | 83 message, substitutions, NULL).c_str())); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace extensions | 86 } // namespace extensions |
| OLD | NEW |