This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from panter/features/typescript
feat(typescript): include typescript typings
- Loading branch information
Showing
6 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"javascript.implicitProjectConfig.experimentalDecorators": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { i18n, TranslationFunction, TranslationOptions } from "i18next"; | ||
import Vue, { PluginFunction } from "vue"; | ||
|
||
declare class VueI18Next { | ||
constructor(i18next: i18n, options: VueI18NextOptions); | ||
i18next: i18n; | ||
t: TranslationFunction; | ||
resetVm: ({ }: { i18nLoadedAt: Date }) => void; | ||
i18nLoadedAt: string; | ||
onI18nChanged: () => void; | ||
|
||
static install: PluginFunction<never>; | ||
static version: string; | ||
} | ||
|
||
export interface VueI18NextOptions extends TranslationOptions { | ||
bindI18n?: string; | ||
bindStore?: string; | ||
loadComponentNamespace?: boolean; | ||
} | ||
|
||
export interface VueI18NextComponentOptions { | ||
namespaces?: string | Array<string>; | ||
lng?: string; | ||
keyPrefix?: string; | ||
messages?: { [x: string]: {} }; | ||
} | ||
|
||
declare module "vue/types/options" { | ||
interface ComponentOptions<V extends Vue> { | ||
i18n?: VueI18Next; | ||
i18nOptions?: VueI18NextComponentOptions; | ||
} | ||
} | ||
|
||
declare module "vue/types/vue" { | ||
interface Vue { | ||
readonly $i18n: VueI18Next; | ||
$t: TranslationFunction; | ||
} | ||
} | ||
|
||
export default VueI18Next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Vue, { ComponentOptions } from "vue"; | ||
import * as i18next from "i18next"; | ||
import VueI18Next from "../index"; | ||
import { TranslationFunction } from "i18next"; | ||
import Component from "vue-class-component"; | ||
|
||
/** | ||
* VueI18n.install | ||
*/ | ||
Vue.use(VueI18Next); | ||
VueI18Next.install(Vue); | ||
|
||
VueI18Next.version; // $ExpectType string | ||
|
||
i18next.init({ | ||
lng: "de", | ||
resources: {} | ||
}); | ||
const i18n = new VueI18Next(i18next, {}); | ||
|
||
const vm = new Vue({ | ||
i18n | ||
}); | ||
|
||
vm.$i18n; // $ExpectType VueI18Next | ||
vm.$i18n.i18next; // $ExpectType i18next | ||
vm.$t; // $ExpectType TranslationFunction | ||
|
||
@Component({ | ||
template: "<div><a v-on:click=\"changeLanguage('de')\">DE</a></div>" | ||
}) | ||
class LanguageChangerComponent extends Vue { | ||
changeLanguage(lang: string): void { | ||
this.$i18n.i18next.changeLanguage(lang); | ||
} | ||
} | ||
|
||
new LanguageChangerComponent().changeLanguage("de"); | ||
|
||
Vue.component("app", { | ||
i18nOptions: { namespaces: "common" } | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"experimentalDecorators": true, | ||
"strict": true, | ||
"noEmit": true, | ||
"noImplicitAny": true | ||
}, | ||
"files": ["index.d.ts", "./test/vue-i18next-tests.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ | |
conventional-changelog "0.0.17" | ||
github-url-from-git "^1.4.0" | ||
|
||
"@types/i18next@^8.4.3": | ||
version "8.4.3" | ||
resolved "https://registry.yarnpkg.com/@types/i18next/-/i18next-8.4.3.tgz#9136a9551bf5bf7169aa9f3125c1743f1f8dd6de" | ||
|
||
abbrev@1, [email protected]: | ||
version "1.0.9" | ||
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" | ||
|
@@ -5962,6 +5966,10 @@ typedarray@^0.0.6, typedarray@~0.0.5: | |
version "0.0.6" | ||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" | ||
|
||
typescript@^2.8.3: | ||
version "2.8.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" | ||
|
||
uglify-js@^2.6, uglify-js@^2.8.5: | ||
version "2.8.23" | ||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.23.tgz#8230dd9783371232d62a7821e2cf9a817270a8a0" | ||
|
@@ -6121,6 +6129,10 @@ void-elements@^2.0.0: | |
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" | ||
|
||
vue-class-component@^6.2.0: | ||
version "6.2.0" | ||
resolved "https://registry.yarnpkg.com/vue-class-component/-/vue-class-component-6.2.0.tgz#7adb1daa9a868c75f30f97f33f4f1b94aee62089" | ||
|
||
vue-hot-reload-api@^2.0.1: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz#9ca58a6e0df9078554ce1708688b6578754d86de" | ||
|
@@ -6159,9 +6171,9 @@ vue-template-es2015-compiler@^1.2.2: | |
version "1.5.2" | ||
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.2.tgz#a0a6c50c941d2a4abda963f2f42c337ac450ee95" | ||
|
||
vue@^2.2.0: | ||
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/vue/-/vue-2.3.2.tgz#9e52aae3593480be235ff227557837e69f98203a" | ||
vue@^2.4.0: | ||
version "2.5.16" | ||
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085" | ||
|
||
walk@^2.3.9: | ||
version "2.3.9" | ||
|