mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
vuex-i18n: Provides its own types (#39568)
This commit is contained in:
committed by
Jesse Trinity
parent
f9f76f3280
commit
8b63e0de7b
@@ -4692,6 +4692,12 @@
|
||||
"sourceRepoURL": "https://github.com/rigor789/vue-scrollto",
|
||||
"asOfVersion": "2.17.1"
|
||||
},
|
||||
{
|
||||
"libraryName": "vuex-i18n",
|
||||
"typingsPackageName": "vuex-i18n",
|
||||
"sourceRepoURL": "https://github.com/dkfbasel/vuex-i18n",
|
||||
"asOfVersion": "1.13.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "typescript",
|
||||
"typingsPackageName": "w3c-permissions",
|
||||
|
||||
Vendored
-109
@@ -1,109 +0,0 @@
|
||||
// Type definitions for vuex-i18n 1.10
|
||||
// Project: https://github.com/dkfbasel/vuex-i18n
|
||||
// Definitions by: Cedric Kemp <https://github.com/jaeggerr>
|
||||
// Noam Kfir <https://github.com/noamkfir>
|
||||
// Suleimanov Artem <https://github.com/barahliush>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
import _Vue, { PluginObject } from "vue";
|
||||
|
||||
declare module "vue/types/vue" {
|
||||
interface Vue {
|
||||
$i18n: Ii18n;
|
||||
$t(key: string, options?: any, pluralization?: number): string | undefined;
|
||||
$t(key: string, defaultValue: string, options?: any, pluralization?: number): string | undefined;
|
||||
}
|
||||
|
||||
interface VueConstructor<V extends Vue = Vue> {
|
||||
i18n: Ii18n;
|
||||
}
|
||||
}
|
||||
|
||||
export interface i18nState {
|
||||
fallback: string | null;
|
||||
locale: string | null;
|
||||
translations: {
|
||||
[key: string]: Translations;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Translations {
|
||||
[key: string]: string | Translations;
|
||||
}
|
||||
|
||||
export interface Ii18n {
|
||||
/** get the current locale */
|
||||
locale(): string | null;
|
||||
|
||||
/** get all the registered locales */
|
||||
locales(): 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: Translations): 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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
translateIn(locale: string, key: string, options?: any, pluralization?: number): string | undefined;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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, scope?: string): boolean;
|
||||
}
|
||||
|
||||
declare const _default: {
|
||||
plugin: PluginObject<Ii18n>;
|
||||
};
|
||||
|
||||
export default _default;
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"vue": ">=2.0.0",
|
||||
"vuex": ">=2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"types": [],
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"noEmit": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"vuex-i18n-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// load vue and vuex instance
|
||||
import Vue from "vue";
|
||||
import { Store } from "vuex";
|
||||
|
||||
// load vuex i18n module
|
||||
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<RootState>({});
|
||||
|
||||
// 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",
|
||||
tree: {
|
||||
nested: "This is nested 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");
|
||||
|
||||
Vue.i18n.translateIn("en", "tree.nested");
|
||||
Reference in New Issue
Block a user