1
1
import { Inject , Injectable , Pipe , PipeTransform } from '@angular/core' ;
2
+ import * as i18n from 'i18next' ;
2
3
3
4
import { I18NEXT_NAMESPACE , I18NEXT_SCOPE , I18NEXT_SERVICE } from './I18NEXT_TOKENS' ;
4
5
import { ITranslationService } from './ITranslationService' ;
6
+ import { PipeOptions } from './models' ;
5
7
@Injectable ( )
6
8
@Pipe ( {
7
9
name : 'i18next'
@@ -13,10 +15,10 @@ export class I18NextPipe implements PipeTransform {
13
15
@Inject ( I18NEXT_NAMESPACE ) protected ns : string | string [ ] ,
14
16
@Inject ( I18NEXT_SCOPE ) protected scope : string | string [ ] ) { }
15
17
16
- public transform ( key : string | string [ ] , options ?: any ) : string {
18
+ public transform ( key : string | string [ ] , options ?: PipeOptions ) : string {
17
19
options = this . prepareOptions ( options ) ;
18
20
19
- let i18nOpts = this . translateI18Next . options ;
21
+ let i18nOpts : i18n . TOptions = this . translateI18Next . options ;
20
22
if ( options . prependScope === undefined || options . prependScope === true ) {
21
23
if ( this . scope ) {
22
24
key = this . prependScope ( key , this . scope , i18nOpts . keySeparator , i18nOpts . nsSeparator ) ;
@@ -28,12 +30,8 @@ export class I18NextPipe implements PipeTransform {
28
30
}
29
31
}
30
32
31
- let result : string ;
32
- if ( options . defaultValue ) {
33
- result = this . translateI18Next . t ( key , options . defaultValue , options ) ;
34
- } else {
35
- result = this . translateI18Next . t ( key , options ) ;
36
- }
33
+ let result : string = this . translateI18Next . t ( key , options ) ;
34
+
37
35
if ( options . format ) {
38
36
if ( result ) {
39
37
result = this . translateI18Next
@@ -87,7 +85,7 @@ export class I18NextPipe implements PipeTransform {
87
85
return key . indexOf ( nsSeparator ) !== - 1 ;
88
86
}
89
87
90
- private prepareOptions ( options : any ) {
88
+ private prepareOptions ( options : PipeOptions ) {
91
89
options = options || { } ;
92
90
if ( options . context != null )
93
91
options . context = options . context . toString ( ) ;
0 commit comments