1.0.2 • Published 2 years ago

ngx-simple-i18n v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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);
    })
  }
}
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago