Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid transform to globalThis with bundler #1413

Merged
merged 1 commit into from
May 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/vue-i18n-core/src/i18n.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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