Skip to content

Commit

Permalink
fix: allow empty default message (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed May 11, 2024
1 parent c14ad03 commit 4b231ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core-base/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,11 @@ export function translate<
: (!messageCompiler ? () => key : key)
: fallbackFormat // default by `fallbackFormat` option
? (!messageCompiler ? () => key : key)
: ''
const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== ''
: null
const enableDefaultMsg =
fallbackFormat ||
(defaultMsgOrKey != null &&
(isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey)))
const locale = getLocale(context, options)

// escape params
Expand Down
1 change: 1 addition & 0 deletions packages/core-base/test/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('default option', () => {
expect(translate(ctx, 'hello', 'hello, default message!')).toEqual(
'hello, default message!'
)
expect(translate(ctx, 'hello', '')).toEqual('')
})

test('boolean true', () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/vue-i18n-core/test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ describe('t', () => {
await nextTick()
expect(t('hello')).toEqual(JA_HELLO)
})

test('default msg', () => {
const { t } = createComposer({
locale: 'en',
messages: {
en: { hello: 'Hello!' }
}
})
expect(t('foo', '')).toEqual('')
})
})

describe('rt', () => {
Expand Down

0 comments on commit 4b231ce

Please sign in to comment.