Skip to content

Commit 22b9457

Browse files
authored
fix: inherit warn html message setting option (#856)
* fix: inherit warn html message setting option closes #853 * fix: lint errors
1 parent 1b9711a commit 22b9457

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed

packages/vue-i18n-core/src/composer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,9 +1847,12 @@ export function createComposer(options: any = {}, VueI18nLegacy?: any): any {
18471847
? options.postTranslation
18481848
: null
18491849

1850-
let _warnHtmlMessage = isBoolean(options.warnHtmlMessage)
1851-
? options.warnHtmlMessage
1852-
: true
1850+
// prettier-ignore
1851+
let _warnHtmlMessage = __root
1852+
? __root.warnHtmlMessage
1853+
: isBoolean(options.warnHtmlMessage)
1854+
? options.warnHtmlMessage
1855+
: true
18531856

18541857
let _escapeParameter = !!options.escapeParameter
18551858

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,96 @@ test('issue #819: v-for', async () => {
314314
)
315315
})
316316

317+
describe('issue #853', () => {
318+
test('legacy', async () => {
319+
const mockWarn = warn as jest.MockedFunction<typeof warn>
320+
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
321+
322+
const i18n = createI18n({
323+
locale: 'en',
324+
fallbackLocale: 'en',
325+
warnHtmlInMessage: 'off',
326+
messages: {
327+
en: {
328+
hello: '<p>hello</p>'
329+
}
330+
}
331+
})
332+
333+
const Child = defineComponent({
334+
i18n: {
335+
messages: {
336+
en: { child: '<p>child</p>' }
337+
}
338+
},
339+
template: `<div v-html="$t('child')"></div>`
340+
})
341+
342+
const App = defineComponent({
343+
components: {
344+
Child
345+
},
346+
template: `
347+
<div>
348+
<Child />
349+
<div v-html="$t('hello')"></div>
350+
</div>`
351+
})
352+
353+
await mount(App, i18n)
354+
355+
expect(mockWarn).toHaveBeenCalledTimes(0)
356+
})
357+
358+
test('compostion', async () => {
359+
const mockWarn = warn as jest.MockedFunction<typeof warn>
360+
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
361+
362+
const i18n = createI18n({
363+
legacy: false,
364+
locale: 'en',
365+
fallbackLocale: 'en',
366+
globalInjection: true,
367+
warnHtmlMessage: false,
368+
messages: {
369+
en: {
370+
hello: '<p>hello</p>'
371+
}
372+
}
373+
})
374+
375+
const Child = defineComponent({
376+
setup() {
377+
const { t } = useI18n({
378+
messages: {
379+
en: { child: '<p>child</p>' }
380+
}
381+
})
382+
return { t }
383+
},
384+
template: `<div v-html="t('child')"></div>`
385+
})
386+
387+
const App = defineComponent({
388+
components: {
389+
Child
390+
},
391+
template: `
392+
<div>
393+
<Child />
394+
<div v-html="$t('hello')"></div>
395+
</div>`
396+
})
397+
398+
await mount(App, i18n)
399+
400+
expect(mockWarn).toHaveBeenCalledTimes(0)
401+
})
402+
})
403+
317404
test('issue #854', async () => {
318405
const mockWarn = warn as jest.MockedFunction<typeof warn>
319-
mockWarn.mockImplementation(() => {})
406+
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
320407

321408
const i18n = createI18n({
322409
legacy: false,

0 commit comments

Comments
 (0)