OLD | NEW |
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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const SubstitutionMap& dictionary); | 64 const SubstitutionMap& dictionary); |
65 | 65 |
66 // Number of messages in the catalog. | 66 // Number of messages in the catalog. |
67 // Used for unittesting only. | 67 // Used for unittesting only. |
68 size_t size() const { return dictionary_.size(); } | 68 size_t size() const { return dictionary_.size(); } |
69 | 69 |
70 // Replaces all __MSG_message__ with values from the catalog. | 70 // Replaces all __MSG_message__ with values from the catalog. |
71 // Returns false if there is a message in text that's not defined in the | 71 // Returns false if there is a message in text that's not defined in the |
72 // dictionary. | 72 // dictionary. |
73 bool ReplaceMessages(std::string* text, std::string* error) const; | 73 bool ReplaceMessages(std::string* text, std::string* error) const; |
| 74 // Static version that accepts dictionary. |
| 75 static bool ReplaceMessagesWithExternalDictionary( |
| 76 const SubstitutionMap& dictionary, std::string* text, std::string* error); |
74 | 77 |
75 // Replaces each occurance of variable placeholder with its value. | 78 // Replaces each occurance of variable placeholder with its value. |
76 // I.e. replaces __MSG_name__ with value from the catalog with the key "name". | 79 // I.e. replaces __MSG_name__ with value from the catalog with the key "name". |
77 // Returns false if for a valid message/placeholder name there is no matching | 80 // Returns false if for a valid message/placeholder name there is no matching |
78 // replacement. | 81 // replacement. |
79 // Public for easier unittesting. | 82 // Public for easier unittesting. |
80 static bool ReplaceVariables(const SubstitutionMap& variables, | 83 static bool ReplaceVariables(const SubstitutionMap& variables, |
81 const std::string& var_begin, | 84 const std::string& var_begin, |
82 const std::string& var_end, | 85 const std::string& var_end, |
83 std::string* message, | 86 std::string* message, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // For a given message, replaces all placeholders with their actual value. | 141 // For a given message, replaces all placeholders with their actual value. |
139 // Returns false if replacement failed (see ReplaceVariables). | 142 // Returns false if replacement failed (see ReplaceVariables). |
140 bool ReplacePlaceholders(const SubstitutionMap& placeholders, | 143 bool ReplacePlaceholders(const SubstitutionMap& placeholders, |
141 std::string* message, | 144 std::string* message, |
142 std::string* error) const; | 145 std::string* error) const; |
143 | 146 |
144 // Holds all messages for application locale. | 147 // Holds all messages for application locale. |
145 SubstitutionMap dictionary_; | 148 SubstitutionMap dictionary_; |
146 }; | 149 }; |
147 | 150 |
| 151 /////////////////////////////////////////////////////////////////////////////// |
| 152 // |
| 153 // Renderer helper typedefs and functions. |
| 154 // |
| 155 /////////////////////////////////////////////////////////////////////////////// |
| 156 |
| 157 // A map of message name to message. |
| 158 typedef std::map<std::string, std::string> L10nMessagesMap; |
| 159 |
| 160 // A map of extension ID to l10n message map. |
| 161 typedef std::map<std::string, L10nMessagesMap > ExtensionToL10nMessagesMap; |
| 162 |
| 163 // Unique class for Singleton. |
| 164 struct ExtensionToMessagesMap { |
| 165 // Maps extension ID to message map. |
| 166 ExtensionToL10nMessagesMap messages_map; |
| 167 }; |
| 168 |
| 169 // Returns the extension_id to messages map. |
| 170 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap(); |
| 171 |
| 172 // Returns message map that matches given extension_id, or NULL. |
| 173 L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id); |
| 174 |
148 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 175 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ |
OLD | NEW |