From 8e246946208180a7e91c4e37f70894e807c39e8c Mon Sep 17 00:00:00 2001 From: Jan Klimke Date: Wed, 26 Apr 2017 23:35:57 +0200 Subject: [PATCH] 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 --- types/i18next/i18next-tests.ts | 14 ++++++++++++-- types/i18next/index.d.ts | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/types/i18next/i18next-tests.ts b/types/i18next/i18next-tests.ts index 23c67cc742..e51f2f495c 100644 --- a/types/i18next/i18next-tests.ts +++ b/types/i18next/i18next-tests.ts @@ -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', { count: 10 }); +i18n.t('helloWorldInterpolated', { + 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; diff --git a/types/i18next/index.d.ts b/types/i18next/index.d.ts index 958bff12a6..ee06d8d18c 100644 --- a/types/i18next/index.d.ts +++ b/types/i18next/index.d.ts @@ -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; - exists(): boolean; + exists(key: string, options?: TranslationOptions): boolean; setDefaultNamespace(ns: string): void;