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

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

Powered by Google App Engine
This is Rietveld 408576698