Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 03230ca

Browse files
authored
allow use other vue instance (#3)
* allow use other vue instance * strong type return value; bumpup version * rename composition function return type interface
1 parent 320f13c commit 03230ca

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-i18n-composable",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"main": "dist/index.js",
55
"module": "dist/index.m.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import Vue from 'vue'
22
import VueI18n from 'vue-i18n'
3-
import { computed, getCurrentInstance } from '@vue/composition-api'
3+
import { computed, getCurrentInstance, WritableComputedRef } from '@vue/composition-api'
4+
import { VueConstructor } from 'vue/types/umd'
45

56
let i18nInstance: VueI18n | undefined
67

7-
export function createI18n(options?: VueI18n.I18nOptions) {
8-
Vue.use(VueI18n)
8+
export function createI18n(options?: VueI18n.I18nOptions, vue: VueConstructor = Vue): VueI18n {
9+
vue.use(VueI18n)
910
i18nInstance = new VueI18n(options)
1011

1112
return i18nInstance
1213
}
1314

14-
export function useI18n() {
15+
export interface Composer {
16+
locale: WritableComputedRef<string>
17+
t: typeof VueI18n.prototype.t
18+
tc: typeof VueI18n.prototype.tc
19+
te: typeof VueI18n.prototype.te
20+
d: typeof VueI18n.prototype.d
21+
n: typeof VueI18n.prototype.n
22+
}
23+
24+
export function useI18n(): Composer {
1525
if (!i18nInstance)
1626
throw new Error('vue-i18n not initialized')
1727

0 commit comments

Comments
 (0)