Skip to content

Commit

Permalink
fix: avoid transform to globalThis with bundler (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed May 30, 2023
1 parent 67b8402 commit 2b6fbba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/vue-i18n-core/src/i18n.ts
Expand Up @@ -834,7 +834,7 @@ export function useI18n<
}

const i18n = getI18nInstance(instance)
const global = getGlobalComposer(i18n)
const gl = getGlobalComposer(i18n)
const componentOptions = getComponentOptions(instance)
const scope = getScope(options, componentOptions)

Expand All @@ -844,13 +844,13 @@ export function useI18n<
if (!i18n.allowComposition) {
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE)
}
return useI18nForLegacy(instance, scope, global, options)
return useI18nForLegacy(instance, scope, gl, options)
}
}

if (scope === 'global') {
adjustI18nResources(global, options, componentOptions)
return global as unknown as Composer<
adjustI18nResources(gl, options, componentOptions)
return gl as unknown as Composer<
Messages,
DateTimeFormats,
NumberFormats,
Expand All @@ -865,7 +865,7 @@ export function useI18n<
if (__DEV__) {
warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE))
}
composer = global as unknown as Composer
composer = gl as unknown as Composer
}
return composer as unknown as Composer<
Messages,
Expand All @@ -885,8 +885,8 @@ export function useI18n<
composerOptions.__i18n = componentOptions.__i18n
}

if (global) {
composerOptions.__root = global
if (gl) {
composerOptions.__root = gl
}

composer = createComposer(composerOptions, _legacyVueI18n) as Composer
Expand Down
10 changes: 5 additions & 5 deletions packages/vue-i18n-core/src/utils.ts
Expand Up @@ -162,13 +162,13 @@ export function getComponentOptions(instance: ComponentInternalInstance): any {
}

export function adjustI18nResources(
global: Composer,
gl: Composer,
options: ComposerOptions,
componentOptions: any // eslint-disable-line @typescript-eslint/no-explicit-any
): void {
let messages = isObject(options.messages) ? options.messages : {}
if ('__i18nGlobal' in componentOptions) {
messages = getLocaleMessages(global.locale.value as Locale, {
messages = getLocaleMessages(gl.locale.value as Locale, {
messages,
__i18n: componentOptions.__i18nGlobal
})
Expand All @@ -177,7 +177,7 @@ export function adjustI18nResources(
const locales = Object.keys(messages)
if (locales.length) {
locales.forEach(locale => {
global.mergeLocaleMessage(locale, messages[locale])
gl.mergeLocaleMessage(locale, messages[locale])
})
}
if (!__LITE__) {
Expand All @@ -186,7 +186,7 @@ export function adjustI18nResources(
const locales = Object.keys(options.datetimeFormats)
if (locales.length) {
locales.forEach(locale => {
global.mergeDateTimeFormat(locale, options.datetimeFormats![locale])
gl.mergeDateTimeFormat(locale, options.datetimeFormats![locale])
})
}
}
Expand All @@ -195,7 +195,7 @@ export function adjustI18nResources(
const locales = Object.keys(options.numberFormats)
if (locales.length) {
locales.forEach(locale => {
global.mergeNumberFormat(locale, options.numberFormats![locale])
gl.mergeNumberFormat(locale, options.numberFormats![locale])
})
}
}
Expand Down

0 comments on commit 2b6fbba

Please sign in to comment.