Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

物件宣告 Sails 多國語系

Posted at 2016-03-28 Sails i18n 

Sails 官方的文件,在於說明多國語系的部分非常簡略,請教 Google 大師之後,發現 Sails 多國語系的底層是使用i18n-node,所以基本 i18n-node 有提供的功能都可以使用。

objectNotation 這個功能預設是 false,所以必須得先設定。

範例

修改多國語系設定檔

1
2
3
4
5
6
7
8
9
// config/i18n.js

module.exports.i18n = {
updateFiles: true,
localesDirectory: '/config/locales',
locales: ['en', 'zh'],
// 加這行
objectNotation: true
}

支援物件式的寫法

1
2
3
4
5
6
7
8
9
10
11
// config/locales/zh.json
{
"admin": {
"common": {
"createdAt": "建立日期",
"publishAt": "發佈日期",
"title": "標題",
"content": "內容",
}
}
}

修改 view 檔

此範例是針對 Jade 的寫法

1
#{i18n('admin.common.createdAt')}

相關連結

  • i18n does not support the objectNotation config option
  • sails i18n

Share 

 Previous post: Jade Mixins Next post: sequelize delete 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo