Updated 18next exists method and added ability to use string interpolation arguments (#16124)

* Updated i18next extists function definition 

and allow for additional interpolation options to be passed as TranslationOptions

* Updated 18next test

* i18next fixed typing of exists key parameter

* i18next Fixed test typo
This commit is contained in:
Jan Klimke
2017-04-26 14:35:57 -07:00
committed by Sheetal Nandi
parent c4077c19e4
commit 8e24694620
2 changed files with 15 additions and 3 deletions
+12 -2
View File
@@ -10,12 +10,14 @@ i18n.init({
resources: {
en: {
translation: {
helloWorld: 'Hello, world!'
helloWorld: 'Hello, world!',
helloWorldInterpolated: 'Hello, {{name}}!'
}
},
ru: {
translation: {
helloWorld: 'Привет, мир!'
helloWorld: 'Привет, мир!',
helloWorldInterpolated: 'Привет, {{name}}!'
}
}
},
@@ -61,6 +63,14 @@ i18n.t('helloWorld', <i18n.TranslationOptions> {
count: 10
});
i18n.t('helloWorldInterpolated', <i18n.TranslationOptions> {
defaultValue: 'default',
count: 10,
name: "world"
});
i18n.exists("helloWorld");
const options:i18n.Options = i18n.options;
const currentLanguage:string = i18n.language;
const userLanguageCodes:string[] = i18n.languages;
+3 -1
View File
@@ -49,6 +49,8 @@ declare namespace i18n {
joinArrays?: string;
postProcess?: string | any[];
interpolation?: InterpolationOptions;
//add an indexer to assure that interpolation arguments can be passed
[x: string]: any;
}
interface Options {
@@ -106,7 +108,7 @@ declare namespace i18n {
t(key: string, options?: TranslationOptions): string | any | Array<any>;
exists(): boolean;
exists(key: string, options?: TranslationOptions): boolean;
setDefaultNamespace(ns: string): void;