From 6009b7e8bd6dae6a1b64a6e1e353971ba9edb415 Mon Sep 17 00:00:00 2001 From: barahliush Date: Sun, 28 Oct 2018 15:25:09 +0200 Subject: [PATCH 1/5] added interface for i18n plugin in store, updated signature in method "keyExists" --- types/vuex-i18n/index.d.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index e1f607ef39..2c8c280e2f 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for vuex-i18n 1.7 +// Type definitions for vuex-i18n 1.10 // Project: https://github.com/dkfbasel/vuex-i18n // Definitions by: Cedric Kemp // Noam Kfir +// Suleimanov Artem // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.9 import _Vue, { PluginObject } from "vue"; @@ -17,6 +18,14 @@ declare module "vue/types/vue" { } } +export interface i18nState { + fallback: string; + locale: string; + translations: { + [key: string]: Translations; + }; +} + export interface Translations { [key: string]: string | Translations; } @@ -81,9 +90,14 @@ export interface Ii18n { localeExists(locale: string): boolean; /** - * check if the given key is available in the current or fallback locale + * check if the given key is available + * optional with a second parameter to limit the scope + * strict: only current locale (exact match) + * locale: current locale and parent language locale (i.e. en-us & en) + * fallback: current locale, parent language locale and fallback locale + * the default is fallback */ - keyExists(key: string): boolean; + keyExists(key: string, mode?: string): boolean; } declare const _default: { From 988a8af2422524f5eef7fb31278cb9efbe1c3af8 Mon Sep 17 00:00:00 2001 From: barahliush Date: Sun, 28 Oct 2018 15:40:43 +0200 Subject: [PATCH 2/5] added test for store's module interface --- types/vuex-i18n/vuex-i18n-tests.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts index 82d9d864d9..11010df30b 100644 --- a/types/vuex-i18n/vuex-i18n-tests.ts +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -3,11 +3,16 @@ import Vue from "vue"; import { Store } from "vuex"; // load vuex i18n module -import vuexI18n from "vuex-i18n"; +import vuexI18n, { i18nState } from "vuex-i18n"; + +// declare interface for store's root state +interface RootState { + i18n: i18nState; +} // initialize the vuex store using the vuex module. note that you can change the -// name of the module if you wish -const store = new Store({}); +// name of the module if you wish +const store = new Store({}); // initialize the internationalization plugin on the vue instance. note that // the store must be passed to the plugin. the plugin will then generate some From 7015d5fc5b753310a5a34c37b79381fd4fc73c5c Mon Sep 17 00:00:00 2001 From: barahliush Date: Sun, 28 Oct 2018 16:00:55 +0200 Subject: [PATCH 3/5] fixed types in store's state --- types/vuex-i18n/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 2c8c280e2f..d2c5f60b08 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -19,8 +19,8 @@ declare module "vue/types/vue" { } export interface i18nState { - fallback: string; - locale: string; + fallback: string | null; + locale: string | null; translations: { [key: string]: Translations; }; From 9be14bb68c2b862206317cb4bd7e867786cbb4a6 Mon Sep 17 00:00:00 2001 From: barahliush Date: Sun, 28 Oct 2018 19:31:36 +0200 Subject: [PATCH 4/5] update signature for method "locale" --- types/vuex-i18n/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index d2c5f60b08..8282b99c05 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -32,7 +32,7 @@ export interface Translations { export interface Ii18n { /** get the current locale */ - locale(): string; + locale(): string | null; /** get all the registered locales */ locales(): string[]; From 2d2409cf47b72760289c8a5756bc61c83f0bb85a Mon Sep 17 00:00:00 2001 From: barahliush Date: Tue, 6 Nov 2018 10:39:51 +0200 Subject: [PATCH 5/5] Parameter 'mode' in method 'key Exists' has been renamed to 'scope' --- types/vuex-i18n/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 8282b99c05..f6b75afa1a 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -97,7 +97,7 @@ export interface Ii18n { * fallback: current locale, parent language locale and fallback locale * the default is fallback */ - keyExists(key: string, mode?: string): boolean; + keyExists(key: string, scope?: string): boolean; } declare const _default: {