Skip to content

Commit 1cbb16f

Browse files
littleboarx双面胶
andauthored
fix:using the better Fragment detection(#1122) (#1177)
Co-authored-by: 双面胶 <[email protected]>
1 parent 6161779 commit 1cbb16f

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

packages/vue-i18n-core/src/components/utils.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import { Fragment } from 'vue'
2-
import { isArray } from '@intlify/shared'
1+
import { Fragment, VNode } from 'vue'
32

43
import type { NamedValue } from '@intlify/core-base'
5-
64
export function getInterpolateArg(
75
// eslint-disable-next-line @typescript-eslint/no-explicit-any
86
{ slots }: any, // SetupContext,
97
keys: string[]
108
): NamedValue | unknown[] {
119
if (keys.length === 1 && keys[0] === 'default') {
1210
// default slot with list
13-
const ret = slots.default ? slots.default() : []
11+
const ret: VNode[] = slots.default ? slots.default() : []
1412
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
return ret.reduce((slot: any[], current: any) => {
16-
return (slot = [
13+
return ret.reduce((slot: (VNode | typeof Fragment)[], current: any) => {
14+
return [
1715
...slot,
18-
...(isArray(current.children) ? current.children : [current])
19-
])
16+
...(current.type === Fragment ? current.children : [current])
17+
]
2018
}, [])
2119
} else {
2220
// named slots

packages/vue-i18n-core/test/issues.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ test('issue #708', async () => {
9696
<strong>{{ $t("world") }}</strong>
9797
</template>
9898
</i18n-t>
99-
99+
100100
<br />
101-
101+
102102
<C2>
103103
<div>{{ $t("hello", { world: $t("world") }) }}</div>
104104
<i18n-t keypath="hello" tag="div">
@@ -685,3 +685,34 @@ test('issue #1083', async () => {
685685
await nextTick()
686686
expect(dirEl!.textContent).toEqual('Hello World!')
687687
})
688+
689+
test('issue #1123', async () => {
690+
const i18n = createI18n({
691+
legacy: false,
692+
locale: 'en',
693+
messages
694+
})
695+
696+
const App = defineComponent({
697+
setup() {
698+
useI18n()
699+
const values = ref(['kazupon', 'oranges'])
700+
return { values }
701+
},
702+
template: `
703+
<i18n-t keypath="message.list_multi" locale="en">
704+
<span>Hello</span>
705+
<a
706+
>
707+
<strong>Vue </strong>
708+
I18n
709+
</a>
710+
</i18n-t>
711+
`
712+
})
713+
const wrapper = await mount(App, i18n)
714+
715+
expect(wrapper.html()).toEqual(
716+
`hello, <span>Hello</span>! Do you like <a><strong>Vue </strong> I18n </a>?`
717+
)
718+
})

0 commit comments

Comments
 (0)