ngx-i18n
An Angular 4 i18n
基于Angular4的国际化方案
Dependencies
module
imports: I18nModule // or // I18nModule.forRoot()
Component
{ $$I18nServices;} // I18nConfig lang default 'en';
i18n resource
// en.json// {0}, {1}, {name}// 参数替换支持数组和对象 "HELLO_WORLD": "Hello, World!!!" "HELLO_USER": "Hello, {0}!!!" "WELCOME_1": "Welcome {0} back to {1}, {0} last login in {2}" "WELCOME_2": "Welcome {name} back to {site}, {name} last login in {address.province}!!!" "WELCOME_3": "Welcome {name} back to {site}, {name} last login in {address.province} {0}!!!" "WELCOME": "_3": "Welcome {name} back to {site}, {name} last login in {address.province} {0}!!!"
// 对象参数注意必须放在最后一个this$$I18nServices;
Pipe
{{ 'HELLO_WORLD' | i18n }}{{ 'HELLO_USER' | i18n: 'Mizi' }}{{ 'WELCOME_1' | i18n:'Mizi':'i18n' }}{{ 'WELCOME_1' | i18n:['Mizi','i18n'] : 'Shanghai' }}{{ 'WELCOME_2' | i18n: userInfo }}{{ 'WELCOME_3' | i18n: '2017-05-05' : userInfo }}{{ 'WELCOME._3' | i18n: '2017-05-05' : userInfo }}
Directive
HELLO_WORLDHELLO_USERWELCOME_1WELCOME_1WELCOME._3