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

Side by Side Diff: chrome/common/extensions/docs/server2/templates/intros/i18n.html

Issue 10832042: Extensions Docs Server: Doc conversion script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: everything but svn stuff 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
1 <!-- 1 <!--
2 [NOTEs for editors: 2 [NOTEs for editors:
3 * Try to be consistent about string vs. message (it's probably not yet). 3 * Try to be consistent about string vs. message (it's probably not yet).
4 --> 4 -->
5 <!-- BEGIN AUTHORED CONTENT --> 5
6
6 <p id="classSummary"> 7 <p id="classSummary">
7 An <em>internationalized</em> extension 8 An <em>internationalized</em> extension
8 can be easily 9 can be easily
9 <em>localized</em> &mdash; 10 <em>localized</em> &mdash;
10 adapted to languages and regions 11 adapted to languages and regions
11 that it didn't originally support. 12 that it didn't originally support.
12 </p> 13 </p>
14
13 <p> 15 <p>
14 To internationalize your extension, 16 To internationalize your extension,
15 you need to put all of its user-visible strings into a file 17 you need to put all of its user-visible strings into a file
16 named <a href="i18n-messages.html"><code>messages.json</code></a>. 18 named <a href="i18n-messages.html"><code>messages.json</code></a>.
17 Each time you localize your extension 19 Each time you localize your extension
18 you add a messages file 20 you add a messages file
19 under a directory 21 under a directory
20 named <code>_locales/<em>localeCode</em></code>, 22 named <code>_locales/<em>localeCode</em></code>,
21 where <em>localeCode</em> is a code such as 23 where <em>localeCode</em> is a code such as
22 <code>en</code> for English. 24 <code>en</code> for English.
23 </p> 25 </p>
26
24 <p> 27 <p>
25 Here's the file hierarchy 28 Here's the file hierarchy
26 for an internationalized extension that supports 29 for an internationalized extension that supports
27 English (<code>en</code>), 30 English (<code>en</code>),
28 Spanish (<code>es</code>), and 31 Spanish (<code>es</code>), and
29 Korean (<code>ko</code>): 32 Korean (<code>ko</code>):
30 </p> 33 </p>
34
31 <img src="{{static}}/images/i18n-hierarchy.gif" 35 <img src="{{static}}/images/i18n-hierarchy.gif"
32 alt='In the extension directory: manifest.json, *.html, *.js, _locales director y. In the _locales directory: en, es, and ko directories, each with a messages.j son file.' 36 alt='In the extension directory: manifest.json, *.html, *.js, _locales director y. In the _locales directory: en, es, and ko directories, each with a messages.j son file.'
33 width="385" height="77" /> 37 width="385" height="77" />
38
39
34 <h2 id="l10">How to support multiple languages</h2> 40 <h2 id="l10">How to support multiple languages</h2>
41
35 <p> 42 <p>
36 Say you have an extension 43 Say you have an extension
37 with the files shown in the following figure: 44 with the files shown in the following figure:
38 </p> 45 </p>
46
39 <img src="{{static}}/images/i18n-before.gif" 47 <img src="{{static}}/images/i18n-before.gif"
40 alt='A manifest.json file and a file with JavaScript. The .json file has "name" : "Hello World". The JavaScript file has title = "Hello World";' 48 alt='A manifest.json file and a file with JavaScript. The .json file has "name" : "Hello World". The JavaScript file has title = "Hello World";'
41 width="323" height="148"> 49 width="323" height="148">
50
42 <p> 51 <p>
43 To internationalize this extension, 52 To internationalize this extension,
44 you name each user-visible string 53 you name each user-visible string
45 and put it into a messages file. 54 and put it into a messages file.
46 The extension's manifest, 55 The extension's manifest,
47 CSS files, 56 CSS files,
48 and JavaScript code 57 and JavaScript code
49 use each string's name to get its localized version. 58 use each string's name to get its localized version.
50 </p> 59 </p>
60
51 <p> 61 <p>
52 Here's what the extension looks like when it's internationalized 62 Here's what the extension looks like when it's internationalized
53 (note that it still has only English strings): 63 (note that it still has only English strings):
54 </p> 64 </p>
65
55 <img src="{{static}}/images/i18n-after-1.gif" 66 <img src="{{static}}/images/i18n-after-1.gif"
56 alt='In the manifest.json file, "Hello World" has been changed to "__MSG_extNam e__", and a new "default_locale" item has the value "en". In the JavaScript file , "Hello World" has been changed to chrome.i18n.getMessage("extName"). A new fil e named _locales/en/messages.json defines "extName".' 67 alt='In the manifest.json file, "Hello World" has been changed to "__MSG_extNam e__", and a new "default_locale" item has the value "en". In the JavaScript file , "Hello World" has been changed to chrome.i18n.getMessage("extName"). A new fil e named _locales/en/messages.json defines "extName".'
57 width="782" height="228"> 68 width="782" height="228">
69
58 <p class="note"> 70 <p class="note">
59 <b>Important:</b> 71 <b>Important:</b>
60 If an extension has a <code>_locales</code> directory, 72 If an extension has a <code>_locales</code> directory,
61 the <a href="manifest.html">manifest</a> 73 the <a href="manifest.html">manifest</a>
62 <b>must</b> define "default_locale". 74 <b>must</b> define "default_locale".
63 </p> 75 </p>
76
64 <p> 77 <p>
65 Some notes about internationalizing extensions: 78 Some notes about internationalizing extensions:
66 </p> 79 </p>
80
67 <ul> 81 <ul>
68 <li><p> 82 <li><p>
69 You can use any of the <a href="#overview-locales">supported locales</a>. 83 You can use any of the <a href="#overview-locales">supported locales</a>.
70 If you use an unsupported locale, 84 If you use an unsupported locale,
71 Google Chrome ignores it. 85 Google Chrome ignores it.
72 </p></li> 86 </p></li>
87
73 <li> 88 <li>
74 In <code>manifest.json</code> 89 In <code>manifest.json</code>
75 and CSS files, 90 and CSS files,
76 refer to a string named <em>messagename</em> like this: 91 refer to a string named <em>messagename</em> like this:
77 <pre>__MSG_<em>messagename</em>__</pre> 92 <pre>__MSG_<em>messagename</em>__</pre>
78 </li> 93 </li>
94
79 <li> 95 <li>
80 In your extension's JavaScript code, 96 In your extension's JavaScript code,
81 refer to a string named <em>messagename</em> 97 refer to a string named <em>messagename</em>
82 like this: 98 like this:
83 <pre>chrome.i18n.getMessage("<em>messagename</em>")</pre> 99 <pre>chrome.i18n.getMessage("<em>messagename</em>")</pre>
100
84 <li> <p> 101 <li> <p>
85 In each call to <code>getMessage()</code>, 102 In each call to <code>getMessage()</code>,
86 you can supply up to 9 strings 103 you can supply up to 9 strings
87 to be included in the message. 104 to be included in the message.
88 See <a href="#examples-getMessage">Examples: getMessage</a> 105 See <a href="#examples-getMessage">Examples: getMessage</a>
89 for details. 106 for details.
90 </p> 107 </p>
91 </li> 108 </li>
109
92 <li><p> 110 <li><p>
93 Some messages, such as <code>@@bidi_dir</code> and <code>@@ui_locale</code>, 111 Some messages, such as <code>@@bidi_dir</code> and <code>@@ui_locale</code>,
94 are provided by the internationalization system. 112 are provided by the internationalization system.
95 See the <a href="#overview-predefined">Predefined messages</a> section 113 See the <a href="#overview-predefined">Predefined messages</a> section
96 for a full list of predefined message names. 114 for a full list of predefined message names.
97 </p> 115 </p>
98 </li> 116 </li>
117
99 <li> 118 <li>
100 In <code>messages.json</code>, 119 In <code>messages.json</code>,
101 each user-visible string has a name, a "message" item, 120 each user-visible string has a name, a "message" item,
102 and an optional "description" item. 121 and an optional "description" item.
103 The name is a key 122 The name is a key
104 such as "extName" or "search_string" 123 such as "extName" or "search_string"
105 that identifies the string. 124 that identifies the string.
106 The "message" specifies 125 The "message" specifies
107 the value of the string in this locale. 126 the value of the string in this locale.
108 The optional "description" 127 The optional "description"
109 provides help to translators, 128 provides help to translators,
110 who might not be able to see how the string is used in your extension. 129 who might not be able to see how the string is used in your extension.
111 For example: 130 For example:
112 <pre> 131 <pre>
113 { 132 {
114 "search_string": { 133 "search_string": {
115 "message": "hello%20world", 134 "message": "hello%20world",
116 "description": "The string we search for. Put %20 between words that go toge ther." 135 "description": "The string we search for. Put %20 between words that go toge ther."
117 }, 136 },
118 ... 137 ...
119 }</pre> 138 }</pre>
139
120 <p> 140 <p>
121 For more information, see 141 For more information, see
122 <a href="i18n-messages.html">Formats: Locale-Specific Messages</a>. 142 <a href="i18n-messages.html">Formats: Locale-Specific Messages</a>.
123 </p> 143 </p>
124 </li> 144 </li>
125 </ul> 145 </ul>
146
126 <p> 147 <p>
127 Once an extension is internationalized, 148 Once an extension is internationalized,
128 translating it is simple. 149 translating it is simple.
129 You copy <code>messages.json</code>, 150 You copy <code>messages.json</code>,
130 translate it, 151 translate it,
131 and put the copy into a new directory under <code>_locales</code>. 152 and put the copy into a new directory under <code>_locales</code>.
132 For example, to support Spanish, 153 For example, to support Spanish,
133 just put a translated copy of <code>messages.json</code> 154 just put a translated copy of <code>messages.json</code>
134 under <code>_locales/es</code>. 155 under <code>_locales/es</code>.
135 The following figure shows the previous extension 156 The following figure shows the previous extension
136 with a new Spanish translation. 157 with a new Spanish translation.
137 </p> 158 </p>
159
138 <img src="{{static}}/images/i18n-after-2.gif" 160 <img src="{{static}}/images/i18n-after-2.gif"
139 alt='This looks the same as the previous figure, but with a new file at _locale s/es/messages.json that contains a Spanish translation of the messages.' 161 alt='This looks the same as the previous figure, but with a new file at _locale s/es/messages.json that contains a Spanish translation of the messages.'
140 width="782" height="358"> 162 width="782" height="358">
163
164
141 <h2 id="overview-predefined">Predefined messages</h2> 165 <h2 id="overview-predefined">Predefined messages</h2>
166
142 <p> 167 <p>
143 The internationalization system provides a few predefined 168 The internationalization system provides a few predefined
144 messages to help you localize your extension. 169 messages to help you localize your extension.
145 These include <code>@@ui_locale</code>, 170 These include <code>@@ui_locale</code>,
146 so you can detect the current UI locale, 171 so you can detect the current UI locale,
147 and a few <code>@@bidi_...</code> messages 172 and a few <code>@@bidi_...</code> messages
148 that let you detect the text direction. 173 that let you detect the text direction.
149 The latter messages have similar names to constants in the 174 The latter messages have similar names to constants in the
150 <a href="http://code.google.com/apis/gadgets/docs/i18n.html#BIDI"> 175 <a href="http://code.google.com/apis/gadgets/docs/i18n.html#BIDI">
151 gadgets BIDI (bi-directional) API</a>. 176 gadgets BIDI (bi-directional) API</a>.
152 </p> 177 </p>
178
153 <p> 179 <p>
154 The special message <code>@@extension_id</code> 180 The special message <code>@@extension_id</code>
155 can be used in the CSS and JavaScript files of any extension, 181 can be used in the CSS and JavaScript files of any extension,
156 whether or not the extension is localized. 182 whether or not the extension is localized.
157 This message doesn't work in manifest files. 183 This message doesn't work in manifest files.
158 </p> 184 </p>
185
159 <p> 186 <p>
160 The following table describes each predefined message. 187 The following table describes each predefined message.
161 </p> 188 </p>
189
162 <table> 190 <table>
163 <tr> 191 <tr>
164 <th>Message name</th> <th>Description</th> 192 <th>Message name</th> <th>Description</th>
165 </tr> 193 </tr>
166 <tr> 194 <tr>
167 <td> <code>@@extension_id</code> </td> 195 <td> <code>@@extension_id</code> </td>
168 <td>The extension ID; 196 <td>The extension ID;
169 you might use this string to construct URLs 197 you might use this string to construct URLs
170 for resources inside the extension. 198 for resources inside the extension.
171 Even unlocalized extensions can use this message. 199 Even unlocalized extensions can use this message.
(...skipping 21 matching lines...) Expand all
193 <td> <code>@@bidi_start_edge</code> </td> 221 <td> <code>@@bidi_start_edge</code> </td>
194 <td> If the <code>@@bidi_dir</code> is "ltr", then this is "left"; 222 <td> If the <code>@@bidi_dir</code> is "ltr", then this is "left";
195 otherwise, it's "right". </td> 223 otherwise, it's "right". </td>
196 </tr> 224 </tr>
197 <tr> 225 <tr>
198 <td> <code>@@bidi_end_edge</code> </td> 226 <td> <code>@@bidi_end_edge</code> </td>
199 <td> If the <code>@@bidi_dir</code> is "ltr", then this is "right"; 227 <td> If the <code>@@bidi_dir</code> is "ltr", then this is "right";
200 otherwise, it's "left". </td> 228 otherwise, it's "left". </td>
201 </tr> 229 </tr>
202 </table> 230 </table>
231
203 <p> 232 <p>
204 Here's an example of using <code>@@extension_id</code> in a CSS file 233 Here's an example of using <code>@@extension_id</code> in a CSS file
205 to construct a URL: 234 to construct a URL:
206 </p> 235 </p>
236
207 <pre> 237 <pre>
208 body { 238 body {
209 <b>background-image:url('chrome-extension://__MSG_@@extension_id__/background. png');</b> 239 <b>background-image:url('chrome-extension://__MSG_@@extension_id__/background. png');</b>
210 } 240 }
211 </pre> 241 </pre>
242
212 <p> 243 <p>
213 If the extension ID is abcdefghijklmnopqrstuvwxyzabcdef, 244 If the extension ID is abcdefghijklmnopqrstuvwxyzabcdef,
214 then the bold line in the previous code snippet becomes: 245 then the bold line in the previous code snippet becomes:
215 </p> 246 </p>
247
216 <pre> 248 <pre>
217 background-image:url('chrome-extension://abcdefghijklmnopqrstuvwxyzabcdef/backgr ound.png'); 249 background-image:url('chrome-extension://abcdefghijklmnopqrstuvwxyzabcdef/backgr ound.png');
218 </pre> 250 </pre>
251
219 <p> 252 <p>
220 Here's an example of using <code>@@bidi_*</code> messages in a CSS file: 253 Here's an example of using <code>@@bidi_*</code> messages in a CSS file:
221 </p> 254 </p>
255
222 <pre> 256 <pre>
223 body { 257 body {
224 <b>direction: __MSG_@@bidi_dir__;</b> 258 <b>direction: __MSG_@@bidi_dir__;</b>
225 } 259 }
260
226 div#header { 261 div#header {
227 margin-bottom: 1.05em; 262 margin-bottom: 1.05em;
228 overflow: hidden; 263 overflow: hidden;
229 padding-bottom: 1.5em; 264 padding-bottom: 1.5em;
230 <b>padding-__MSG_@@bidi_start_edge__: 0;</b> 265 <b>padding-__MSG_@@bidi_start_edge__: 0;</b>
231 <b>padding-__MSG_@@bidi_end_edge__: 1.5em;</b> 266 <b>padding-__MSG_@@bidi_end_edge__: 1.5em;</b>
232 position: relative; 267 position: relative;
233 } 268 }
234 </pre> 269 </pre>
270
235 <p> 271 <p>
236 For left-to-right languages such as English, 272 For left-to-right languages such as English,
237 the bold lines become: 273 the bold lines become:
238 </p> 274 </p>
275
239 <pre> 276 <pre>
240 dir: ltr; 277 dir: ltr;
241 padding-left: 0; 278 padding-left: 0;
242 padding-right: 1.5em; 279 padding-right: 1.5em;
243 </pre> 280 </pre>
281
282
244 <h2 id="overview-locales">Locales</h2> 283 <h2 id="overview-locales">Locales</h2>
284
245 <p> 285 <p>
246 You can choose from many locales, 286 You can choose from many locales,
247 including some (such as <code>en</code>) 287 including some (such as <code>en</code>)
248 that let a single translation support multiple variations of a language 288 that let a single translation support multiple variations of a language
249 (such as <code>en_GB</code> and <code>en_US</code>). 289 (such as <code>en_GB</code> and <code>en_US</code>).
250 </p> 290 </p>
291
292
251 <h3 id="locales-supported">Supported locales</h3> 293 <h3 id="locales-supported">Supported locales</h3>
294
252 <p> 295 <p>
253 Extensions can use any of the 296 Extensions can use any of the
254 <a href="http://code.google.com/chrome/webstore/docs/i18n.html#localeTable">loca les that the Chrome Web Store supports</a>. 297 <a href="http://code.google.com/chrome/webstore/docs/i18n.html#localeTable">loca les that the Chrome Web Store supports</a>.
255 </p> 298 </p>
299
300
256 <h3 id="locales-usage">How extensions find strings</h3> 301 <h3 id="locales-usage">How extensions find strings</h3>
302
257 <p> 303 <p>
258 You don't have to define every string for every locale 304 You don't have to define every string for every locale
259 that your internationalized extension supports. 305 that your internationalized extension supports.
260 As long as the default locale's <code>messages.json</code> file 306 As long as the default locale's <code>messages.json</code> file
261 has a value for every string, 307 has a value for every string,
262 your extension will run no matter how sparse a translation is. 308 your extension will run no matter how sparse a translation is.
263 Here's how the extension system searches for a message: 309 Here's how the extension system searches for a message:
264 </p> 310 </p>
311
265 <ol> 312 <ol>
266 <li> 313 <li>
267 Search the messages file (if any) 314 Search the messages file (if any)
268 for the user's preferred locale. 315 for the user's preferred locale.
269 For example, when Google Chrome's locale is set to 316 For example, when Google Chrome's locale is set to
270 British English (<code>en_GB</code>), 317 British English (<code>en_GB</code>),
271 the system first looks for the message in 318 the system first looks for the message in
272 <code>_locales/en_GB/messages.json</code>. 319 <code>_locales/en_GB/messages.json</code>.
273 If that file exists and the message is there, 320 If that file exists and the message is there,
274 the system looks no further. 321 the system looks no further.
(...skipping 10 matching lines...) Expand all
285 </li> 332 </li>
286 <li> 333 <li>
287 Search the messages file for the extension's default locale. 334 Search the messages file for the extension's default locale.
288 For example, if the extension's "default_locale" is set to "es", 335 For example, if the extension's "default_locale" is set to "es",
289 and neither <code>_locales/en_GB/messages.json</code> 336 and neither <code>_locales/en_GB/messages.json</code>
290 nor <code>_locales/en/messages.json</code> contains the message, 337 nor <code>_locales/en/messages.json</code> contains the message,
291 the extension uses the message from 338 the extension uses the message from
292 <code>_locales/es/messages.json</code>. 339 <code>_locales/es/messages.json</code>.
293 </li> 340 </li>
294 </ol> 341 </ol>
342
295 <p> 343 <p>
296 In the following figure, 344 In the following figure,
297 the message named "colores" is in all three locales 345 the message named "colores" is in all three locales
298 that the extension supports, 346 that the extension supports,
299 but "extName" is in only two of the locales. 347 but "extName" is in only two of the locales.
300 Wherever a user running Google Chrome in US English sees the label "Colors", 348 Wherever a user running Google Chrome in US English sees the label "Colors",
301 a user of British English sees "Colours". 349 a user of British English sees "Colours".
302 Both US English and British English users 350 Both US English and British English users
303 see the extension name "Hello World". 351 see the extension name "Hello World".
304 Because the default language is Spanish, 352 Because the default language is Spanish,
305 users running Google Chrome in any non-English language 353 users running Google Chrome in any non-English language
306 see the label "Colores" and the extension name "Hola mundo". 354 see the label "Colores" and the extension name "Hola mundo".
307 </p> 355 </p>
356
308 <img src="{{static}}/images/i18n-strings.gif" 357 <img src="{{static}}/images/i18n-strings.gif"
309 alt='Four files: manifest.json and three messages.json files (for es, en, and e n_GB). The es and en files show entries for messages named "extName" and "color es"; the en_GB file has just one entry (for "colores").' 358 alt='Four files: manifest.json and three messages.json files (for es, en, and e n_GB). The es and en files show entries for messages named "extName" and "color es"; the en_GB file has just one entry (for "colores").'
310 width="493" height="488" /> 359 width="493" height="488" />
360
311 <h3 id="locales-testing">How to set your browser's locale</h3> 361 <h3 id="locales-testing">How to set your browser's locale</h3>
362
312 <p> 363 <p>
313 To test translations, you might want to set your browser's locale. 364 To test translations, you might want to set your browser's locale.
314 This section tells you how to set the locale in 365 This section tells you how to set the locale in
315 <a href="#testing-win">Windows</a>, 366 <a href="#testing-win">Windows</a>,
316 <a href="#testing-mac">Mac OS X</a>, and 367 <a href="#testing-mac">Mac OS X</a>, and
317 <a href="#testing-linux">Linux</a>. 368 <a href="#testing-linux">Linux</a>.
318 </p> 369 </p>
370
319 <h4 id="testing-win">Windows</h4> 371 <h4 id="testing-win">Windows</h4>
372
320 <p> 373 <p>
321 You can change the locale using either 374 You can change the locale using either
322 a locale-specific shortcut 375 a locale-specific shortcut
323 or the Google Chrome UI. 376 or the Google Chrome UI.
324 The shortcut approach is quicker, once you've set it up, 377 The shortcut approach is quicker, once you've set it up,
325 and it lets you use several languages at once. 378 and it lets you use several languages at once.
326 </p> 379 </p>
380
327 <h5 id="win-shortcut">Using a locale-specific shortcut</h5> 381 <h5 id="win-shortcut">Using a locale-specific shortcut</h5>
382
328 <p> 383 <p>
329 To create and use a shortcut that launches Google Chrome 384 To create and use a shortcut that launches Google Chrome
330 with a particular locale: 385 with a particular locale:
331 </p> 386 </p>
387
332 <ol> 388 <ol>
333 <li> 389 <li>
334 Make a copy of the Google Chrome shortcut 390 Make a copy of the Google Chrome shortcut
335 that's already on your desktop. 391 that's already on your desktop.
336 </li> 392 </li>
337 <li> 393 <li>
338 Rename the new shortcut to match the new locale. 394 Rename the new shortcut to match the new locale.
339 </li> 395 </li>
340 <li> 396 <li>
341 Change the shortcut's properties 397 Change the shortcut's properties
342 so that the Target field specifies the 398 so that the Target field specifies the
343 <code>--lang</code> and 399 <code>--lang</code> and
344 <code>--user-data-dir</code> flags. 400 <code>--user-data-dir</code> flags.
345 The target should look something like this: 401 The target should look something like this:
402
346 <pre><em>path_to_chrome.exe</em> --lang=<em>locale</em> --user-data-dir=c:\<em>l ocale_profile_dir</em></pre> 403 <pre><em>path_to_chrome.exe</em> --lang=<em>locale</em> --user-data-dir=c:\<em>l ocale_profile_dir</em></pre>
347 </li> 404 </li>
405
348 <li> 406 <li>
349 Launch Google Chrome by double-clicking the shortcut. 407 Launch Google Chrome by double-clicking the shortcut.
350 </li> 408 </li>
351 </ol> 409 </ol>
410
352 <p> 411 <p>
353 For example, to create a shortcut 412 For example, to create a shortcut
354 that launches Google Chrome in Spanish (<code>es</code>), 413 that launches Google Chrome in Spanish (<code>es</code>),
355 you might create a shortcut named <code>chrome-es</code> 414 you might create a shortcut named <code>chrome-es</code>
356 that has the following target: 415 that has the following target:
357 </p> 416 </p>
417
358 <pre><em>path_to_chrome.exe</em> --lang=es --user-data-dir=c:\chrome-profile-es< /pre> 418 <pre><em>path_to_chrome.exe</em> --lang=es --user-data-dir=c:\chrome-profile-es< /pre>
419
359 <p> 420 <p>
360 You can create as many shortcuts as you like, 421 You can create as many shortcuts as you like,
361 making it easy to test your extension in multiple languages. 422 making it easy to test your extension in multiple languages.
362 For example: 423 For example:
363 </p> 424 </p>
425
364 <pre><em>path_to_chrome.exe</em> --lang=en --user-data-dir=c:\chrome-profile-en 426 <pre><em>path_to_chrome.exe</em> --lang=en --user-data-dir=c:\chrome-profile-en
365 <em>path_to_chrome.exe</em> --lang=en_GB --user-data-dir=c:\chrome-profile-en_GB 427 <em>path_to_chrome.exe</em> --lang=en_GB --user-data-dir=c:\chrome-profile-en_GB
366 <em>path_to_chrome.exe</em> --lang=ko --user-data-dir=c:\chrome-profile-ko</pre> 428 <em>path_to_chrome.exe</em> --lang=ko --user-data-dir=c:\chrome-profile-ko</pre>
429
367 <p class="note"> 430 <p class="note">
368 <b>Note:</b> 431 <b>Note:</b>
369 Specifying <code>--user-data-dir</code> is optional but handy. 432 Specifying <code>--user-data-dir</code> is optional but handy.
370 Having one data directory per locale 433 Having one data directory per locale
371 lets you run the browser 434 lets you run the browser
372 in several languages at the same time. 435 in several languages at the same time.
373 A disadvantage is that because the locales' data isn't shared, 436 A disadvantage is that because the locales' data isn't shared,
374 you have to install your extension multiple times &mdash; once per locale, 437 you have to install your extension multiple times &mdash; once per locale,
375 which can be challenging when you don't speak the language. 438 which can be challenging when you don't speak the language.
376 For more information, see 439 For more information, see
377 <a href="http://www.chromium.org/developers/creating-and-using-profiles">Creatin g and Using Profiles</a>. 440 <a href="http://www.chromium.org/developers/creating-and-using-profiles">Creatin g and Using Profiles</a>.
378 </p> 441 </p>
442
443
379 <h5 id="win-ui">Using the UI</h5> 444 <h5 id="win-ui">Using the UI</h5>
445
380 <p> 446 <p>
381 Here's how to change the locale using the UI on Google Chrome for Windows: 447 Here's how to change the locale using the UI on Google Chrome for Windows:
382 </p> 448 </p>
449
383 <ol> 450 <ol>
384 <li> Wrench icon > <b>Options</b> </li> 451 <li> Wrench icon > <b>Options</b> </li>
385 <li> Choose the <b>Under the Hood</b> tab </li> 452 <li> Choose the <b>Under the Hood</b> tab </li>
386 <li> Scroll down to <b>Web Content</b> </li> 453 <li> Scroll down to <b>Web Content</b> </li>
387 <li> Click <b>Change font and language settings</b> </li> 454 <li> Click <b>Change font and language settings</b> </li>
388 <li> Choose the <b>Languages</b> tab </li> 455 <li> Choose the <b>Languages</b> tab </li>
389 <li> Use the drop down to set the <b>Google Chrome language</b> </li> 456 <li> Use the drop down to set the <b>Google Chrome language</b> </li>
390 <li> Restart Chrome </li> 457 <li> Restart Chrome </li>
391 </ol> 458 </ol>
459
460
392 <h4 id="testing-mac">Mac OS X</h4> 461 <h4 id="testing-mac">Mac OS X</h4>
462
393 <p> 463 <p>
394 To change the locale on Mac, 464 To change the locale on Mac,
395 you use the system preferences. 465 you use the system preferences.
396 </p> 466 </p>
467
397 <ol> 468 <ol>
398 <li> From the Apple menu, choose <b>System Preferences</b> </li> 469 <li> From the Apple menu, choose <b>System Preferences</b> </li>
399 <li> Under the <b>Personal</b> section, choose <b>International</b> </li> 470 <li> Under the <b>Personal</b> section, choose <b>International</b> </li>
400 <li> Choose your language and location </li> 471 <li> Choose your language and location </li>
401 <li> Restart Chrome </li> 472 <li> Restart Chrome </li>
402 </ol> 473 </ol>
474
475
403 <h4 id="testing-linux">Linux</h4> 476 <h4 id="testing-linux">Linux</h4>
477
404 <p> 478 <p>
405 To change the locale on Linux, 479 To change the locale on Linux,
406 first quit Google Chrome. 480 first quit Google Chrome.
407 Then, all in one line, 481 Then, all in one line,
408 set the LANGUAGE environment variable 482 set the LANGUAGE environment variable
409 and launch Google Chrome. 483 and launch Google Chrome.
410 For example: 484 For example:
411 </p> 485 </p>
486
412 <pre> 487 <pre>
413 LANGUAGE=es ./chrome 488 LANGUAGE=es ./chrome
414 </pre> 489 </pre>
490
491
415 <h2 id="overview-examples">Examples</h2> 492 <h2 id="overview-examples">Examples</h2>
493
416 <p> 494 <p>
417 You can find simple examples of internationalization in the 495 You can find simple examples of internationalization in the
418 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/api/i18n/">examples/api/i18n</a> 496 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/api/i18n/">examples/api/i18n</a>
419 directory. 497 directory.
420 For a complete example, see 498 For a complete example, see
421 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/extensions/news/">examples/extensions/news</a>. 499 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/extensions/news/">examples/extensions/news</a>.
422 For other examples and for help in viewing the source code, see 500 For other examples and for help in viewing the source code, see
423 <a href="samples.html">Samples</a>. 501 <a href="samples.html">Samples</a>.
424 </p> 502 </p>
503
504
425 <h3 id="examples-getMessage">Examples: getMessage</h3> 505 <h3 id="examples-getMessage">Examples: getMessage</h3>
506
426 <!-- 507 <!--
427 [PENDING: improve this section. it should probably start with a 508 [PENDING: improve this section. it should probably start with a
428 one-variable example that includes the messages.json code.] 509 one-variable example that includes the messages.json code.]
429 --> 510 -->
511
430 <p> 512 <p>
431 The following code gets a localized message from the browser 513 The following code gets a localized message from the browser
432 and displays it as a string. 514 and displays it as a string.
433 It replaces two placeholders within the message with the strings 515 It replaces two placeholders within the message with the strings
434 "string1" and "string2". 516 "string1" and "string2".
435 </p> 517 </p>
518
436 <pre> 519 <pre>
437 function getMessage() { 520 function getMessage() {
438 var message = chrome.i18n.getMessage("click_here", ["string1", "string2"]); 521 var message = chrome.i18n.getMessage("click_here", ["string1", "string2"]);
439 document.getElementById("languageSpan").innerHTML = message; 522 document.getElementById("languageSpan").innerHTML = message;
440 } 523 }
441 </pre> 524 </pre>
525
442 <p> 526 <p>
443 Here's how you'd supply and use a single string: 527 Here's how you'd supply and use a single string:
444 </p> 528 </p>
529
445 <pre> 530 <pre>
446 <em>// In JavaScript code</em> 531 <em>// In JavaScript code</em>
447 status.innerText = chrome.i18n.getMessage("error", errorDetails); 532 status.innerText = chrome.i18n.getMessage("error", errorDetails);
533
448 <em>// In messages.json</em> 534 <em>// In messages.json</em>
449 "error": { 535 "error": {
450 "message": "Error: $details$", 536 "message": "Error: $details$",
451 "description": "Generic error template. Expects error parameter to be passed i n.", 537 "description": "Generic error template. Expects error parameter to be passed i n.",
452 "placeholders": { 538 "placeholders": {
453 "details": { 539 "details": {
454 "content": "$1", 540 "content": "$1",
455 "example": "Failed to fetch RSS feed." 541 "example": "Failed to fetch RSS feed."
456 } 542 }
457 } 543 }
458 } 544 }
459 </pre> 545 </pre>
546
460 <p> 547 <p>
461 For more information about placeholders, see the 548 For more information about placeholders, see the
462 <a href="i18n-messages.html">Locale-Specific Messages</a> page. 549 <a href="i18n-messages.html">Locale-Specific Messages</a> page.
463 For details on calling <code>getMessage()</code>, see the 550 For details on calling <code>getMessage()</code>, see the
464 <a href="#method-getMessage">API reference</a>. 551 <a href="#method-getMessage">API reference</a>.
465 </p> 552 </p>
553
466 <h3 id="example-accept-languages">Example: getAcceptLanguages</h3> 554 <h3 id="example-accept-languages">Example: getAcceptLanguages</h3>
467 <p> 555 <p>
468 The following code gets accept-languages from the browser and displays them as a 556 The following code gets accept-languages from the browser and displays them as a
469 string by separating each accept-language with ','. 557 string by separating each accept-language with ','.
470 </p> 558 </p>
559
471 <pre> 560 <pre>
472 function getAcceptLanguages() { 561 function getAcceptLanguages() {
473 chrome.i18n.getAcceptLanguages(function(languageList) { 562 chrome.i18n.getAcceptLanguages(function(languageList) {
474 var languages = languageList.join(","); 563 var languages = languageList.join(",");
475 document.getElementById("languageSpan").innerHTML = languages; 564 document.getElementById("languageSpan").innerHTML = languages;
476 }) 565 })
477 } 566 }
478 </pre> 567 </pre>
568
479 <p> 569 <p>
480 For details on calling <code>getAcceptLanguages()</code>, see the 570 For details on calling <code>getAcceptLanguages()</code>, see the
481 <a href="#method-getAcceptLanguages">API reference</a>. 571 <a href="#method-getAcceptLanguages">API reference</a>.
482 </p> 572 </p>
483 <!-- END AUTHORED CONTENT -->
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698