OLD | NEW |
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 | 5 |
6 <p> | 6 <p> |
7 You need to put all of its user-visible strings into a file | 7 You need to put all of its user-visible strings into a file |
8 named <a href="i18n-messages.html"><code>messages.json</code></a>. | 8 named <a href="i18n-messages"><code>messages.json</code></a>. |
9 Each time you add a new locale, | 9 Each time you add a new locale, |
10 you add a messages file | 10 you add a messages file |
11 under a directory | 11 under a directory |
12 named <code>_locales/<em>localeCode</em></code>, | 12 named <code>_locales/<em>localeCode</em></code>, |
13 where <em>localeCode</em> is a code such as | 13 where <em>localeCode</em> is a code such as |
14 <code>en</code> for English. | 14 <code>en</code> for English. |
15 </p> | 15 </p> |
16 | 16 |
17 <p> | 17 <p> |
18 Here's the file hierarchy | 18 Here's the file hierarchy |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 (note that it still has only English strings): | 53 (note that it still has only English strings): |
54 </p> | 54 </p> |
55 | 55 |
56 <img src="{{static}}/images/i18n-after-1.gif" | 56 <img src="{{static}}/images/i18n-after-1.gif" |
57 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 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".' |
58 width="782" height="228"> | 58 width="782" height="228"> |
59 | 59 |
60 <p class="note"> | 60 <p class="note"> |
61 <b>Important:</b> | 61 <b>Important:</b> |
62 If an extension has a <code>_locales</code> directory, | 62 If an extension has a <code>_locales</code> directory, |
63 the <a href="manifest.html">manifest</a> | 63 the <a href="manifest">manifest</a> |
64 <b>must</b> define "default_locale". | 64 <b>must</b> define "default_locale". |
65 </p> | 65 </p> |
66 | 66 |
67 <p> | 67 <p> |
68 Some notes about internationalizing: | 68 Some notes about internationalizing: |
69 </p> | 69 </p> |
70 | 70 |
71 <ul> | 71 <ul> |
72 <li><p> | 72 <li><p> |
73 You can use any of the <a href="#overview-locales">supported locales</a>. | 73 You can use any of the <a href="#overview-locales">supported locales</a>. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 { | 122 { |
123 "search_string": { | 123 "search_string": { |
124 "message": "hello%20world", | 124 "message": "hello%20world", |
125 "description": "The string we search for. Put %20 between words that go toge
ther." | 125 "description": "The string we search for. Put %20 between words that go toge
ther." |
126 }, | 126 }, |
127 ... | 127 ... |
128 }</pre> | 128 }</pre> |
129 | 129 |
130 <p> | 130 <p> |
131 For more information, see | 131 For more information, see |
132 <a href="i18n-messages.html">Formats: Locale-Specific Messages</a>. | 132 <a href="i18n-messages">Formats: Locale-Specific Messages</a>. |
133 </p> | 133 </p> |
134 </li> | 134 </li> |
135 </ul> | 135 </ul> |
136 | 136 |
137 <p> | 137 <p> |
138 Once an extension or app is internationalized, | 138 Once an extension or app is internationalized, |
139 translating it is simple. | 139 translating it is simple. |
140 You copy <code>messages.json</code>, | 140 You copy <code>messages.json</code>, |
141 translate it, | 141 translate it, |
142 and put the copy into a new directory under <code>_locales</code>. | 142 and put the copy into a new directory under <code>_locales</code>. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 480 |
481 <h2 id="overview-examples">Examples</h2> | 481 <h2 id="overview-examples">Examples</h2> |
482 | 482 |
483 <p> | 483 <p> |
484 You can find simple examples of internationalization in the | 484 You can find simple examples of internationalization in the |
485 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/api/i18n/">examples/api/i18n</a> | 485 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/api/i18n/">examples/api/i18n</a> |
486 directory. | 486 directory. |
487 For a complete example, see | 487 For a complete example, see |
488 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/extensions/news/">examples/extensions/news</a>. | 488 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/extensions/news/">examples/extensions/news</a>. |
489 For other examples and for help in viewing the source code, see | 489 For other examples and for help in viewing the source code, see |
490 <a href="samples.html">Samples</a>. | 490 <a href="samples">Samples</a>. |
491 </p> | 491 </p> |
492 | 492 |
493 | 493 |
494 <h3 id="examples-getMessage">Examples: getMessage</h3> | 494 <h3 id="examples-getMessage">Examples: getMessage</h3> |
495 | 495 |
496 <!-- | 496 <!-- |
497 [PENDING: improve this section. it should probably start with a | 497 [PENDING: improve this section. it should probably start with a |
498 one-variable example that includes the messages.json code.] | 498 one-variable example that includes the messages.json code.] |
499 --> | 499 --> |
500 | 500 |
(...skipping 27 matching lines...) Expand all Loading... |
528 "details": { | 528 "details": { |
529 "content": "$1", | 529 "content": "$1", |
530 "example": "Failed to fetch RSS feed." | 530 "example": "Failed to fetch RSS feed." |
531 } | 531 } |
532 } | 532 } |
533 } | 533 } |
534 </pre> | 534 </pre> |
535 | 535 |
536 <p> | 536 <p> |
537 For more information about placeholders, see the | 537 For more information about placeholders, see the |
538 <a href="i18n-messages.html">Locale-Specific Messages</a> page. | 538 <a href="i18n-messages">Locale-Specific Messages</a> page. |
539 For details on calling <code>getMessage()</code>, see the | 539 For details on calling <code>getMessage()</code>, see the |
540 $(ref:i18n.getMessage API reference). | 540 $(ref:i18n.getMessage API reference). |
541 </p> | 541 </p> |
542 | 542 |
543 <h3 id="example-accept-languages">Example: getAcceptLanguages</h3> | 543 <h3 id="example-accept-languages">Example: getAcceptLanguages</h3> |
544 <p> | 544 <p> |
545 The following code gets accept-languages from the browser and displays them as a | 545 The following code gets accept-languages from the browser and displays them as a |
546 string by separating each accept-language with ','. | 546 string by separating each accept-language with ','. |
547 </p> | 547 </p> |
548 | 548 |
549 <pre> | 549 <pre> |
550 function getAcceptLanguages() { | 550 function getAcceptLanguages() { |
551 chrome.i18n.getAcceptLanguages(function(languageList) { | 551 chrome.i18n.getAcceptLanguages(function(languageList) { |
552 var languages = languageList.join(","); | 552 var languages = languageList.join(","); |
553 document.getElementById("languageSpan").innerHTML = languages; | 553 document.getElementById("languageSpan").innerHTML = languages; |
554 }) | 554 }) |
555 } | 555 } |
556 </pre> | 556 </pre> |
557 | 557 |
558 <p> | 558 <p> |
559 For details on calling <code>getAcceptLanguages()</code>, see the | 559 For details on calling <code>getAcceptLanguages()</code>, see the |
560 $(ref:i18n.getAcceptLanguages API reference). | 560 $(ref:i18n.getAcceptLanguages API reference). |
561 </p> | 561 </p> |
OLD | NEW |