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
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const errorMessages: { [code: number]: string } = {
[I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]:
'vue-i18n-bridge support Vue 2.x only',
[I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION]:
'Must define ‘i18n’ option in Composition API with using local scope in Legacy API mode',
'Must define ‘i18n’ option or custom block in Composition API with using local scope in Legacy API mode',
[I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY]:
'Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly'
}
6 changes: 5 additions & 1 deletion packages/vue-i18n-core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,11 @@ function useI18nForLegacy(
const isLocale = scope === 'local'
const _composer = shallowRef<Composer | null>(null)

if (isLocale && instance.proxy && !instance.proxy.$options.i18n) {
if (
isLocale &&
instance.proxy &&
!(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)
) {
throw createI18nError(
I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION
)
Expand Down
39 changes: 39 additions & 0 deletions packages/vue-i18n-core/test/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,45 @@ describe('useI18n', () => {
expect(html()).toEqual('<p>en:world!</p>')
})

test('use custom block', async () => {
const i18n = createI18n({
allowComposition: true,
locale: 'ja',
messages: {
en: {
hello: 'hello!'
},
ja: {}
}
})

const App = defineComponent({
setup() {
const instance = getCurrentInstance()
if (instance == null) {
throw new Error()
}
const options = instance.type as ComponentOptions
options.__i18n = [
{
locale: 'ja',
resource: {
hello: 'こんにちは!'
}
}
]
const { locale, t } = useI18n({
inheritLocale: true,
useScope: 'local'
})
return { locale, t }
},
template: `<p>{{ locale }}:{{ t('hello') }}</p>`
})
const { html } = await mount(App, i18n)
expect(html()).toEqual('<p>ja:こんにちは!</p>')
})

test('not defined i18n option in local scope', async () => {
const i18n = createI18n({
allowComposition: true,
Expand Down