javascriptで国際化(多言語対応)
i18nのためのjqueryプラグインを使いました。
jQuery.i18n.properties
まず、リソースファイルを準備します。
Messages.properties
# This line is ignored by the plugin MSG_HELLO = Hello MSG_COMPLEX = Hey, {0}
Messages_ja.properties
# This line is ignored by the plugin MSG_HELLO = こんにちわ MSG_COMPLEX = やあ、{0}
リソースファイルは /i18n/におきました。
HTMLのヘッダに、これをお忘れなく。
<script src="/js/jquery-1.5.1.min.js" type="text/javascript"></script> <script src="/js/jquery.i18n.properties.js" type="text/javascript"></script>
javascriptはこんな感じ。
jQuery.i18n.properties({ name: 'Messages', path:'/i18n/', mode:'both' callback: function() { alert(MSG_HELLO); alert(MSG_COMPLEX('John')); } });
何気にすごい便利なんだけど、日本語の情報が少ないのは、ほかにいいものがあるからかな?