「ローカライズ」の編集履歴(バックアップ)一覧はこちら

ローカライズ - (2011/02/25 (金) 00:55:03) の最新版との変更点

追加された行は緑色になります。

削除された行は赤色になります。

#contents() *XULのローカライズ localeフォルダにsample.dtdファイルを作成し、実体宣言を行う。 #highlight(xml){ <!ENTITY sample.label "サンプル"> <!ENTITY sample.key "S">} contentフォルダのsample.xulに、dtdファイルの読み込み宣言と実体参照を記述する。 #highlight(xml){ <!DOCTYPE window SYSTEM "chrome://sample/locale/sample.dtd">} #highlight(xul){ <menuitem label="&sample.label;" accesskey="&sample.key;"/>} *JavaScriptのローカライズ(XULを仲介する) localeフォルダにsample.propertiesファイルを用意する。 #highlight(){ SAMPLE = サンプル SAMPLE_REPLACE = 数字%Sと数字%S} XULに以下のように記述。 #highlight(xul){ <stringbundleset id="stringbundleset"> <stringbundle id="strings_sample" src="chrome://sample/locale/sample.properties"/> </stringbundleset>} あとはJavaScript内で以下のように使える。 #highlight(linenumber,javascript){ var strings = document.getElementById("strings_sample"); var text1 = strings.getString("SAMPLE"); // → サンプル var num1 = 1; var num2 = 2; var text2 = strings.getFormattedString("SAMPLE_REPLACE", [num1, num2]); // → 数字1と数字2}
#contents() *XULのローカライズ localeフォルダにsample.dtdファイルを作成し、実体宣言を行う。 #highlight(xml){ <!ENTITY sample.label "サンプル"> <!ENTITY sample.key "S">} contentフォルダのsample.xulに、dtdファイルの読み込み宣言と実体参照を記述する。 #highlight(xml){ <!DOCTYPE window SYSTEM "chrome://sample/locale/sample.dtd">} #highlight(xml){ <menuitem label="&sample.label;" accesskey="&sample.key;"/>} -[[Localization - XUL Tutorial | MDN>https://developer.mozilla.org/en-US/docs/XUL_Tutorial/Localization]] 実体が無いと例外エラーを吐くので注意 *JavaScriptのローカライズ まず、localeフォルダにsample.propertiesファイルを用意する。 #highlight(){ SAMPLE = サンプル SAMPLE_REPLACE_1 = 数字%Sと数字%S SAMPLE_REPLACE_2 = 数字%2$Sと数字%1$S} で、この後だが、XUL、JSM、XPCOM の3つの方法がある。 **XULを仲介する XULに以下のように記述。 #highlight(xml){ <stringbundleset id="stringbundleset"> <stringbundle id="strings_sample" src="chrome://sample/locale/sample.properties"/> </stringbundleset>} あとはJavaScript内で以下のように使える。 #highlight(javascript){ var strings = document.getElementById("strings_sample"); var text1 = strings.getString("SAMPLE"); // → サンプル var num1 = 5; var num2 = 10; var text2 = strings.getFormattedString("SAMPLE_REPLACE_1", [num1, num2]); // → 数字5と数字10 var text3 = strings.getFormattedString("SAMPLE_REPLACE_2", [num1, num2]); // → 数字10と数字5} ローカライズ文字列を取得できないと例外エラーを吐くので注意 -[[Property Files - XUL Tutorial | MDN>https://developer.mozilla.org/en-US/docs/XUL_Tutorial/Property_Files]] -[[stringbundle - XUL | MDN>https://developer.mozilla.org/en-US/docs/XUL/stringbundle]] **JavaScriptコードモジュールを使用 sample.propertiesを用意した後は以下のように使う。 #highlight(javascript){ Components.utils.import("resource://gre/modules/services-common/stringbundle.js"); var strings = new StringBundle("chrome://sample/locale/sample.properties"); var text1 = strings.get("SAMPLE"); // → サンプル var num1 = 5; var num2 = 10; var text2 = strings.get("SAMPLE_REPLACE_1", [num1, num2]); // → 数字5と数字10 var text3 = strings.get("SAMPLE_REPLACE_2", [num1, num2]); // → 数字10と数字5} XULを仲介するより楽な気がする… getStringやgetFormattedStringも使える。 -[[Labs/JS Modules - MozillaWiki>https://wiki.mozilla.org/Labs/JS_Modules#StringBundle]] **XPCOMを直接使う #highlight(javascript){ Components.utils.import("resource://gre/modules/Services.jsm"); var strings = Services.strings.createBundle("chrome://sample/locale/sample.properties"); var text1 = strings.GetStringFromName("SAMPLE"); // → サンプル} -[[nsIStringBundleService - XPCOM Interface Reference | MDN>https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIStringBundleService]] -[[nsIStringBundle - XPCOM Interface Reference | MDN>https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIStringBundle]]

表示オプション

横に並べて表示:
変化行の前後のみ表示: