- contentフォルダの兄弟にlocaleフォルダを作り、子フォルダにja-JPとたとえばen-USを作りそこにsample.dtdとsample.propatiesを置く。
- XUL
- DTDを使う。DTDの中は以下のENTITYをひたすら書く。
<!ENTITY sample.identifier "localize string">
- xulの中でつかうときは先頭のほうに以下を書いて、&sample.identifier;と書くことで展開される。
<!DOCTYPE overlay SYSTEM "chrome://sample/locale/sample.dtd">
- DTDを使う。DTDの中は以下のENTITYをひたすら書く。
- JS
- スクリプトのリテラルを国際化したいときはstringbundleをつかう。
- dtdと同じフォルダにsample.propertiesを作り、中に以下のような代入文をひたすら書く
sample.identifier2=test
- propatyには日本語がかけないので以下でescape-unicode変換する。
- http://homepage3.nifty.com/chado/playjs/mojicode/mojicode.htm
- Firefox2ではUTF-8で書いておけばOk
- xulには以下を書いて、JSがdocument.getElementByIdできる要素の子要素(toolbarなど)に置く
<stringbundle id="sample_string_bundle" src="chrome://sample/locale/sample.properties"/>
- jsからは以下のように使う
document.getElementById( "sample_string_bundle" ).getString("sample.identifier2") - sample.propatiesで%nSという記法を使うことで、フォーマット機能を使うことができる。
- 以下のように
sample.identifier3=%2S is %1S
- とすると
"B is A" == document.getElementById( "sample_string_bundle" ).getFormattedString("sample.identifier3", ["A", "B"]) - となる。
- 以下のように
- ロケールを一時的に変更してテストするにはabout:configでgeneral.useragent.localeの値を変えて再起動。
- XUL