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

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

Issue 546040: Add reserved messages to ExtensionMessageBundle dictionary. They are of the f... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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 #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 12 matching lines...) Expand all
23 static const wchar_t* kContentKey; 23 static const wchar_t* kContentKey;
24 static const wchar_t* kMessageKey; 24 static const wchar_t* kMessageKey;
25 static const wchar_t* kPlaceholdersKey; 25 static const wchar_t* kPlaceholdersKey;
26 26
27 // Begin/end markers for placeholders and messages 27 // Begin/end markers for placeholders and messages
28 static const char* kPlaceholderBegin; 28 static const char* kPlaceholderBegin;
29 static const char* kPlaceholderEnd; 29 static const char* kPlaceholderEnd;
30 static const char* kMessageBegin; 30 static const char* kMessageBegin;
31 static const char* kMessageEnd; 31 static const char* kMessageEnd;
32 32
33 // Reserved message names in the dictionary.
34 // Update i18n documentation when adding new reserved value.
35 static const char* kUILocaleKey;
36 // See http://code.google.com/apis/gadgets/docs/i18n.html#BIDI for
37 // description.
38 // TODO(cira): point to chrome docs once they are out.
39 static const char* kBidiDirectionKey;
40 static const char* kBidiReversedDirectionKey;
41 static const char* kBidiStartEdgeKey;
42 static const char* kBidiEndEdgeKey;
43
44 // Values for some of the reserved messages.
45 static const char* kBidiLeftEdgeValue;
46 static const char* kBidiRightEdgeValue;
47
33 // Creates ExtensionMessageBundle or returns NULL if there was an error. 48 // Creates ExtensionMessageBundle or returns NULL if there was an error.
34 // Expects locale_catalogs to be sorted from more specific to less specific, 49 // Expects locale_catalogs to be sorted from more specific to less specific,
35 // with default catalog at the end. 50 // with default catalog at the end.
36 static ExtensionMessageBundle* Create(const CatalogVector& locale_catalogs, 51 static ExtensionMessageBundle* Create(const CatalogVector& locale_catalogs,
37 std::string* error); 52 std::string* error);
38 53
39 // Get message from the catalog with given key. 54 // Get message from the catalog with given key.
40 // Returned message has all of the internal placeholders resolved to their 55 // Returned message has all of the internal placeholders resolved to their
41 // value (content). 56 // value (content).
42 // Returns empty string if it can't find a message. 57 // Returns empty string if it can't find a message.
(...skipping 18 matching lines...) Expand all
61 // I.e. replaces __MSG_name__ with value from the catalog with the key "name". 76 // I.e. replaces __MSG_name__ with value from the catalog with the key "name".
62 // Returns false if for a valid message/placeholder name there is no matching 77 // Returns false if for a valid message/placeholder name there is no matching
63 // replacement. 78 // replacement.
64 // Public for easier unittesting. 79 // Public for easier unittesting.
65 static bool ReplaceVariables(const SubstitutionMap& variables, 80 static bool ReplaceVariables(const SubstitutionMap& variables,
66 const std::string& var_begin, 81 const std::string& var_begin,
67 const std::string& var_end, 82 const std::string& var_end,
68 std::string* message, 83 std::string* message,
69 std::string* error); 84 std::string* error);
70 85
71 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name.
72 // Returns false if the input is empty or if it has illegal characters.
73 // Public for easier unittesting.
74 template<typename str>
75 static bool IsValidName(const str& name);
76
77 // Getter for dictionary_. 86 // Getter for dictionary_.
78 const SubstitutionMap* dictionary() const { return &dictionary_; } 87 const SubstitutionMap* dictionary() const { return &dictionary_; }
79 88
80 private: 89 private:
90 // Testing friend.
91 friend class ExtensionMessageBundleTest;
92
81 // Use Create to create ExtensionMessageBundle instance. 93 // Use Create to create ExtensionMessageBundle instance.
82 ExtensionMessageBundle(); 94 ExtensionMessageBundle();
83 95
84 // Initializes the instance from the contents of vector of catalogs. 96 // Initializes the instance from the contents of vector of catalogs.
85 // If the key is not present in more specific catalog we fall back to next one 97 // If the key is not present in more specific catalog we fall back to next one
86 // (less specific). 98 // (less specific).
87 // Returns false on error. 99 // Returns false on error.
88 bool Init(const CatalogVector& locale_catalogs, std::string* error); 100 bool Init(const CatalogVector& locale_catalogs, std::string* error);
89 101
102 // Appends reserved messages to the dictionary.
jungshik at Google 2010/01/20 21:35:47 nit: "Appends locale-specific reserved messages to
Nebojša Ćirić 2010/01/20 22:40:21 Done.
103 // Returns false if there was a conflict with user defined messages.
104 bool AppendReservedMessages(const std::string& application_locale,
105 std::string* error);
106
90 // Helper methods that navigate JSON tree and return simplified message. 107 // Helper methods that navigate JSON tree and return simplified message.
91 // They replace all $PLACEHOLDERS$ with their value, and return just key/value 108 // They replace all $PLACEHOLDERS$ with their value, and return just key/value
92 // of the message. 109 // of the message.
93 bool GetMessageValue(const std::wstring& wkey, 110 bool GetMessageValue(const std::wstring& wkey,
94 const DictionaryValue& catalog, 111 const DictionaryValue& catalog,
95 std::string* value, 112 std::string* value,
96 std::string* error) const; 113 std::string* error) const;
97 114
98 // Get all placeholders for a given message from JSON subtree. 115 // Get all placeholders for a given message from JSON subtree.
99 bool GetPlaceholders(const DictionaryValue& name_tree, 116 bool GetPlaceholders(const DictionaryValue& name_tree,
100 const std::string& name_key, 117 const std::string& name_key,
101 SubstitutionMap* placeholders, 118 SubstitutionMap* placeholders,
102 std::string* error) const; 119 std::string* error) const;
103 120
104 // For a given message, replaces all placeholders with their actual value. 121 // For a given message, replaces all placeholders with their actual value.
105 // Returns false if replacement failed (see ReplaceVariables). 122 // Returns false if replacement failed (see ReplaceVariables).
106 bool ReplacePlaceholders(const SubstitutionMap& placeholders, 123 bool ReplacePlaceholders(const SubstitutionMap& placeholders,
107 std::string* message, 124 std::string* message,
108 std::string* error) const; 125 std::string* error) const;
109 126
127 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name.
128 // Returns false if the input is empty or if it has illegal characters.
129 template<typename str>
130 static bool IsValidName(const str& name);
131
110 // Holds all messages for application locale. 132 // Holds all messages for application locale.
111 SubstitutionMap dictionary_; 133 SubstitutionMap dictionary_;
112 }; 134 };
113 135
114 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ 136 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_constants.cc ('k') | chrome/common/extensions/extension_message_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698