LoginSignup
3
3

More than 5 years have passed since last update.

Sails.js(0.10.x)で多言語対応

Last updated at Posted at 2015-01-14

特に難しい話でもないので簡単にメモ。

実装

i18n(InternationalizatioN)の設定。対応言語をlocalsに配列の形で記述して、defaultLocaleにデフォルトの言語を設定。

/config/locals/i18n.js
module.exports.i18n = {
 locales: ['en', 'ja'],
 defaultLocale: 'en',

 // updateFiles: false,
 // localesDirectory: '/config/locales'
};

/config/locales/以下に書く言語ごとのjsonファイルを設置して変換テーブルを作る。

/config/locales/en.json
{
  "Hello": "Hello"
}
/config/locales/ja.json
{
  "Hello": "こんにちは"
}

Viewで以下のように記述したら終わり。

View/page/start.ejs
<h1><%- __('Hello') %></h1>

テスト

chromeで言語設定を変更する。chromeの設定(URLにchrome://settingsでいける)から詳細設定を表示して「言語」を選択。

2.png

英語を一番上にドラッグして「完了」

3.png

これで英語で表示されるはず。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3