Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vue-i18n-core/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,17 +2110,17 @@ export function createComposer(options: any = {}): any {
const locale = computed({
get: () => _locale.value,
set: val => {
_context.locale = val
_locale.value = val
_context.locale = _locale.value
}
})

// fallbackLocale
const fallbackLocale = computed({
get: () => _fallbackLocale.value,
set: val => {
_context.fallbackLocale = val
_fallbackLocale.value = val
_context.fallbackLocale = _fallbackLocale.value
updateFallbackLocale(_context, _locale.value, val)
}
})
Expand Down
23 changes: 22 additions & 1 deletion packages/vue-i18n-core/test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,35 @@ describe('locale', () => {
test('reactivity', async () => {
const fn = vi.fn()

const { locale } = createComposer({})
const { locale, t } = createComposer({
messages: {
en: {
test: 'en'
},
'en-US': {
test: 'en-US'
}
}
})
watch(locale, fn)
locale.value = 'en'
await nextTick()

expect(fn).toBeCalled()
expect(fn.mock.calls[0][0]).toEqual('en')
expect(fn.mock.calls[0][1]).toEqual('en-US')

let result = ''
locale.value = 'en'

watch(locale, () => (result = t('test')), {
immediate: true,
flush: 'sync'
})
expect(result).toEqual('en')
locale.value = 'en-US'
await nextTick()
expect(result).toEqual('en-US')
})
})

Expand Down