3
3
*/
4
4
5
5
import { mount } from '../helper'
6
- import { h , defineComponent , SetupContext , VNodeChild , ref } from 'vue'
6
+ import {
7
+ h ,
8
+ defineComponent ,
9
+ SetupContext ,
10
+ VNodeChild ,
11
+ ref ,
12
+ nextTick
13
+ } from 'vue'
7
14
import {
8
15
compileToFunction ,
9
16
registerMessageCompiler ,
@@ -14,6 +21,7 @@ import {
14
21
} from '@intlify/core-base'
15
22
import { createI18n , useI18n } from '../../src/index'
16
23
24
+ import type { Ref } from 'vue'
17
25
import type { Path , PathValue , MessageResolver } from '@intlify/core-base'
18
26
19
27
const messages = {
@@ -22,6 +30,7 @@ const messages = {
22
30
language : 'English' ,
23
31
quantity : 'Quantity' ,
24
32
list : 'hello, {0}!' ,
33
+ list_multi : 'hello, {0}! Do you like {1}?' ,
25
34
named : 'hello, {name}!' ,
26
35
linked : '@:message.named How are you?' ,
27
36
plural : 'no bananas | {n} banana | {n} bananas'
@@ -277,6 +286,70 @@ test('message resolver', async () => {
277
286
expect ( mockMessageResolver . mock . calls [ 0 ] [ 1 ] ) . toEqual ( 'message.named' )
278
287
} )
279
288
289
+ test ( 'v-if / v-else' , async ( ) => {
290
+ const i18n = createI18n ( {
291
+ legacy : false ,
292
+ locale : 'en' ,
293
+ messages
294
+ } )
295
+
296
+ let toggle : Ref < boolean >
297
+ const App = defineComponent ( {
298
+ setup ( ) {
299
+ useI18n ( )
300
+ toggle = ref ( true )
301
+ return { toggle }
302
+ } ,
303
+ template : `
304
+ <i18n-t tag="p" class="name" keypath="message.named">
305
+ <template #name>
306
+ <span v-if="toggle">kazupon</span>
307
+ <span v-else="toggle">kazu_pon</span>
308
+ </template>
309
+ </i18n-t>
310
+ `
311
+ } )
312
+ const wrapper = await mount ( App , i18n )
313
+
314
+ expect ( wrapper . html ( ) ) . toEqual (
315
+ `<p class="name">hello, <span>kazupon</span>!</p>`
316
+ )
317
+
318
+ toggle ! . value = false
319
+ await nextTick ( )
320
+ expect ( wrapper . html ( ) ) . toEqual (
321
+ `<p class="name">hello, <span>kazu_pon</span>!</p>`
322
+ )
323
+ } )
324
+
325
+ test ( 'v-for: issue #819' , async ( ) => {
326
+ const i18n = createI18n ( {
327
+ legacy : false ,
328
+ locale : 'en' ,
329
+ messages
330
+ } )
331
+
332
+ const App = defineComponent ( {
333
+ setup ( ) {
334
+ useI18n ( )
335
+ const values = ref ( [ 'kazupon' , 'oranges' ] )
336
+ return { values }
337
+ } ,
338
+ template : `
339
+ <i18n-t keypath="message.list_multi" locale="en">
340
+ <span v-for="(value, index) in values" :key="index" class="bold">
341
+ {{ value }}
342
+ </span>
343
+ </i18n-t>
344
+ `
345
+ } )
346
+ const wrapper = await mount ( App , i18n )
347
+
348
+ expect ( wrapper . html ( ) ) . toEqual (
349
+ `hello, <span class="bold">kazupon</span>! Do you like <span class="bold">oranges</span>?`
350
+ )
351
+ } )
352
+
280
353
test ( 'issue #708' , async ( ) => {
281
354
const i18n = createI18n ( {
282
355
legacy : true ,
0 commit comments