Skip to content

Commit cd5492c

Browse files
committed
fix: export global composer interface
1 parent 0f549d8 commit cd5492c

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

src/composer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export type CustomBlocks = string[] | PreCompileHandler
8686
/**
8787
* Composer Options
8888
*
89+
* @remarks
8990
* This is options to create composer.
9091
*/
9192
export interface ComposerOptions {
@@ -117,6 +118,7 @@ export interface ComposerInternalOptions {
117118
/**
118119
* Composer Interfaces
119120
*
121+
* @remarks
120122
* This is the interface for being used for Vue 3 Composition API.
121123
*/
122124
export type Composer = {
@@ -265,6 +267,7 @@ export function addPreCompileMessages(
265267

266268
/**
267269
* Create composer interface factory
270+
*
268271
* @internal
269272
*/
270273
export function createComposer(

src/directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function getComposer(
2121
instance: ComponentInternalInstance
2222
): Composer | null {
2323
if (i18n.mode === 'composable') {
24-
return i18n._getComposer(instance) || i18n._global
24+
return i18n._getComposer(instance) || i18n.global
2525
} else {
2626
const vueI18n = i18n._getLegacy(instance)
27-
return vueI18n != null ? vueI18n.__composer : i18n._global
27+
return vueI18n != null ? vueI18n.__composer : i18n.global
2828
}
2929
}
3030

src/i18n.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,28 @@ import { defineMixin } from './mixin'
2020
import { isEmptyObject } from './utils'
2121

2222
/**
23-
* I18n Options
23+
* I18n Options for `createI18n`
2424
*
2525
* @remarks
26-
* `I18nOptions` is inherited {@link ComposerOptions} and {@link VueI18nOptions}, so you can specify these options.
26+
* `I18nOptions` is inherited {@link I18nAdditionalOptions}, {@link ComposerOptions} and {@link VueI18nOptions},
27+
* so you can specify these options.
2728
*
2829
*/
30+
export type I18nOptions = I18nAdditionalOptions &
31+
(ComposerOptions | VueI18nOptions)
32+
33+
/**
34+
* I18n Additional Options for `createI18n`
35+
*/
2936
export interface I18nAdditionalOptions {
3037
/**
3138
* Whether vue-i18n legacy API use on your Vue App.
39+
*
3240
* @defaultValue `false`
3341
*/
3442
legacy?: boolean
3543
}
3644

37-
export type I18nOptions = I18nAdditionalOptions &
38-
(ComposerOptions | VueI18nOptions)
39-
4045
/**
4146
* I18n API mode
4247
*/
@@ -46,16 +51,32 @@ export type I18nMode = 'legacy' | 'composable'
4651
* I18n interface
4752
*/
4853
export interface I18n {
54+
/**
55+
* I18n API mode
56+
*
57+
* @remarks
58+
* if you specified `legacy: true` option in `createI18n`, return `legacy`,
59+
* else `composable`
60+
*
61+
* @defaultValue `composable`
62+
*/
4963
readonly mode: I18nMode
64+
/**
65+
* Global composer
66+
*/
67+
readonly global: Composer
68+
/**
69+
* @internal
70+
*/
5071
install(app: App, ...options: unknown[]): void
5172
}
5273

5374
/**
5475
* I18n interface for internal usage
76+
*
5577
* @internal
5678
*/
5779
export interface I18nInternal {
58-
readonly _global: Composer
5980
_getComposer(instance: ComponentInternalInstance): Composer | null
6081
_setComposer(instance: ComponentInternalInstance, composer: Composer): void
6182
_deleteComposer(instance: ComponentInternalInstance): void
@@ -70,17 +91,24 @@ export interface I18nInternal {
7091
export type I18nScope = 'local' | 'parent' | 'global'
7192

7293
/**
73-
* Composer additional options
94+
* I18n Options for `useI18n`
95+
*
96+
* @remarks
97+
* `UseI18nOptions` is inherited {@link ComposerAdditionalOptions} and {@link ComposerOptions},
98+
* so you can specify these options.
99+
*/
100+
export type UseI18nOptions = ComposerAdditionalOptions & ComposerOptions
101+
102+
/**
103+
* Composer additional options for `useI18n`
74104
*
75-
* @remarks
105+
* @remarks
76106
* `ComposerAdditionalOptions` is extend for {@link ComposerOptions}, so you can specify these options.
77107
*/
78108
export interface ComposerAdditionalOptions {
79-
useScope?: I18nScope // default 'global'
109+
useScope?: I18nScope
80110
}
81111

82-
export type UseI18nOptions = ComposerAdditionalOptions & ComposerOptions
83-
84112
/**
85113
* I18n instance injectin key
86114
* @internal
@@ -97,7 +125,7 @@ export const I18nSymbol: InjectionKey<I18n & I18nInternal> = Symbol.for(
97125
*
98126
* @remarks
99127
* When you use Composable API, you need to specify options of {@link ComposerOptions}.
100-
* When you use Legacy API, you need toto specify options of {@link VueI18nOptions} and `legacy: true`.
128+
* When you use Legacy API, you need toto specify options of {@link VueI18nOptions} and `legacy: true` option.
101129
*
102130
* @example
103131
* case: for Composable API
@@ -181,7 +209,7 @@ export function createI18n(options: I18nOptions = {}): I18n {
181209
)
182210
}
183211
},
184-
get _global(): Composer {
212+
get global(): Composer {
185213
return __legacyMode
186214
? (__global as VueI18n).__composer
187215
: (__global as Composer)
@@ -264,7 +292,7 @@ export function useI18n(options: UseI18nOptions = {}): Composer {
264292
throw new Error('TODO')
265293
}
266294

267-
const global = i18n._global
295+
const global = i18n.global
268296

269297
let emptyOption = false
270298
// prettier-ignore

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ export {
4848
UseI18nOptions
4949
} from './i18n'
5050
export { I18nPluginOptions } from './plugin'
51+
52+
/**
53+
* vue-i18n version
54+
*/
5155
export const VERSION = __VERSION__

src/legacy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface Formatter {
5959
/**
6060
* VueI18n Options
6161
*
62+
* @remarks
6263
* This option is compatible with the constructor options of `VueI18n` class (offered with [email protected]).
6364
*/
6465
export interface VueI18nOptions {
@@ -86,6 +87,7 @@ export interface VueI18nOptions {
8687
/**
8788
* VueI18n Interfaces
8889
*
90+
* @remarks
8991
* This interface is compatible with interface of `VueI18n` class (offered with [email protected]).
9092
*/
9193
export type VueI18n = {
@@ -154,6 +156,7 @@ export type VueI18n = {
154156

155157
/**
156158
* Convert to I18n Composer Options from VueI18n Options
159+
*
157160
* @internal
158161
*/
159162
function convertComposerOptions(
@@ -236,6 +239,7 @@ function convertComposerOptions(
236239

237240
/**
238241
* create VueI18n interface factory
242+
*
239243
* @internal
240244
*/
241245
export function createVueI18n(

src/plugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { Translation, NumberFormat, DatetimeFormat } from './components'
44
import { vTDirective } from './directive'
55
import { isPlainObject, isString, warn } from './utils'
66

7+
/**
8+
* I18n plugin options
9+
*
10+
* @remarks
11+
* An options specified when installing vue-i18n as Vue plugin with using `app.use`.
12+
*/
713
export interface I18nPluginOptions {
14+
// TODO: should be more redisigned, we should change to `boolean` option
815
'i18n-t'?: string
916
}
1017

0 commit comments

Comments
 (0)