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

Side by Side Diff: chrome/common/extensions/docs/server2/templates/articles/i18n-messages.html

Issue 10832042: Extensions Docs Server: Doc conversion script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment in converter.py Created 8 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
(Empty)
1 <h1 class="page_title">Formats: Locale-Specific Messages</h1>
2 <div id="pageData-showTOC" class="pageData">true</div>
3 <p>
4 Each internationalized extension has at least one
5 file named <code>messages.json</code>
6 that provides locale-specific strings for the extension.
7 This page describes the format of <code>messages.json</code> files.
8 For information on how to internationalize and localize your extension,
9 see the <a href="i18n.html">Internationalization</a> page.
10 </p>
11 <h2 id="overview"> Field summary </h2>
12 <p>
13 The following code shows the supported fields for
14 <code>messages.json</code>.
15 Only the "<em>name</em>" and "message" fields are required.
16 </p>
17 <pre>
18 {
19 "<a href="#name"><em>name</em></a>": {
20 "<a href="#message">message</a>": "<em>Message text, with optional placehold ers.</em>",
21 "<a href="#description">description</a>": "<em>Translator-aimed description of the message.</em>",
22 "<a href="#placeholders">placeholders</a>": {
23 "<em>placeholder_name</em>": {
24 "content": "<em>A string to be placed within the message.</em>",
25 "example": "<em>Translator-aimed example of the placeholder string.</em> "
26 },
27 ...
28 }
29 },
30 ...
31 }
32 </pre>
33 <h2 id="example"> Example </h2>
34 <p>
35 Here's a <code>messages.json</code> file
36 that defines three messages
37 named "prompt_for_name", "hello", and "bye":
38 </p>
39 <pre>
40 {
41 "prompt_for_name": {
42 "message": "What's your name?",
43 "description": "Ask for the user's name"
44 },
45 "hello": {
46 "message": "Hello, $USER$",
47 "description": "Greet the user",
48 "placeholders": {
49 "user": {
50 "content": "$1",
51 "example": "Cira"
52 }
53 }
54 },
55 "bye": {
56 "message": "Goodbye, $USER$. Come back to $OUR_SITE$ soon!",
57 "description": "Say goodbye to the user",
58 "placeholders": {
59 "our_site": {
60 "content": "Example.com",
61 },
62 "user": {
63 "content": "$1",
64 "example": "Cira"
65 }
66 }
67 }
68 }
69 </pre>
70 <h2>Field details</h2>
71 <p>
72 This section describes each field
73 that can appear in a <code>messages.json</code> file.
74 For details on how the messages file is used &mdash;
75 for example, what happens when a locale doesn't define
76 all the messages &mdash;
77 see <a href="i18n.html">Internationalization</a>.
78 </p>
79 <h3 id="name">name</h3>
80 <p>
81 Actually, there's no field called "name".
82 This field's name is the name of the message &mdash;
83 the same <em>name</em> that you see in
84 <code>__MSG_<em>name</em>__</code>
85 or <code>getMessage("<em>name</em>")</code>.
86 </p>
87 <p>
88 The name is a case-insensitive key
89 that lets you retrieve the localized message text.
90 The name can include the following characters:
91 </p>
92 <ul>
93 <li> A-Z </li>
94 <li> a-z </li>
95 <li> 0-9 </li>
96 <li> _ (underscore) </li>
97 <li> @ </li>
98 </ul>
99 <p class="note">
100 <b>Note:</b>
101 Don't define names that begin with "@@".
102 Those names are reserved for
103 <a href="i18n.html#overview-predefined">predefined messages</a>.
104 </p>
105 <p>
106 Here are three examples of names,
107 taken from the <a href="#example">Example</a> section:
108 </p>
109 <pre>
110 "prompt_for_name": {
111 ...
112 },
113 "hello": {
114 ...
115 },
116 "bye": {
117 ...
118 }
119 </pre>
120 <p>
121 For more examples of using names, see the
122 <a href="i18n.html">Internationalization</a> page.
123 </p>
124 <h3 id="message">message</h3>
125 <p>
126 The translated message,
127 in the form of a string that can contain
128 <a href="#placeholders">placeholders</a>.
129 Use <code>$<em>placeholder_name</em>$</code>
130 (case insensitive)
131 to refer to a particular placeholder.
132 For example, you can refer to a placeholder named "our_site" as
133 <code>$our_site$</code>, <code>$OUR_SITE$</code>, or <code>$oUR_sITe$</code>.
134 </p>
135 <p>
136 Here are three examples of messages,
137 taken from the <a href="#example">Example</a> section:
138 </p>
139 <pre>
140 "message": "What's your name?"
141 ...
142 "message": "Hello, $USER$"
143 ...
144 "message": "Goodbye, $USER$. Come back to $OUR_SITE$ soon!"
145 </pre>
146 <p>
147 To put a dollar sign (<code>$</code>) into the string,
148 use <code>$$</code>.
149 For example, use the following code to specify the message
150 <b>Amount (in $)</b>:
151 <pre>
152 "message": "Amount (in $$)"
153 </pre>
154 <p>
155 Although placeholders such as <code>$USER$</code> are
156 the preferred way of referring to <em>substitution strings</em>
157 (strings specified using the <em>substitutions</em> parameter of
158 <a href="i18n.html#method-getMessage"><code>getMessage()</code></a>)
159 you can also refer to substitution strings directly
160 within the message.
161 For example, the following message
162 refers to the first three substitution strings passed into
163 <code>getMessage()</code>:
164 </p>
165 <pre>
166 "message": "Params: $1, $2, $3"
167 </pre>
168 <p>
169 Despite that example,
170 we recommend that you stick to using placeholders
171 instead of <code>$<em>n</em></code> strings
172 within your messages.
173 Think of placeholders as good variable names.
174 A week after you write your code,
175 you'll probably forget what <code>$1</code> refers to,
176 but you'll know what your placeholders refer to.
177 For more information on placeholders and substitution strings, see
178 the <a href="#placeholders">placeholders</a> section.
179 </p>
180 <h3 id="description">description</h3>
181 <p>
182 <em>Optional.</em>
183 A description of the message,
184 intended to give context
185 or details to help the translator
186 make the best possible translation.
187 </p>
188 <p>
189 Here are three examples of descriptions,
190 taken from the <a href="#example">Example</a> section:
191 </p>
192 <pre>
193 "description": "Ask for the user's name"
194 ...
195 "description": "Greet the user"
196 ...
197 "description": "Say goodbye to the user"
198 </pre>
199 <h3 id="placeholders">placeholders</h3>
200 <p>
201 <em>Optional.</em>
202 Defines one or more substrings
203 to be used within the message.
204 Here are two reasons you might want to use a placeholder:
205 </p>
206 <ul>
207 <li>
208 To define the text
209 for a part of your message
210 that shouldn't be translated.
211 Examples: HTML code, trademarked names, formatting specifiers.
212 </li>
213 <li>
214 To refer to a substitution string passed into
215 <code>getMessage()</code>.
216 Example: <code>$1</code>.
217 </li>
218 </ul>
219 <p>
220 Each placeholder has a name,
221 a "content" item,
222 and an optional "example" item.
223 A placeholder's name is case-insensitive
224 and can contain the same characters
225 as a <a href="#name">message name</a>.
226 </p>
227 <p>
228 The "content" item's value is a string
229 that can refer to substitution strings, which are
230 specified using the
231 <a href="i18n.html#method-getMessage"><code>getMessage()</code></a> method's
232 <em>substitutions</em> parameter.
233 The value of a "content" item is typically something like
234 "Example.com" or "$1".
235 If you refer to
236 a substitution string that doesn't exist,
237 you get an empty string.
238 The following table shows how
239 <code>$<em>n</em></code> strings correspond to
240 strings specified by the <em>substitutions</em> parameter.
241 </p>
242 <table>
243 <tr>
244 <th> <em>substitutions</em> parameter </th>
245 <th> Value of $1</th>
246 <th> Value of $2</th>
247 <th> Value of $3</th>
248 </tr>
249 <tr>
250 <td> <code>userName</code> </td>
251 <td> value of <code>userName</code> </td>
252 <td> <code>""</code> </td>
253 <td> <code>""</code> </td>
254 </tr>
255 <tr>
256 <td> <code>["Cira", "Kathy"]</code> </td>
257 <td> <code>"Cira"</code> </td>
258 <td> <code>"Kathy"</code> </td>
259 <td> <code>""</code> </td>
260 </tr>
261 </table>
262 <p>
263 The "example" item
264 (optional, but highly recommended)
265 helps translators by showing how the content appears to the end user.
266 For example, a placeholder
267 for a dollar amount
268 should have an example like <code>"$23.45"</code>.
269 </p>
270 <p>
271 The following snippet,
272 taken from the <a href="#example">Example</a> section,
273 shows a "placeholders" item that contains two placeholders
274 named "our_site" and "user".
275 The "our_site" placeholder has no "example" item
276 because its value is obvious from the "content" field.
277 </p>
278 <pre>
279 "placeholders": {
280 "our_site": {
281 "content": "Example.com",
282 },
283 "user": {
284 "content": "$1",
285 "example": "Cira"
286 }
287 }
288 </pre>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698