33 */
44
55import { 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'
714import {
815 compileToFunction ,
916 registerMessageCompiler ,
@@ -14,6 +21,7 @@ import {
1421} from '@intlify/core-base'
1522import { createI18n , useI18n } from '../../src/index'
1623
24+ import type { Ref } from 'vue'
1725import type { Path , PathValue , MessageResolver } from '@intlify/core-base'
1826
1927const messages = {
@@ -22,6 +30,7 @@ const messages = {
2230 language : 'English' ,
2331 quantity : 'Quantity' ,
2432 list : 'hello, {0}!' ,
33+ list_multi : 'hello, {0}! Do you like {1}?' ,
2534 named : 'hello, {name}!' ,
2635 linked : '@:message.named How are you?' ,
2736 plural : 'no bananas | {n} banana | {n} bananas'
@@ -277,6 +286,70 @@ test('message resolver', async () => {
277286 expect ( mockMessageResolver . mock . calls [ 0 ] [ 1 ] ) . toEqual ( 'message.named' )
278287} )
279288
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+
280353test ( 'issue #708' , async ( ) => {
281354 const i18n = createI18n ( {
282355 legacy : true ,
0 commit comments