File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
packages/vue-i18n-core/test Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ const i18n = createI18n({
79
79
80
80
const app = createApp ({
81
81
data () {
82
- return {
82
+ return {
83
83
byePath: ' message.bye' ,
84
84
appleCount: 7 ,
85
85
}
@@ -112,6 +112,16 @@ Outputs:
112
112
</div >
113
113
```
114
114
115
+ ## scoping
116
+
117
+ As mentioned in [ the scope section] ( ../essentials/scope.md ) , vue-i18n has a global scope and a local scope.
118
+
119
+ The scope under which ` v-t ` is also affected by scope when it works.
120
+
121
+ - local scope: using the i18n option in Legacy API style or using ` useScope: ‘local' ` in ` useI18n ` .
122
+ - global scope: all cases other than the above.
123
+
124
+
115
125
## ` $t ` vs ` v-t `
116
126
117
127
### ` $t `
Original file line number Diff line number Diff line change @@ -165,6 +165,36 @@ test('legacy mode', async () => {
165
165
expect ( wrapper . html ( ) ) . toEqual ( '<p>hello!</p>' )
166
166
} )
167
167
168
+ test ( 'fallback to global scope' , async ( ) => {
169
+ const i18n = createI18n ( {
170
+ locale : 'en' ,
171
+ messages : {
172
+ en : {
173
+ hello : 'hello!'
174
+ }
175
+ }
176
+ } )
177
+
178
+ const Child = defineComponent ( {
179
+ setup ( ) {
180
+ // <p v-t="'hello'"></p>
181
+ const t = resolveDirective ( 't' )
182
+ return ( ) => {
183
+ return withDirectives ( h ( 'p' ) , [ [ t ! , 'hello' ] ] )
184
+ }
185
+ }
186
+ } )
187
+
188
+ const App = defineComponent ( {
189
+ setup ( ) {
190
+ return ( ) => h ( 'div' , [ h ( Child ) ] )
191
+ }
192
+ } )
193
+ const wrapper = await mount ( App , i18n )
194
+
195
+ expect ( wrapper . html ( ) ) . toEqual ( '<div><p>hello!</p></div>' )
196
+ } )
197
+
168
198
test ( 'using in template' , async ( ) => {
169
199
const i18n = createI18n ( {
170
200
locale : 'en' ,
You can’t perform that action at this time.
0 commit comments