Skip to content

Commit 369d0de

Browse files
authored
fix: nullish assignment (#954)
* fix: nullish assignment closes #952 * improve corectly case
1 parent 53e5197 commit 369d0de

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export const I18nErrorCodes = {
3434
BRIDGE_SUPPORT_VUE_2_ONLY: inc(), // 26
3535
// need to define `i18n` option in `allowComposition: true` and `useScope: 'local' at `useI18n``
3636
MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION: inc(), // 27
37+
// Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
38+
NOT_AVAILABLE_COMPOSITION_IN_LEGACY: inc(), // 28
3739
// for enhancement
38-
__EXTEND_POINT__: inc() // 27
40+
__EXTEND_POINT__: inc() // 29
3941
} as const
4042

4143
type I18nErrorCodes = typeof I18nErrorCodes[keyof typeof I18nErrorCodes]
@@ -69,5 +71,7 @@ export const errorMessages: { [code: number]: string } = {
6971
[I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]:
7072
'vue-i18n-bridge support Vue 2.x only',
7173
[I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION]:
72-
'Must define ‘i18n’ option in Composition API with using local scope in Legacy API mode'
74+
'Must define ‘i18n’ option in Composition API with using local scope in Legacy API mode',
75+
[I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY]:
76+
'Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly'
7377
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,11 @@ function useI18nForLegacy(
14811481
}
14821482

14831483
onBeforeMount(() => {
1484+
if (instance.proxy == null || instance.proxy.$i18n == null) {
1485+
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY)
1486+
}
14841487
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1485-
const composer = (_composer.value = (instance.proxy?.$i18n as any)
1488+
const composer = (_composer.value = (instance.proxy.$i18n as any)
14861489
.__composer as Composer)
14871490
if (scope === 'global') {
14881491
_locale.value = composer.locale.value

0 commit comments

Comments
 (0)