From e54bbf3cdaa27e8908a05d205b95cc69529f8c15 Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 01:29:52 -0400 Subject: [PATCH 1/9] Adding typings for vex-i18n --- types/vuex-i18n/index.d.ts | 64 ++++++++++++++++++++++++++++ types/vuex-i18n/package.json | 5 +++ types/vuex-i18n/tsconfig.json | 26 ++++++++++++ types/vuex-i18n/tslint.json | 79 +++++++++++++++++++++++++++++++++++ types/vuex-i18n/vue.d.ts | 21 ++++++++++ 5 files changed, 195 insertions(+) create mode 100644 types/vuex-i18n/index.d.ts create mode 100644 types/vuex-i18n/package.json create mode 100644 types/vuex-i18n/tsconfig.json create mode 100644 types/vuex-i18n/tslint.json create mode 100644 types/vuex-i18n/vue.d.ts diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts new file mode 100644 index 0000000000..dc79a847ff --- /dev/null +++ b/types/vuex-i18n/index.d.ts @@ -0,0 +1,64 @@ +// Type definitions for vuex-i18n 1.7.0 +// Project: https://github.com/dkfbasel/vuex-i18n +// Definitions by: Cedric Kemp +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// TypeScript Version: 2.3 + +import _Vue, { PluginObject } from "vue"; + +// augment typings of Vue.js +import "./vue"; + +export declare interface ITranslations { + [key: string]: string +} + +export declare interface Ii18n { + /** get the current locale */ + locale(): string + + /** set the current locale (i.e. 'de', 'en') */ + set(locale: string): void + + /** add locale translation to the storage. this will extend existing information + (i.e. 'de', {'message': 'Eine Nachricht'}) */ + add(locale: string, translations: ITranslations): void + + /** replace locale translations in the storage. this will remove all previous + locale information for the specified locale */ + replace(locale: string, translations: ITranslations): void + + /** remove the given locale from the store */ + remove(locale: string): void + + /** set a fallback locale if translation for current locale does not exist */ + fallback(locale: string): void + + /** get localized string from store. note that we pass the arguments passed + to the function directly to the translateInLanguage function */ + translate(key: string, options: any, pluralization?: number): string | undefined + + /** get localized string from store. note that we pass the arguments passed + to the function directly to the translateInLanguage function */ + translate(key: string, defaultValue: string, options: any, pluralization?: number): string | undefined + + /** get localized string from store in a given language if available. + * get localized string from store in a given language if available. + */ + translateIn(locale: string, key: string, options: any, pluralization?: number): string | undefined + + /** get localized string from store in a given language if available. + * get localized string from store in a given language if available. + */ + translateIn(locale: string, key: string, defaultValue: string, options: any, pluralization?: number): string | undefined + + /** check if the given locale translations are present in the store */ + localeExists(locale: string): boolean + + /** check if the given key is available in the current or fallback locale */ + keyExists(key: string): boolean +} + +declare module 'vuex-i18n' { + const plugin: PluginObject +} diff --git a/types/vuex-i18n/package.json b/types/vuex-i18n/package.json new file mode 100644 index 0000000000..acec5c3904 --- /dev/null +++ b/types/vuex-i18n/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "vue": ">=2.0.0" + } +} diff --git a/types/vuex-i18n/tsconfig.json b/types/vuex-i18n/tsconfig.json new file mode 100644 index 0000000000..22d8f832eb --- /dev/null +++ b/types/vuex-i18n/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "lib": [ + "es5", + "es2015" + ], + "types": [], + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "noEmit": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "forceConsistentCasingInFileNames": true, + "version": 2.3 + }, + "files": [ + "index.d.ts", + "vue.d.ts" + ] +} \ No newline at end of file diff --git a/types/vuex-i18n/tslint.json b/types/vuex-i18n/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/vuex-i18n/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} diff --git a/types/vuex-i18n/vue.d.ts b/types/vuex-i18n/vue.d.ts new file mode 100644 index 0000000000..f20b24462d --- /dev/null +++ b/types/vuex-i18n/vue.d.ts @@ -0,0 +1,21 @@ +// Type definitions for vuex-i18n 1.7.0 +// Project: https://github.com/dkfbasel/vuex-i18n +// Definitions by: Cedric Kemp +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// TypeScript Version: 2.3 + +/** + * Extends interfaces in Vue.js + */ +import Vue from "vue"; +import { Ii18n } from "./index"; + +declare module "vue/types/vue" { + interface Vue { + $i18n: Ii18n; + } + + interface VueConstructor { + i18n: Ii18n; + } +} From 3f5fbd114126564f264bc5318e73b6586525c19a Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 01:39:21 -0400 Subject: [PATCH 2/9] Set private: true in package.json --- types/vuex-i18n/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/vuex-i18n/package.json b/types/vuex-i18n/package.json index acec5c3904..faefc1b2f7 100644 --- a/types/vuex-i18n/package.json +++ b/types/vuex-i18n/package.json @@ -1,4 +1,5 @@ { + "private": true, "dependencies": { "vue": ">=2.0.0" } From 465a9b2f96db93e18a419624dfeafb10a4dbce1b Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 01:44:34 -0400 Subject: [PATCH 3/9] Removed invalid compiler option --- types/vuex-i18n/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/vuex-i18n/tsconfig.json b/types/vuex-i18n/tsconfig.json index 22d8f832eb..27957ff7ee 100644 --- a/types/vuex-i18n/tsconfig.json +++ b/types/vuex-i18n/tsconfig.json @@ -16,8 +16,7 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, - "forceConsistentCasingInFileNames": true, - "version": 2.3 + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", From 0d6c58f145c8141a4bba15476f18b9d7639a7ed7 Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 09:20:48 -0400 Subject: [PATCH 4/9] Removed rules from tslint.json --- types/vuex-i18n/tslint.json | 78 +------------------------------------ 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/types/vuex-i18n/tslint.json b/types/vuex-i18n/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/vuex-i18n/tslint.json +++ b/types/vuex-i18n/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From fea50ed89a97a1016879abb75dd5e2281c97f833 Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 11:29:11 -0400 Subject: [PATCH 5/9] Fixed linter issues --- types/vuex-i18n/index.d.ts | 92 ++++++++++++++++++++++---------------- types/vuex-i18n/vue.d.ts | 6 --- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index dc79a847ff..f20772b9bd 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for vuex-i18n 1.7.0 +// Type definitions for vuex-i18n 1.7 // Project: https://github.com/dkfbasel/vuex-i18n // Definitions by: Cedric Kemp // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -9,56 +9,72 @@ import _Vue, { PluginObject } from "vue"; // augment typings of Vue.js import "./vue"; -export declare interface ITranslations { - [key: string]: string -} +export interface Translations { + [key: string]: string; +} -export declare interface Ii18n { +export interface Ii18n { /** get the current locale */ - locale(): string + locale(): string; /** set the current locale (i.e. 'de', 'en') */ - set(locale: string): void + set(locale: string): void; - /** add locale translation to the storage. this will extend existing information - (i.e. 'de', {'message': 'Eine Nachricht'}) */ - add(locale: string, translations: ITranslations): void + /** + * add locale translation to the storage. this will extend existing information + * (i.e. 'de', {'message': 'Eine Nachricht'}) + */ + add(locale: string, translations: Translations): void; - /** replace locale translations in the storage. this will remove all previous - locale information for the specified locale */ - replace(locale: string, translations: ITranslations): void + /** + * replace locale translations in the storage. this will remove all previous + * locale information for the specified locale + */ + replace(locale: string, translations: Translations): void; - /** remove the given locale from the store */ - remove(locale: string): void + /** + * remove the given locale from the store + */ + remove(locale: string): void; - /** set a fallback locale if translation for current locale does not exist */ - fallback(locale: string): void + /** + * set a fallback locale if translation for current locale does not exist + */ + fallback(locale: string): void; - /** get localized string from store. note that we pass the arguments passed - to the function directly to the translateInLanguage function */ - translate(key: string, options: any, pluralization?: number): string | undefined + /** + * get localized string from store. note that we pass the arguments passed + * to the function directly to the translateInLanguage function + */ + translate(key: string, options: any, pluralization?: number): string | undefined; - /** get localized string from store. note that we pass the arguments passed - to the function directly to the translateInLanguage function */ - translate(key: string, defaultValue: string, options: any, pluralization?: number): string | undefined + /** + * get localized string from store. note that we pass the arguments passed + * to the function directly to the translateInLanguage function + */ + translate(key: string, defaultValue: string, options: any, pluralization?: number): string | undefined; - /** get localized string from store in a given language if available. - * get localized string from store in a given language if available. - */ - translateIn(locale: string, key: string, options: any, pluralization?: number): string | undefined + /** + * get localized string from store in a given language if available. + * get localized string from store in a given language if available. + */ + translateIn(locale: string, key: string, options: any, pluralization?: number): string | undefined; - /** get localized string from store in a given language if available. - * get localized string from store in a given language if available. - */ - translateIn(locale: string, key: string, defaultValue: string, options: any, pluralization?: number): string | undefined + /** + * get localized string from store in a given language if available. + * get localized string from store in a given language if available. + */ + translateIn(locale: string, key: string, defaultValue: string, options: any, pluralization?: number): string | undefined; - /** check if the given locale translations are present in the store */ - localeExists(locale: string): boolean + /** + * check if the given locale translations are present in the store + */ + localeExists(locale: string): boolean; - /** check if the given key is available in the current or fallback locale */ - keyExists(key: string): boolean + /** + * check if the given key is available in the current or fallback locale + */ + keyExists(key: string): boolean; } -declare module 'vuex-i18n' { - const plugin: PluginObject -} +export const plugin: PluginObject; diff --git a/types/vuex-i18n/vue.d.ts b/types/vuex-i18n/vue.d.ts index f20b24462d..f88cff8dc0 100644 --- a/types/vuex-i18n/vue.d.ts +++ b/types/vuex-i18n/vue.d.ts @@ -1,9 +1,3 @@ -// Type definitions for vuex-i18n 1.7.0 -// Project: https://github.com/dkfbasel/vuex-i18n -// Definitions by: Cedric Kemp -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// TypeScript Version: 2.3 - /** * Extends interfaces in Vue.js */ From 244b60c9170b1c2a11ae73f06b86a3e8a30df65f Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 11:49:35 -0400 Subject: [PATCH 6/9] Fixed duplicated commet --- types/vuex-i18n/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index f20772b9bd..52f56d45a5 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -55,13 +55,11 @@ export interface Ii18n { translate(key: string, defaultValue: string, options: any, pluralization?: number): string | undefined; /** - * get localized string from store in a given language if available. * get localized string from store in a given language if available. */ translateIn(locale: string, key: string, options: any, pluralization?: number): string | undefined; /** - * get localized string from store in a given language if available. * get localized string from store in a given language if available. */ translateIn(locale: string, key: string, defaultValue: string, options: any, pluralization?: number): string | undefined; From f90b634d7682476369327135fcbd5dacf1246af2 Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 14:47:14 -0400 Subject: [PATCH 7/9] Added test file and vuex dependency --- types/vuex-i18n/index.d.ts | 6 ++++- types/vuex-i18n/package.json | 3 ++- types/vuex-i18n/tsconfig.json | 3 ++- types/vuex-i18n/vuex-i18n-tests.ts | 41 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 types/vuex-i18n/vuex-i18n-tests.ts diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index 52f56d45a5..011e6d50ef 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -75,4 +75,8 @@ export interface Ii18n { keyExists(key: string): boolean; } -export const plugin: PluginObject; +declare const _default: { + plugin: PluginObject; +}; + +export default _default; diff --git a/types/vuex-i18n/package.json b/types/vuex-i18n/package.json index faefc1b2f7..f180048358 100644 --- a/types/vuex-i18n/package.json +++ b/types/vuex-i18n/package.json @@ -1,6 +1,7 @@ { "private": true, "dependencies": { - "vue": ">=2.0.0" + "vue": ">=2.0.0", + "vuex": ">=2.0.0" } } diff --git a/types/vuex-i18n/tsconfig.json b/types/vuex-i18n/tsconfig.json index 27957ff7ee..0d820b060e 100644 --- a/types/vuex-i18n/tsconfig.json +++ b/types/vuex-i18n/tsconfig.json @@ -20,6 +20,7 @@ }, "files": [ "index.d.ts", - "vue.d.ts" + "vue.d.ts", + "vuex-i18n-tests.ts" ] } \ No newline at end of file diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts new file mode 100644 index 0000000000..0046d17b22 --- /dev/null +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -0,0 +1,41 @@ +// load vue and vuex instance +import Vue from 'vue'; +import { Store } from 'vuex'; + +// load vuex i18n module +import vuexI18n from 'vuex-i18n'; + +// 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({}); + +// initialize the internationalization plugin on the vue instance. note that +// the store must be passed to the plugin. the plugin will then generate some +// helper functions for components (i.e. this.$i18n.set, this.$t) and on the vue +// instance (i.e. Vue.i18n.set). +Vue.use(vuexI18n.plugin, store); + +// please note that you must specify the name of the vuex module if it is +// different from i18n. i.e. Vue.use(vuexI18n.plugin, store, 'myName') + +// add some translations (could also be loaded from a separate file) +// note that it is possible to use placeholders. translations can also be +// structured as object trees and will automatically be flattened by the the +// plugin +const translationsEn = { + content: "This is some {type} content" +}; + +// translations can be kept in separate files for each language +// i.e. resources/i18n/de.json. +const translationsDe = { + "My nice title": "Ein schöner Titel", + content: "Dies ist ein toller Inhalt" +}; + +// add translations directly to the application +Vue.i18n.add('en', translationsEn); +Vue.i18n.add('de', translationsDe); + +// set the start locale to use +Vue.i18n.set('en'); From b22c579a73cb9f1553efd65e5199654cda230a6f Mon Sep 17 00:00:00 2001 From: Cedric Kemp Date: Tue, 31 Oct 2017 14:49:15 -0400 Subject: [PATCH 8/9] Normalized strings syntax --- types/vuex-i18n/vuex-i18n-tests.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts index 0046d17b22..218bd12ccf 100644 --- a/types/vuex-i18n/vuex-i18n-tests.ts +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -1,9 +1,9 @@ // load vue and vuex instance -import Vue from 'vue'; -import { Store } from 'vuex'; +import Vue from "vue"; +import { Store } from "vuex"; // load vuex i18n module -import vuexI18n from 'vuex-i18n'; +import vuexI18n from "vuex-i18n"; // initialize the vuex store using the vuex module. note that you can change the // name of the module if you wish @@ -16,7 +16,7 @@ const store = new Store({}); Vue.use(vuexI18n.plugin, store); // please note that you must specify the name of the vuex module if it is -// different from i18n. i.e. Vue.use(vuexI18n.plugin, store, 'myName') +// different from i18n. i.e. Vue.use(vuexI18n.plugin, store, "myName") // add some translations (could also be loaded from a separate file) // note that it is possible to use placeholders. translations can also be @@ -34,8 +34,8 @@ const translationsDe = { }; // add translations directly to the application -Vue.i18n.add('en', translationsEn); -Vue.i18n.add('de', translationsDe); +Vue.i18n.add("en", translationsEn); +Vue.i18n.add("de", translationsDe); // set the start locale to use -Vue.i18n.set('en'); +Vue.i18n.set("en"); From c870d67fe9ca282ad6bedf36c270f962fcb87a5d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 7 Nov 2017 10:43:04 -0800 Subject: [PATCH 9/9] slash-slash-slash -> slash-slash --- 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 011e6d50ef..82f57ff53a 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/dkfbasel/vuex-i18n // Definitions by: Cedric Kemp // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// TypeScript Version: 2.3 +// TypeScript Version: 2.3 import _Vue, { PluginObject } from "vue";