1- import { App , ComponentPublicInstance , FunctionDirective } from 'vue'
2- import { Path } from './path'
3- import { Locale } from './runtime/context'
1+ import { App , FunctionDirective } from 'vue'
42import { I18nComposer } from './composer'
53import { GlobalI18nSymbol } from './use'
6- import {
7- VueI18n ,
8- createI18n ,
9- VueI18nOptions ,
10- TranslateResult ,
11- DateTimeFormatResult ,
12- NumberFormatResult
13- } from './legacy'
144import { Interpolate , Number } from './components'
155import { hook as vT } from './directive'
166
17- export type LegacyVueI18n = {
18- $i18n : VueI18n
19- $t ( key : Path ) : TranslateResult
20- $t ( key : Path , locale : Locale ) : TranslateResult
21- $t ( key : Path , locale : Locale , list : unknown [ ] ) : TranslateResult
22- $t ( key : Path , locale : Locale , named : object ) : TranslateResult
23- $t ( key : Path , list : unknown [ ] ) : TranslateResult
24- $t ( key : Path , named : object ) : TranslateResult
25- $tc ( key : Path ) : TranslateResult
26- $tc ( key : Path , locale : Locale ) : TranslateResult
27- $tc ( key : Path , list : unknown [ ] ) : TranslateResult
28- $tc ( key : Path , named : object ) : TranslateResult
29- $tc ( key : Path , choice : number ) : TranslateResult
30- $tc ( key : Path , choice : number , locale : Locale ) : TranslateResult
31- $tc ( key : Path , choice : number , list : unknown [ ] ) : TranslateResult
32- $tc ( key : Path , choice : number , named : object ) : TranslateResult
33- $te ( key : Path , locale ?: Locale ) : boolean
34- $d ( value : number | Date ) : DateTimeFormatResult
35- $d ( value : number | Date , key : string ) : DateTimeFormatResult
36- $d ( value : number | Date , key : string , locale : Locale ) : DateTimeFormatResult
37- $d (
38- value : number | Date ,
39- args : { [ key : string ] : string }
40- ) : DateTimeFormatResult
41- $n ( value : number ) : NumberFormatResult
42- $n ( value : number , key : string ) : NumberFormatResult
43- $n ( value : number , key : string , locale : Locale ) : NumberFormatResult
44- $n ( value : number , args : { [ key : string ] : string } ) : NumberFormatResult
45- }
46-
47- export function applyPlugin (
48- app : App ,
49- legacyI18n : VueI18n ,
50- composer : I18nComposer
51- ) : void {
7+ export function apply ( app : App , composer : I18nComposer ) : void {
528 // install components
539 app . component ( Interpolate . name , Interpolate )
5410 app . component ( Number . name , Number )
@@ -58,47 +14,4 @@ export function applyPlugin(
5814
5915 // setup global provider
6016 app . provide ( GlobalI18nSymbol , composer )
61-
62- // supports compatibility for vue-i18n legacy APIs
63- app . mixin ( {
64- beforeCreate ( this : ComponentPublicInstance < LegacyVueI18n > ) {
65- const options = this . $options
66-
67- if ( options . i18n ) {
68- // component local i18n
69- const optionsI18n = options . i18n as VueI18nOptions
70- if ( options . __i18n ) {
71- optionsI18n . __i18n = options . __i18n
72- }
73- optionsI18n . _root = composer
74- this . $i18n = createI18n ( optionsI18n )
75- } else if ( options . __i18n ) {
76- this . $i18n = createI18n ( { __i18n : options . __i18n , _root : composer } )
77- } else if ( this . $root && this . $root . proxy ) {
78- // root i18n
79- // TODO: should resolve type inference
80- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81- const instance : any = this . $root . proxy
82- this . $i18n = instance . $i18n || legacyI18n
83- } else if ( this . $parent && this . $parent . proxy ) {
84- // parent i18n
85- // TODO: should resolve type inference
86- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87- const instance : any = this . $parent . proxy
88- this . $i18n = instance . $i18n || legacyI18n
89- } else {
90- this . $i18n = legacyI18n
91- }
92-
93- // define vue-i18n legacy APIs
94- this . $t = ( ...args : unknown [ ] ) : TranslateResult => this . $i18n . t ( ...args )
95- this . $tc = ( ...args : unknown [ ] ) : TranslateResult => this . $i18n . tc ( ...args )
96- this . $te = ( key : Path , locale ?: Locale ) : boolean =>
97- this . $i18n . te ( key , locale )
98- this . $d = ( ...args : unknown [ ] ) : DateTimeFormatResult =>
99- this . $i18n . d ( ...args )
100- this . $n = ( ...args : unknown [ ] ) : NumberFormatResult =>
101- this . $i18n . n ( ...args )
102- }
103- } )
10417}
0 commit comments