From 97a4f36d64639fecd8b3e0c0eb527a7378e7ca87 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Tue, 16 Sep 2014 12:19:41 +0300 Subject: [PATCH] Add exists function to i18next --- i18next/i18next-tests.ts | 19 ++++++++++++++++++- i18next/i18next.d.ts | 7 ++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/i18next/i18next-tests.ts b/i18next/i18next-tests.ts index f40d10b3a..b1732de11 100644 --- a/i18next/i18next-tests.ts +++ b/i18next/i18next-tests.ts @@ -6,7 +6,7 @@ /// declare function done(): void; - + describe('i18next', function () { var i18n = $.i18n @@ -685,6 +685,23 @@ describe('i18next', function () { }); }); + describe('exists functionality', function () { + var resStore = { + dev: { translation: { empty: '' } }, + en: { translation: {} }, + 'en-US': { translation: {} } + }; + + beforeEach(function (done) { + i18n.init($.extend(opts, { resStore: resStore }), + function (t) { done(); }); + }); + + it('it should be able to test if a key exists', function () { + expect(i18n.exists('empty')).to.be(false); + }); + }); + describe('resource string as array', function () { var resStore = { dev: { translation: { testarray: ["title", "text"] } }, diff --git a/i18next/i18next.d.ts b/i18next/i18next.d.ts index e9083c4d5..54bd439f4 100644 --- a/i18next/i18next.d.ts +++ b/i18next/i18next.d.ts @@ -109,6 +109,7 @@ interface I18nextStatic { }; t(key: string, options?: any): string; translate(key: string, options?: any): string; + exists(key: string, options?: any): boolean; } // jQuery extensions @@ -118,9 +119,9 @@ interface JQueryStatic { } interface JQuery { - /* Note: options are same options as used by the translate function. Alternatively by - setting init option or translation option 'useDataAttrOptions = true' the Options - for translation will be read and cached in the elements data-i18n-options attribute. + /* Note: options are same options as used by the translate function. Alternatively by + setting init option or translation option 'useDataAttrOptions = true' the Options + for translation will be read and cached in the elements data-i18n-options attribute. */ i18n: (options?: I18nextOptions) => void; }