@sex-pomelo/pomelo-i18n
v0.0.3
Published
sex pomelo i18n plugin
Downloads
3
Readme
pomelo-i18n
Pomelo i18n plugin.
How To
Locale file directory
You Set path param, set locale file path.
+ app
+ config
+ locale // << default path Locale file is here
- en-US.js
- zh-CN.js
file
// locale/zh-CN.js
module.exports = {
Email: '邮箱',
'Welcome back, %s!': '欢迎回来,%s!',
'Hello {0}! My name is {1}.': '你好 {0}! 我的名字叫 {1}。',
};
Use plugin
Register plugin to pomelo
const i18n = require('@sex-pomelo/pomelo-i18n');
...
app.configure('production|development' ,'!master',function() {
app.use(i18n,{
i18n:{
path: 'app/locale', // set locale path,optional, default <root>/locale
locale: ['en-US','zh-CN'], // use locale, optional
default: 'en-US', // default locale, required
localeFiledName: 'lang' // session locale attribute name
}
});
});
...
Use
- If texts contain format function like
%s
,%j
, we can call by the way similar toutil.format()
. - Support array, subscript and placeholder
- Support from cli session read locale language, you can custom session locale filed name by
localeFiledName
.
app.tr('SystemBusy');
app.tr1('en-US', 'SystemBusy');
app.tr('Welcome back, %s!', 'Shawn');
app.tr('Hello {0}! My name is {1}.', ['foo', 'bar']);
app.tr1('zh-CN','Hello {0}! My name is {1}.', ['foo', 'bar']);
app.tr1(session,'Hello {0}! My name is {1}.', ['foo', 'bar']);
API
tr
app.tr( msgkey, ...);
- msgKey, String, key define in .js
- ..., Other param
tr1
app.tr1( lang|session, msgKey, ... );
- lang, String, locale String
- session, The client session, client should set session language field
- msgKey, String, key define in .js
- ..., Other param