From 7aebf649630aab1a319de457c98c97f9f6d689af Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Sun, 24 Jun 2018 01:29:51 +0300 Subject: [PATCH 1/6] The Translations interface can be recursive. --- types/vuex-i18n/index.d.ts | 2 +- types/vuex-i18n/vuex-i18n-tests.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 2332ef4436..0f8a3ac1ea 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -17,7 +17,7 @@ declare module "vue/types/vue" { } export interface Translations { - [key: string]: string; + [key: string]: string | Translations; } export interface Ii18n { diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts index 218bd12ccf..c24be6c70e 100644 --- a/types/vuex-i18n/vuex-i18n-tests.ts +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -23,7 +23,10 @@ Vue.use(vuexI18n.plugin, store); // structured as object trees and will automatically be flattened by the the // plugin const translationsEn = { - content: "This is some {type} content" + content: "This is some {type} content", + tree: { + nested: "This is nested content" + } }; // translations can be kept in separate files for each language From c59225edd921020f1777b014800a70afd1b7ff92 Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Sun, 24 Jun 2018 01:31:10 +0300 Subject: [PATCH 2/6] translateIn supports just two parameters. --- 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 0f8a3ac1ea..92a6e679dd 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -64,7 +64,7 @@ export interface Ii18n { /** * get localized string from store in a given language if available. */ - translateIn(locale: string, key: string, options: any, pluralization?: number): string | undefined; + translateIn(locale: string, key: string, options?: any, pluralization?: number): string | undefined; /** * get localized string from store in a given language if available. From 0b312f74eaeed706edb197e5ea2c7ab42e969b38 Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Sun, 24 Jun 2018 01:45:29 +0300 Subject: [PATCH 3/6] Added example for translateIn call with two arguments. --- types/vuex-i18n/vuex-i18n-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts index c24be6c70e..82d9d864d9 100644 --- a/types/vuex-i18n/vuex-i18n-tests.ts +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -42,3 +42,5 @@ Vue.i18n.add("de", translationsDe); // set the start locale to use Vue.i18n.set("en"); + +Vue.i18n.translateIn("en", "tree.nested"); From d918c54b7cc11fa0a24265b88fb5f726e05545a6 Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Sun, 24 Jun 2018 02:09:13 +0300 Subject: [PATCH 4/6] Updated header. --- types/vuex-i18n/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 92a6e679dd..30124209a1 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for vuex-i18n 1.7 // Project: https://github.com/dkfbasel/vuex-i18n // Definitions by: Cedric Kemp +// Noam Kfir // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 From ad5d4e8ef1eb39f7d5c425f7e8145a0c9b4ddffd Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Mon, 25 Jun 2018 08:51:02 +0300 Subject: [PATCH 5/6] Added locales method to Ii18n interface. --- types/vuex-i18n/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 30124209a1..00caa4863f 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -25,6 +25,9 @@ export interface Ii18n { /** get the current locale */ locale(): string; + /** get all the registered locales */ + locales(): string[]; + /** set the current locale (i.e. 'de', 'en') */ set(locale: string): void; From 5cd54c107a4367d94a6df2d218037a0ea5e4db16 Mon Sep 17 00:00:00 2001 From: Noam Kfir Date: Sat, 30 Jun 2018 16:11:47 +0300 Subject: [PATCH 6/6] options is also optional in translateIn overload with defaultValue. --- 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 00caa4863f..e1f607ef39 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -73,7 +73,7 @@ export interface Ii18n { /** * get localized string from store in a given language if available. */ - translateIn(locale: string, key: string, defaultValue: string, options: any, pluralization?: number): string | undefined; + translateIn(locale: string, key: string, defaultValue: string, options?: any, pluralization?: number): string | undefined; /** * check if the given locale translations are present in the store