ngx-simple-i18n
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Ngx-simple-i18n

Simple I18n library for angular, support storage for cache with TTL.

Install:

npm i ngx-simple-i18n --save

Usage:

Import modules:

import {NgxSimpleI18nModule} from 'ngx-simple-i18n';

@NgModule({
  imports: [
    NgxSimpleI18nModule,
  ]
})

Configure:

import {SimpleI18n} from 'ngx-simple-i18n';

class AppComponent implements OnInit {
  constructor(
    private simpleI18n: SimpleI18n,
  ){}
  
  ngOnInit() {
    const zhData = {title: '标题', description: '描述'};
    const enData = {title: 'title', description: 'description'};
    // the callback is usefull for custom data source, return the k/v map object
    this.simpleI18n.setLanguage('zh', async() => zhData, sessionStorage, 60 * 1000);
    this.simpleI18n.setLanguage('en', async() => enData, localStorage, 60 * 1000);
    this.simpleI18n.switchLanguage('zh');
  }
}

Use in template with pipe:

 {{"title" | T}}

the pipe will automatically unsubscribe from the Observable.

Use in component:

import {SimpleI18n} from 'ngx-simple-i18n';

class AppComponent implements OnInit {
  constructor(
    private simpleI18n: SimpleI18n,
  ){}

  ngOnInit() {
    this.simpleI18n.translation$.subscribe(data => {
      console.log(data);
    })
  }
}

Versions

Current Tags

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

Version History

Package Sidebar

Install

npm i ngx-simple-i18n

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

46.6 kB

Total Files

14

Last publish

Collaborators

  • twn39