Skip to content

Commit

Permalink
fix: strictly key exsisting with te (#1602)
Browse files Browse the repository at this point in the history
resolve #1559
  • Loading branch information
kazupon authored Oct 23, 2023
1 parent 8508472 commit 9c6fd73
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ export function createComposer(options: any = {}, VueI18nLegacy?: any): any {
if (!key) return false
const targetLocale = isString(locale) ? locale : _locale.value
const message = getLocaleMessage(targetLocale)
return _context.messageResolver(message, key) !== null
return isString(_context.messageResolver(message, key))
}

function resolveMessages(key: Path): LocaleMessageValue<Message> | null {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ describe('messageResolver', () => {
})

expect(t('path.to.message')).toEqual('こんにちは')
expect(te('path.to.message')).toEqual(true)
expect(te('path.to.message')).toEqual(false)
expect(tm('api.errors')).toEqual(ja['api.errors'])
expect(mockMessageResolver).toHaveBeenCalledTimes(5)
expect(mockMessageResolver.mock.calls[0][0]).toEqual({})
Expand Down
32 changes: 32 additions & 0 deletions packages/vue-i18n-core/test/issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,38 @@ test('issue #1547', async () => {
expect(wrapper.html()).toEqual('<div>Deep Linked message</div>')
})

test('issue #1559', async () => {
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en: {
hello: 'Hello, Vue I18n',
language: 'Languages',
keyAndNotTranslation: {
entry1: 'TRANSLATION FOR sub entry1',
entry2: 'TRANSLATION FOR sub entry2'
}
}
}
})

const App = defineComponent({
setup() {
const { t } = useI18n()
return { t }
},
template: `
<h1>{{ t('keyAndNotTranslation.entry1') }}</h1>
<div v-if="$te('keyAndNotTranslation')">{{ $t('keyAndNotTranslation') }}</div>`
})
const wrapper = await mount(App, i18n)

expect(wrapper.html()).toEqual(
'<h1>TRANSLATION FOR sub entry1</h1><!--v-if-->'
)
})

test('issue #1595', async () => {
const i18n = createI18n({
legacy: false,
Expand Down

0 comments on commit 9c6fd73

Please sign in to comment.