-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
1,329 additions
and
882 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
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,74 @@ | ||
import * as Vue from 'vue'; | ||
import { PluginFunction } from 'vue'; | ||
|
||
declare namespace VueI18n { | ||
type Path = string; | ||
type Locale = string; | ||
type Values = any[] | { [key: string]: any }; | ||
type Choice = number; | ||
type LocaleMessage = string | LocaleMessageObject | LocaleMessageArray; | ||
interface LocaleMessageObject { [key: string]: LocaleMessage; } | ||
interface LocaleMessageArray { [index: number]: LocaleMessage; } | ||
interface LocaleMessages { [key: string]: LocaleMessageObject; } | ||
type TranslateResult = string | LocaleMessageArray; | ||
|
||
interface Formatter { | ||
format(message: string, values: Values): string; | ||
} | ||
|
||
type MissingHandler = (locale: Locale, key: Path, vm?: Vue) => void; | ||
|
||
// tslint:disable-next-line:interface-name | ||
interface I18nOptions { | ||
locale?: Locale; | ||
fallbackLocale?: Locale; | ||
messages?: LocaleMessages; | ||
formatter?: Formatter; | ||
missing?: MissingHandler; | ||
fallbackRoot?: boolean; | ||
sync?: boolean; | ||
silentTranslationWarn?: boolean; | ||
} | ||
} | ||
|
||
declare class VueI18n { | ||
constructor(options?: VueI18n.I18nOptions) | ||
|
||
readonly messages: VueI18n.LocaleMessages; | ||
|
||
locale: VueI18n.Locale; | ||
fallbackLocale: VueI18n.Locale; | ||
missing: VueI18n.MissingHandler; | ||
formatter: VueI18n.Formatter; | ||
silentTranslationWarn: boolean; | ||
|
||
t(key: VueI18n.Path, values?: VueI18n.Values): VueI18n.TranslateResult; | ||
t(key: VueI18n.Path, locale: VueI18n.Locale, values?: VueI18n.Values): VueI18n.TranslateResult; | ||
tc(key: VueI18n.Path, choice?: VueI18n.Choice, values?: VueI18n.Values): string; | ||
tc(key: VueI18n.Path, choice: VueI18n.Choice, locale: VueI18n.Locale, values?: VueI18n.Values): string; | ||
te(key: VueI18n.Path, locale?: VueI18n.Locale): boolean; | ||
|
||
getLocaleMessage(locale: VueI18n.Locale): VueI18n.LocaleMessageObject; | ||
setLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void; | ||
mergeLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void; | ||
|
||
static install: PluginFunction<never>; | ||
static version: string; | ||
} | ||
|
||
declare module 'vue/types/vue' { | ||
interface Vue { | ||
readonly $i18n: VueI18n; | ||
$t: typeof VueI18n.prototype.t; | ||
$tc: typeof VueI18n.prototype.tc; | ||
$te: typeof VueI18n.prototype.te; | ||
} | ||
} | ||
|
||
declare module 'vue/types/options' { | ||
interface ComponentOptions<V extends Vue> { | ||
i18n?: VueI18n; | ||
} | ||
} | ||
|
||
export = VueI18n; |
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,97 @@ | ||
import * as Vue from 'vue'; | ||
import * as VueI18n from 'vue-i18n'; | ||
import { ComponentOptions } from 'vue'; | ||
|
||
/** | ||
* VueI18n.install | ||
*/ | ||
Vue.use(VueI18n); | ||
VueI18n.install(Vue); | ||
|
||
/** | ||
* VueI18n.version | ||
*/ | ||
VueI18n.version; // $ExpectType string | ||
|
||
/** | ||
* VueI18n Instance | ||
*/ | ||
const locale = 'locale'; | ||
const key = 'key'; | ||
const value = 'value'; | ||
const i18n = new VueI18n({ | ||
locale, | ||
fallbackLocale: locale, | ||
messages: { | ||
[locale]: { | ||
[key]: value, | ||
}, | ||
}, | ||
formatter: { | ||
format(message, values) { | ||
return message; | ||
}, | ||
}, | ||
missing(locale, key, vm) { | ||
}, | ||
fallbackRoot: false, | ||
sync: true, | ||
silentTranslationWarn: true, | ||
}); | ||
i18n.messages[locale][key]; // $ExpectType LocaleMessage | ||
i18n.locale; // $ExpectType string | ||
i18n.fallbackLocale; // $ExpectType string | ||
i18n.missing; // $ExpectType MissingHandler | ||
i18n.formatter; // $ExpectType Formatter | ||
i18n.silentTranslationWarn; // $ExpectType boolean | ||
i18n.setLocaleMessage; // $ExpectType (locale: string, message: LocaleMessageObject) => void | ||
i18n.getLocaleMessage; // $ExpectType (locale: string) => LocaleMessageObject | ||
i18n.mergeLocaleMessage; // $ExpectType (locale: string, message: LocaleMessageObject) => void | ||
// $ExpectType { (key: string, values?: { [key: string]: any; } | undefined): TranslateResult; (key: string, locale: string, values?: { [key: string]: any; } | undefined): TranslateResult; } | ||
i18n.t; | ||
// tslint:disable-next-line:max-line-length | ||
// $ExpectType { (key: string, choice?: number | undefined, values?: { [key: string]: any; } | undefined): string; (key: string, choice: number, locale: string, values?: { [key: string]: any; } | undefined): string; } | ||
i18n.tc; | ||
// $ExpectType (key: string, locale?: string | undefined) => boolean | ||
i18n.te; | ||
|
||
/** | ||
* Vue | ||
*/ | ||
const vm = new Vue({ | ||
i18n, | ||
}); | ||
vm.$i18n; // $ExpectType VueI18n | ||
vm.$t(key); // $ExpectType TranslateResult | ||
vm.$t(key, ['', 0, false, null, undefined]); // $ExpectType TranslateResult | ||
vm.$t(key, { x: 'x' }); // $ExpectType TranslateResult | ||
vm.$t(key, locale); | ||
vm.$t(key, locale, ['', 0, false, null, undefined]); // $ExpectType TranslateResult | ||
vm.$t(key, locale, { x: 'x' }); // $ExpectType TranslateResult | ||
vm.$tc(key); // $ExpectType string | ||
vm.$tc(key, 1); // $ExpectType string | ||
vm.$tc(key, 1, []); // $ExpectType string | ||
vm.$tc(key, 1, {}); // $ExpectType string | ||
vm.$tc(key, 1, locale); // $ExpectType string | ||
vm.$tc(key, 1, locale, []); // $ExpectType string | ||
vm.$tc(key, 1, locale, {}); // $ExpectType string | ||
vm.$te(key); // $ExpectType boolean | ||
vm.$te(key, locale); // $ExpectType boolean | ||
|
||
/** | ||
* VueI18n | ||
*/ | ||
{ | ||
let path: VueI18n.Path; | ||
let locale: VueI18n.Locale; | ||
let values: VueI18n.Values; | ||
let choice: VueI18n.Choice; | ||
let localeMessage: VueI18n.LocaleMessage; | ||
let localeMessageObject: VueI18n.LocaleMessageObject; | ||
let localeMessageArray: VueI18n.LocaleMessageArray; | ||
let localeMessages: VueI18n.LocaleMessages; | ||
let translateResult: VueI18n.TranslateResult; | ||
let formatter: VueI18n.Formatter; | ||
let missingHandler: VueI18n.MissingHandler; | ||
let i18nOptions: VueI18n.I18nOptions; | ||
} |
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"baseUrl": ".", | ||
"types": [], | ||
"paths": { | ||
"vue-i18n": [ | ||
"." | ||
] | ||
}, | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json" | ||
} |
Oops, something went wrong.