11export * from './I18NEXT_TOKENS' ;
22export * from './I18NextPipe' ;
33export * from './I18NextCapPipe' ;
4+ export * from './I18NextFormatPipe' ;
45export * from './I18NextService' ;
56export * from './I18NextTitle' ;
67export * from './I18nextNamespaceResolver' ;
@@ -14,6 +15,7 @@ import { I18NEXT_NAMESPACE, I18NEXT_SCOPE, I18NEXT_SERVICE, I18NEXT_NAMESPACE_RE
1415import { I18NextTitle } from './I18NextTitle' ;
1516import { I18NextPipe } from './I18NextPipe' ;
1617import { I18NextCapPipe } from './I18NextCapPipe' ;
18+ import { I18NextFormatPipe } from './I18NextFormatPipe' ;
1719import { I18NextService } from './I18NextService' ;
1820import { ITranslationService } from './ITranslationService' ;
1921import { I18nextNamespaceResolver } from './I18nextNamespaceResolver' ;
@@ -31,15 +33,18 @@ import { I18nextNamespaceResolver } from './I18nextNamespaceResolver';
3133 } ,
3234 I18NextPipe ,
3335 I18NextCapPipe ,
36+ I18NextFormatPipe ,
3437 I18NextTitle
3538 ] ,
3639 declarations : [
3740 I18NextPipe ,
38- I18NextCapPipe
41+ I18NextCapPipe ,
42+ I18NextFormatPipe
3943 ] ,
4044 exports : [
4145 I18NextPipe ,
42- I18NextCapPipe
46+ I18NextCapPipe ,
47+ I18NextFormatPipe
4348 ]
4449} )
4550export class I18NextModule {
@@ -52,6 +57,7 @@ export class I18NextModule {
5257 I18NextService ,
5358 I18NextPipe ,
5459 I18NextCapPipe ,
60+ I18NextFormatPipe ,
5561 I18nextNamespaceResolver
5662 ] ;
5763
@@ -67,4 +73,33 @@ export class I18NextModule {
6773 providers : providers
6874 } ;
6975 }
76+
77+ static interpolationFormat ( customFormat : Function = null ) : Function {
78+ return ( value : string , format : string , lng : string ) : string => {
79+ let formatedValue : string ;
80+ if ( ! value )
81+ formatedValue = value ;
82+ switch ( format ) {
83+ case 'upper' :
84+ case 'uppercase' :
85+ formatedValue = value . toUpperCase ( ) ;
86+ break ;
87+ case 'lower' :
88+ case 'lowercase' :
89+ formatedValue = value . toLowerCase ( ) ;
90+ break ;
91+ case 'cap' :
92+ case 'capitalize' :
93+ formatedValue = value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) ;
94+ break ;
95+ case null :
96+ case 'none' :
97+ default :
98+ formatedValue = value ;
99+ }
100+ if ( customFormat === null )
101+ return formatedValue ;
102+ return customFormat ( formatedValue , format , lng ) ;
103+ } ;
104+ }
70105}
0 commit comments