@sex-pomelo/pomelo-i18n

0.0.3 • Public • Published

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 to util.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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    0
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i @sex-pomelo/pomelo-i18n

Weekly Downloads

0

Version

0.0.3

License

none

Unpacked Size

41 kB

Total Files

5

Last publish

Collaborators

  • shudingbo