From 0ca99a7f5e61d0bdcd99cbc21543f766bcaad874 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 17:03:07 +0900 Subject: [PATCH 01/18] remove legacy source --- packages/petite-vue-i18n/src/index.ts | 1 - packages/petite-vue-i18n/src/runtime.ts | 1 - packages/vue-i18n-core/src/devtools.ts | 42 +---- packages/vue-i18n-core/src/i18n.ts | 239 ++++-------------------- packages/vue-i18n-core/src/index.ts | 1 - packages/vue-i18n-core/src/misc.ts | 4 - packages/vue-i18n-core/src/mixins.ts | 216 --------------------- packages/vue-i18n-core/src/petite.ts | 1 - packages/vue-i18n/src/index.ts | 1 - packages/vue-i18n/src/runtime.ts | 1 - 10 files changed, 47 insertions(+), 460 deletions(-) delete mode 100644 packages/vue-i18n-core/src/mixins.ts diff --git a/packages/petite-vue-i18n/src/index.ts b/packages/petite-vue-i18n/src/index.ts index 5c4b915cb..da9cb0a51 100644 --- a/packages/petite-vue-i18n/src/index.ts +++ b/packages/petite-vue-i18n/src/index.ts @@ -70,7 +70,6 @@ export type { ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nMode, I18nOptions, I18nPluginOptions, I18nScope, diff --git a/packages/petite-vue-i18n/src/runtime.ts b/packages/petite-vue-i18n/src/runtime.ts index d9d40abb9..6de23ca7e 100644 --- a/packages/petite-vue-i18n/src/runtime.ts +++ b/packages/petite-vue-i18n/src/runtime.ts @@ -71,7 +71,6 @@ export type { ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nMode, I18nOptions, I18nPluginOptions, I18nScope, diff --git a/packages/vue-i18n-core/src/devtools.ts b/packages/vue-i18n-core/src/devtools.ts index 2ba48bce6..07b726e06 100644 --- a/packages/vue-i18n-core/src/devtools.ts +++ b/packages/vue-i18n-core/src/devtools.ts @@ -25,7 +25,6 @@ import type { import type { App, ComponentInternalInstance } from 'vue' import type { Composer } from './composer' import type { I18n, I18nInternal } from './i18n' -import type { VueI18nInternal } from './legacy' type _I18n = I18n & I18nInternal @@ -73,23 +72,10 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise { componentInstance.vnode.el.__VUE_I18N__ && instanceData ) { - if (i18n.mode === 'legacy') { - // ignore global scope on legacy mode - if ( - componentInstance.vnode.el.__VUE_I18N__ !== - (i18n.global as unknown as VueI18nInternal).__composer - ) { - inspectComposer( - instanceData, - componentInstance.vnode.el.__VUE_I18N__ as Composer - ) - } - } else { - inspectComposer( - instanceData, - componentInstance.vnode.el.__VUE_I18N__ as Composer - ) - } + inspectComposer( + instanceData, + componentInstance.vnode.el.__VUE_I18N__ as Composer + ) } }) @@ -175,9 +161,7 @@ function updateComponentTreeTags( i18n: _I18n ): void { // prettier-ignore - const global = i18n.mode === 'composition' - ? i18n.global - : (i18n.global as unknown as VueI18nInternal).__composer + const global = i18n.global if (instance && instance.vnode.el && instance.vnode.el.__VUE_I18N__) { // add custom tags local scope only if (instance.vnode.el.__VUE_I18N__ !== global) { @@ -295,14 +279,10 @@ function registerScope( label: 'Global Scope' }) // prettier-ignore - const global = i18n.mode === 'composition' - ? i18n.global - : (i18n.global as unknown as VueI18nInternal).__composer + const global = i18n.global for (const [keyInstance, instance] of i18n.__instances) { // prettier-ignore - const composer = i18n.mode === 'composition' - ? instance - : (instance as unknown as VueI18nInternal).__composer + const composer = instance if (global === composer) { continue } @@ -333,17 +313,13 @@ function getComponentInstance( function getComposer(nodeId: string, i18n: _I18n): Composer | null { if (nodeId === 'global') { - return i18n.mode === 'composition' - ? (i18n.global as unknown as Composer) - : (i18n.global as unknown as VueI18nInternal).__composer + return i18n.global } else { const instance = Array.from(i18n.__instances.values()).find( item => item.id.toString() === nodeId ) if (instance) { - return i18n.mode === 'composition' - ? (instance as unknown as Composer) - : (instance as unknown as VueI18nInternal).__composer + return instance } else { return null } diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index 5978aebaa..599c11d1f 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -5,8 +5,7 @@ import { isEmptyObject, isPlainObject, makeSymbol, - warn, - warnOnce + warn } from '@intlify/shared' import { effectScope, @@ -19,15 +18,8 @@ import { import { createComposer } from './composer' import { addTimelineEvent, enableDevTools } from './devtools' import { I18nErrorCodes, createI18nError } from './errors' -import { createVueI18n } from './legacy' -import { defineMixin } from './mixins' import { apply as applyPlugin } from './plugin/next' -import { - DisableEmitter, - DisposeSymbol, - EnableEmitter, - InejctWithOptionSymbol -} from './symbols' +import { DisableEmitter, DisposeSymbol, EnableEmitter } from './symbols' import { adjustI18nResources, getComponentOptions } from './utils' import { I18nWarnCodes, getWarnMessage } from './warnings' @@ -56,12 +48,6 @@ import type { DefaultNumberFormatSchema, VueMessageType } from './composer' -import type { - VueI18n, - VueI18nExtender, - VueI18nInternal, - VueI18nOptions -} from './legacy' import type { Disposer } from './types' /** @@ -90,11 +76,7 @@ export type I18nOptions< numberFormats: unknown } | string = Locale, - Options extends - | ComposerOptions - | VueI18nOptions = - | ComposerOptions - | VueI18nOptions + Options = ComposerOptions > = I18nAdditionalOptions & Options /** @@ -106,19 +88,6 @@ export type I18nOptions< * @VueI18nGeneral */ export interface I18nAdditionalOptions { - /** - * Whether vue-i18n Legacy API mode use on your Vue App - * - * @remarks - * The default is to use the Legacy API mode. If you want to use the Composition API mode, you need to set it to `false`. - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nSee [Composition API](../../guide/advanced/composition) - * - * @defaultValue `true` - */ - legacy?: boolean /** * Whether to inject global properties & functions into for each component. * @@ -133,17 +102,6 @@ export interface I18nAdditionalOptions { globalInjection?: boolean } -/** - * Vue I18n API mode - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nSee [I18n#mode](general#mode) - * - * @VueI18nGeneral - */ -export type I18nMode = 'legacy' | 'composition' - /** * I18n instance * @@ -156,34 +114,15 @@ export interface I18n< Messages extends Record = {}, DateTimeFormats extends Record = {}, NumberFormats extends Record = {}, - OptionLocale = Locale, - Legacy = boolean + OptionLocale = Locale > { - /** - * Vue I18n API mode - * - * @remarks - * If you specified `legacy: true` option in `createI18n`, return `legacy`, else `composition` - * - * @deprecated will be removed at vue-i18n v12 - * - * @defaultValue `'legacy'` - */ - readonly mode: I18nMode // prettier-ignore /** * The property accessible to the global Composer instance or VueI18n instance * - * @remarks - * If the [I18n#mode](general#mode) is `'legacy'`, then you can access to a global {@link VueI18n} instance, else then [I18n#mode](general#mode) is `'composition' `, you can access to the global {@link Composer} instance. - * * An instance of this property is **global scope***. */ - readonly global: Legacy extends true - ? VueI18n - : Legacy extends false - ? Composer - : unknown + readonly global: Composer /** * Install entry point * @@ -207,10 +146,6 @@ export type ComposerExtender = (composer: Composer) => Disposer | undefined */ type ExtendHooks = { __composerExtend?: ComposerExtender - /** - * @deprecated will be removed at vue-i18n v12 - */ - __vueI18nExtend?: VueI18nExtender } /** @@ -226,30 +161,31 @@ export interface I18nInternal< > { __instances: Map< ComponentInternalInstance, - | VueI18n - | Composer + Composer > __getInstance< - Instance extends - | VueI18n - | Composer + Instance extends Composer< + Messages, + DateTimeFormats, + NumberFormats, + OptionLocale + > >( component: ComponentInternalInstance ): Instance | null __setInstance< - Instance extends - | VueI18n - | Composer + Instance extends Composer< + Messages, + DateTimeFormats, + NumberFormats, + OptionLocale + > >( component: ComponentInternalInstance, instance: Instance ): void __deleteInstance(component: ComponentInternalInstance): void __composerExtend?: ComposerExtender - /** - * @deprecated will be removed at vue-i18n v12 - */ - __vueI18nExtend?: VueI18nExtender } /** @@ -322,7 +258,6 @@ export const I18nInjectionKey: InjectionKey | string = /* #__PURE__*/ makeSymbol('global-vue-i18n') export function createI18n< - Legacy extends boolean = true, Options extends I18nOptions = I18nOptions, Messages extends Record = Options['messages'] extends Record< string, @@ -345,11 +280,7 @@ export function createI18n< OptionLocale = Options['locale'] extends string ? Options['locale'] : Locale >( options: Options -): (typeof options)['legacy'] extends true - ? I18n - : (typeof options)['legacy'] extends false - ? I18n - : I18n +): I18n /** * Vue I18n factory @@ -358,53 +289,19 @@ export function createI18n< * * @typeParam Schema - The i18n resources (messages, datetimeFormats, numberFormats) schema, default {@link LocaleMessage} * @typeParam Locales - The locales of i18n resource schema, default `en-US` - * @typeParam Legacy - Whether legacy mode is enabled or disabled, default `true` * * @returns {@link I18n} instance * - * @remarks - * If you use Legacy API mode, you need to specify {@link VueI18nOptions} and `legacy: true` option. - * - * If you use composition API mode, you need to specify {@link ComposerOptions}. - * * @VueI18nSee [Getting Started](../../guide/essentials/started) * @VueI18nSee [Composition API](../../guide/advanced/composition) * * @example - * case: for Legacy API - * ```js - * import { createApp } from 'vue' - * import { createI18n } from 'vue-i18n' - * - * // call with I18n option - * const i18n = createI18n({ - * locale: 'ja', - * messages: { - * en: { ... }, - * ja: { ... } - * } - * }) - * - * const App = { - * // ... - * } - * - * const app = createApp(App) - * - * // install! - * app.use(i18n) - * app.mount('#app') - * ``` - * - * @example - * case: for composition API * ```js * import { createApp } from 'vue' * import { createI18n, useI18n } from 'vue-i18n' * * // call with I18n option * const i18n = createI18n({ - * legacy: false, // you must specify 'legacy: false' option * locale: 'ja', * messages: { * en: { ... }, @@ -432,7 +329,6 @@ export function createI18n< export function createI18n< Schema extends object = DefaultLocaleMessageSchema, Locales extends string | object = 'en-US', - Legacy extends boolean = true, Options extends I18nOptions< SchemaParams, LocaleParams @@ -455,45 +351,30 @@ export function createI18n< OptionLocale = Options['locale'] extends string ? Options['locale'] : Locale >( options: Options -): (typeof options)['legacy'] extends true - ? I18n - : (typeof options)['legacy'] extends false - ? I18n - : I18n +): I18n // eslint-disable-next-line @typescript-eslint/no-explicit-any export function createI18n(options: any = {}): any { type _I18n = I18n & I18nInternal - // prettier-ignore - const __legacyMode = __LITE__ - ? false - : __FEATURE_LEGACY_API__ && isBoolean(options.legacy) - ? options.legacy - : __FEATURE_LEGACY_API__ - - if (__DEV__ && __legacyMode) { - warnOnce(getWarnMessage(I18nWarnCodes.DEPRECATE_LEGACY_MODE)) - } - // prettier-ignore const __globalInjection = isBoolean(options.globalInjection) ? options.globalInjection : true - const __instances = new Map() - const [globalScope, __global] = createGlobal(options, __legacyMode) + const __instances = new Map() + const [globalScope, __global] = createGlobal(options) const symbol: InjectionKey | string = /* #__PURE__*/ makeSymbol( __DEV__ ? 'vue-i18n' : '' ) - function __getInstance( + function __getInstance( component: ComponentInternalInstance - ): Instance | null { - return (__instances.get(component) as unknown as Instance) || null + ): Composer | null { + return __instances.get(component) || null } - function __setInstance( + function __setInstance( component: ComponentInternalInstance, - instance: Instance + instance: Composer ): void { __instances.set(component, instance) } @@ -503,10 +384,8 @@ export function createI18n(options: any = {}): any { const i18n = { // mode - get mode(): I18nMode { - return !__LITE__ && __FEATURE_LEGACY_API__ && __legacyMode - ? 'legacy' - : 'composition' + get mode() { + return 'composition' }, // install plugin async install(app: App, ...options: unknown[]): Promise { @@ -525,14 +404,12 @@ export function createI18n(options: any = {}): any { // so we keep it temporary ;(i18n as unknown as I18nInternal).__composerExtend = opts.__composerExtend - ;(i18n as unknown as I18nInternal).__vueI18nExtend = - opts.__vueI18nExtend } // global method and properties injection for Composition API let globalReleaseHandler: ReturnType | null = null - if (!__legacyMode && __globalInjection) { + if (__globalInjection) { globalReleaseHandler = injectGlobalFields(app, i18n.global as Composer) } @@ -541,17 +418,6 @@ export function createI18n(options: any = {}): any { applyPlugin(app, ...options) } - // setup mixin for Legacy API - if (!__LITE__ && __FEATURE_LEGACY_API__ && __legacyMode) { - app.mixin( - defineMixin( - __global as unknown as VueI18n, - (__global as unknown as VueI18nInternal).__composer as Composer, - i18n as unknown as I18nInternal - ) - ) - } - // release global scope const unmountApp = app.unmount app.unmount = () => { @@ -568,14 +434,9 @@ export function createI18n(options: any = {}): any { } const emitter: VueDevToolsEmitter = createEmitter() - if (__legacyMode) { - const _vueI18n = __global as unknown as VueI18nInternal - _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter) - } else { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const _composer = __global as any - _composer[EnableEmitter] && _composer[EnableEmitter](emitter) - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const _composer = __global as any + _composer[EnableEmitter] && _composer[EnableEmitter](emitter) emitter.on('*', addTimelineEvent) } }, @@ -767,15 +628,9 @@ export function useI18n< > } -function createGlobal( - options: I18nOptions, - legacyMode: boolean -): [EffectScope, VueI18n | Composer] { +function createGlobal(options: I18nOptions): [EffectScope, Composer] { const scope = effectScope() - const obj = - !__LITE__ && __FEATURE_LEGACY_API__ && legacyMode - ? scope.run(() => createVueI18n(options)) - : scope.run(() => createComposer(options)) + const obj = scope.run(() => createComposer(options)) if (obj == null) { throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR) } @@ -813,9 +668,7 @@ function getScope(options: UseI18nOptions, componentOptions: any): I18nScope { function getGlobalComposer(i18n: I18n): Composer { // prettier-ignore - return i18n.mode === 'composition' - ? (i18n.global as unknown as Composer) - : (i18n.global as unknown as VueI18nInternal).__composer + return i18n.global } function getComposer( @@ -831,24 +684,8 @@ function getComposer( ) while (current != null) { const i18nInternal = i18n as unknown as I18nInternal - if (i18n.mode === 'composition') { - composer = i18nInternal.__getInstance(current) - } else { - if (!__LITE__ && __FEATURE_LEGACY_API__) { - const vueI18n = i18nInternal.__getInstance(current) - if (vueI18n != null) { - composer = (vueI18n as VueI18n & VueI18nInternal) - .__composer as Composer - if ( - useComponent && - composer && - !(composer as any)[InejctWithOptionSymbol] // eslint-disable-line @typescript-eslint/no-explicit-any - ) { - composer = null - } - } - } - } + composer = i18nInternal.__getInstance(current) + if (composer != null) { break } diff --git a/packages/vue-i18n-core/src/index.ts b/packages/vue-i18n-core/src/index.ts index 18940c5c4..ab87baa54 100644 --- a/packages/vue-i18n-core/src/index.ts +++ b/packages/vue-i18n-core/src/index.ts @@ -76,7 +76,6 @@ export type { ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nMode, I18nOptions, I18nScope, UseI18nOptions diff --git a/packages/vue-i18n-core/src/misc.ts b/packages/vue-i18n-core/src/misc.ts index 67640a09c..71f8d8b4c 100644 --- a/packages/vue-i18n-core/src/misc.ts +++ b/packages/vue-i18n-core/src/misc.ts @@ -21,10 +21,6 @@ export function initFeatureFlags(): void { getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true } - if (typeof __FEATURE_LEGACY_API__ !== 'boolean') { - getGlobalThis().__VUE_I18N_LEGACY_API__ = true - } - if (typeof __FEATURE_DROP_MESSAGE_COMPILER__ !== 'boolean') { getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false } diff --git a/packages/vue-i18n-core/src/mixins.ts b/packages/vue-i18n-core/src/mixins.ts deleted file mode 100644 index 6794aca8c..000000000 --- a/packages/vue-i18n-core/src/mixins.ts +++ /dev/null @@ -1,216 +0,0 @@ -import { createEmitter } from '@intlify/shared' -import { getCurrentInstance } from 'vue' -import { addTimelineEvent } from './devtools' -import { createI18nError, I18nErrorCodes } from './errors' -import { createVueI18n } from './legacy' -import { SetPluralRulesSymbol } from './symbols' -import { adjustI18nResources, getLocaleMessages } from './utils' - -import type { Locale, LocaleMessageValue } from '@intlify/core' -import type { Path } from '@intlify/core-base' -import type { - VueDevToolsEmitter, - VueDevToolsEmitterEvents -} from '@intlify/devtools-types' -import type { ComponentOptions } from 'vue' -import type { - Composer, - ComposerInternalOptions, - ComposerOptions, - VueMessageType -} from './composer' -import type { I18nInternal } from './i18n' -import type { - DateTimeFormatResult, - NumberFormatResult, - TranslateResult, - VueI18n, - VueI18nInternal, - VueI18nInternalOptions, - VueI18nOptions -} from './legacy' - -/** - * Supports compatibility for legacy vue-i18n APIs - * This mixin is used when we use vue-i18n@v9.x or later - */ -export function defineMixin( - vuei18n: VueI18n, - composer: Composer, - i18n: I18nInternal -): ComponentOptions { - return { - beforeCreate(): void { - const instance = getCurrentInstance() - /* istanbul ignore if */ - if (!instance) { - throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR) - } - - const options = this.$options - if (options.i18n) { - const optionsI18n = options.i18n as VueI18nOptions & - VueI18nInternalOptions & - ComposerInternalOptions - - if (options.__i18n) { - optionsI18n.__i18n = options.__i18n - } - optionsI18n.__root = composer - if (this === this.$root) { - // merge option and gttach global - this.$i18n = mergeToGlobal(vuei18n, optionsI18n) - } else { - optionsI18n.__injectWithOption = true - optionsI18n.__extender = i18n.__vueI18nExtend - // atttach local VueI18n instance - this.$i18n = createVueI18n(optionsI18n) - // extend VueI18n instance - const _vueI18n = this.$i18n as unknown as VueI18nInternal - if (_vueI18n.__extender) { - _vueI18n.__disposer = _vueI18n.__extender(this.$i18n) - } - } - } else if (options.__i18n) { - if (this === this.$root) { - // merge option and gttach global - this.$i18n = mergeToGlobal(vuei18n, options) - } else { - // atttach local VueI18n instance - this.$i18n = createVueI18n({ - __i18n: (options as ComposerInternalOptions).__i18n, - __injectWithOption: true, - __extender: i18n.__vueI18nExtend, - __root: composer - } as VueI18nOptions & VueI18nInternalOptions) - // extend VueI18n instance - const _vueI18n = this.$i18n as unknown as VueI18nInternal - if (_vueI18n.__extender) { - _vueI18n.__disposer = _vueI18n.__extender(this.$i18n) - } - } - } else { - // attach global VueI18n instance - this.$i18n = vuei18n - } - - if (options.__i18nGlobal) { - adjustI18nResources(composer, options as ComposerOptions, options) - } - - // defines vue-i18n legacy APIs - this.$t = (...args: unknown[]): TranslateResult => this.$i18n.t(...args) - this.$rt = (...args: unknown[]): TranslateResult => this.$i18n.rt(...args) - this.$te = (key: Path, locale?: Locale): boolean => - this.$i18n.te(key, locale) - this.$d = (...args: unknown[]): DateTimeFormatResult => - this.$i18n.d(...args) - this.$n = (...args: unknown[]): NumberFormatResult => - this.$i18n.n(...args) - this.$tm = (key: Path): LocaleMessageValue | {} => - this.$i18n.tm(key) - - i18n.__setInstance(instance, this.$i18n as VueI18n) - }, - - mounted(): void { - /* istanbul ignore if */ - if ( - (__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && - !__NODE_JS__ && - this.$el && - this.$i18n - ) { - const _vueI18n = this.$i18n as unknown as VueI18nInternal - this.$el.__VUE_I18N__ = _vueI18n.__composer - const emitter: VueDevToolsEmitter = (this.__v_emitter = - createEmitter()) - _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter) - emitter.on('*', addTimelineEvent) - } - }, - - unmounted(): void { - const instance = getCurrentInstance() - /* istanbul ignore if */ - if (!instance) { - throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR) - } - - const _vueI18n = this.$i18n as unknown as VueI18nInternal - - /* istanbul ignore if */ - if ( - (__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && - !__NODE_JS__ && - this.$el && - this.$el.__VUE_I18N__ - ) { - if (this.__v_emitter) { - this.__v_emitter.off('*', addTimelineEvent) - delete this.__v_emitter - } - if (this.$i18n) { - _vueI18n.__disableEmitter && _vueI18n.__disableEmitter() - delete this.$el.__VUE_I18N__ - } - } - - delete this.$t - delete this.$rt - delete this.$te - delete this.$d - delete this.$n - delete this.$tm - - if (_vueI18n.__disposer) { - _vueI18n.__disposer() - delete _vueI18n.__disposer - delete _vueI18n.__extender - } - - i18n.__deleteInstance(instance) - delete this.$i18n - } - } -} - -function mergeToGlobal( - g: VueI18n, - options: VueI18nOptions & ComposerInternalOptions -): VueI18n { - g.locale = options.locale || g.locale - g.fallbackLocale = options.fallbackLocale || g.fallbackLocale - g.missing = options.missing || g.missing - g.silentTranslationWarn = - options.silentTranslationWarn || g.silentFallbackWarn - g.silentFallbackWarn = options.silentFallbackWarn || g.silentFallbackWarn - g.formatFallbackMessages = - options.formatFallbackMessages || g.formatFallbackMessages - g.postTranslation = options.postTranslation || g.postTranslation - g.warnHtmlInMessage = options.warnHtmlInMessage || g.warnHtmlInMessage - g.escapeParameterHtml = options.escapeParameterHtml || g.escapeParameterHtml - g.sync = options.sync || g.sync - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ;(g as any).__composer[SetPluralRulesSymbol]( - options.pluralizationRules || g.pluralizationRules - ) - const messages = getLocaleMessages(g.locale as Locale, { - messages: options.messages, - __i18n: options.__i18n - }) - Object.keys(messages).forEach(locale => - g.mergeLocaleMessage(locale, messages[locale]) - ) - if (options.datetimeFormats) { - Object.keys(options.datetimeFormats).forEach(locale => - g.mergeDateTimeFormat(locale, options.datetimeFormats![locale]) - ) - } - if (options.numberFormats) { - Object.keys(options.numberFormats).forEach(locale => - g.mergeNumberFormat(locale, options.numberFormats![locale]) - ) - } - return g -} diff --git a/packages/vue-i18n-core/src/petite.ts b/packages/vue-i18n-core/src/petite.ts index bb80756fd..c3031f00d 100644 --- a/packages/vue-i18n-core/src/petite.ts +++ b/packages/vue-i18n-core/src/petite.ts @@ -58,7 +58,6 @@ export type { ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nMode, I18nOptions, I18nScope, UseI18nOptions diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index dca19b3d1..409f75fc1 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -91,7 +91,6 @@ export type { I18n, I18nAdditionalOptions, I18nD, - I18nMode, I18nN, I18nOptions, I18nPluginOptions, diff --git a/packages/vue-i18n/src/runtime.ts b/packages/vue-i18n/src/runtime.ts index 76e24f07f..72664e491 100644 --- a/packages/vue-i18n/src/runtime.ts +++ b/packages/vue-i18n/src/runtime.ts @@ -90,7 +90,6 @@ export type { I18n, I18nAdditionalOptions, I18nD, - I18nMode, I18nN, I18nOptions, I18nPluginOptions, From 8164fef68bb2787a65c4428cf07fb22dc830f09c Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 17:37:52 +0900 Subject: [PATCH 02/18] fix test --- packages/vue-i18n-core/test/i18n.test-d.ts | 82 +-- packages/vue-i18n-core/test/i18n.test.ts | 628 +-------------------- packages/vue-i18n-core/test/issues.test.ts | 280 --------- packages/vue-i18n-core/test/mixin.test.ts | 264 --------- packages/vue-i18n-core/test/wc.test.ts | 6 +- 5 files changed, 50 insertions(+), 1210 deletions(-) delete mode 100644 packages/vue-i18n-core/test/mixin.test.ts diff --git a/packages/vue-i18n-core/test/i18n.test-d.ts b/packages/vue-i18n-core/test/i18n.test-d.ts index fc3d7d62a..7d02780a7 100644 --- a/packages/vue-i18n-core/test/i18n.test-d.ts +++ b/packages/vue-i18n-core/test/i18n.test-d.ts @@ -7,6 +7,7 @@ import type { PickupFallbackLocales } from '@intlify/core-base' import type { MyDatetimeScehma, MyNumberSchema, ResourceSchema } from './schema' +import { ComputedRef, WritableComputedRef } from 'vue' beforeEach(() => { // allow mocking @@ -54,7 +55,6 @@ const looseOptions = { // strict options const strictOptions = { locale: 'en', - legacy: false, fallbackLocale: { ja: ['en'] }, @@ -309,8 +309,7 @@ test('local scope without type annotation at useI18n', () => { test('loose i18n', () => { // with object spread and composer const looseI18nComposer = createI18n({ - ...looseOptions, - legacy: false + ...looseOptions }).global expectTypeOf(looseI18nComposer.locale.value).toEqualTypeOf< @@ -346,41 +345,49 @@ test('loose i18n', () => { const looseI18n = createI18n(looseOptions).global expectTypeOf(looseI18n.locale).toEqualTypeOf< - 'en' | 'ja' | 'en-US' | 'ja-JP' + WritableComputedRef<'en' | 'ja' | 'en-US' | 'ja-JP'> >() expectTypeOf(looseI18n.fallbackLocale).toEqualTypeOf< - | 'en' - | 'ja' - | 'en-US' - | 'ja-JP' - | ('en' | 'ja' | 'en-US' | 'ja-JP')[] - | { - [x in string]: PickupFallbackLocales< - ['en' | 'ja' | 'en-US' | 'ja-JP'] - >[] - } - | false + WritableComputedRef< + | 'en' + | 'ja' + | 'en-US' + | 'ja-JP' + | ('en' | 'ja' | 'en-US' | 'ja-JP')[] + | { + [x in string]: PickupFallbackLocales< + ['en' | 'ja' | 'en-US' | 'ja-JP'] + >[] + } + | false + > >() - expectTypeOf(looseI18n.messages).toEqualTypeOf<{ - en: { - foo: string - nest: { - bar: string + expectTypeOf(looseI18n.messages).toEqualTypeOf< + ComputedRef<{ + en: { + foo: string + nest: { + bar: string + } } - } - ja: { - bar: string - nest: { + ja: { bar: string + nest: { + bar: string + } } - } - }>() - expectTypeOf(looseI18n.datetimeFormats).toEqualTypeOf<{ - 'en-US': { short: {} } - }>() - expectTypeOf(looseI18n.numberFormats).toEqualTypeOf<{ - 'ja-JP': { currency: {} } - }>() + }> + >() + expectTypeOf(looseI18n.datetimeFormats).toEqualTypeOf< + ComputedRef<{ + 'en-US': { short: {} } + }> + >() + expectTypeOf(looseI18n.numberFormats).toEqualTypeOf< + ComputedRef<{ + 'ja-JP': { currency: {} } + }> + >() expectTypeOf(looseI18n.t('nest.bar')).toEqualTypeOf() expectTypeOf(looseI18n.t('nest', 'en')).toEqualTypeOf() expectTypeOf(looseI18n.t('foo', [1])).toEqualTypeOf() @@ -399,7 +406,7 @@ test('loose i18n', () => { >() expectTypeOf(looseI18n.rt('foo')).toEqualTypeOf() expectTypeOf(looseI18n.getLocaleMessage('en')).toEqualTypeOf< - typeof looseI18n.messages.en + typeof looseI18n.messages.value.en >() expectTypeOf( looseI18n.getLocaleMessage<{ japan: string }>('japan') @@ -423,7 +430,7 @@ test('loose i18n', () => { }) expectTypeOf(looseI18n.getDateTimeFormat('en-US')).toEqualTypeOf< - (typeof looseI18n.datetimeFormats)['en-US'] + (typeof looseI18n.datetimeFormats.value)['en-US'] >() expectTypeOf( looseI18n.getLocaleMessage<{ long: { hour: string } }>('en-US') @@ -445,7 +452,7 @@ test('loose i18n', () => { }) expectTypeOf(looseI18n.getNumberFormat('ja-JP')).toEqualTypeOf< - (typeof looseI18n.numberFormats)['ja-JP'] + (typeof looseI18n.numberFormats.value)['ja-JP'] >() expectTypeOf( looseI18n.getNumberFormat<{ weight: { unit: string } }>('en-US') @@ -470,7 +477,7 @@ test('loose i18n', () => { }) test('strict i18n', () => { - const strictI18n = createI18n<[ResourceSchema], 'en' | 'ja', false>( + const strictI18n = createI18n<[ResourceSchema], 'en' | 'ja'>( strictOptions ).global @@ -548,8 +555,7 @@ test('strict i18n with direct i18n options', () => { datetime: MyDatetimeScehma number: MyNumberSchema }, - { messages: 'en'; datetimeFormats: 'ja-JP' | 'zh'; numberFormats: 'ca' }, - false + { messages: 'en'; datetimeFormats: 'ja-JP' | 'zh'; numberFormats: 'ca' } >({ messages: { en: { diff --git a/packages/vue-i18n-core/test/i18n.test.ts b/packages/vue-i18n-core/test/i18n.test.ts index 3826dcdf8..cd265f895 100644 --- a/packages/vue-i18n-core/test/i18n.test.ts +++ b/packages/vue-i18n-core/test/i18n.test.ts @@ -39,7 +39,6 @@ import type { IntlifyDevToolsEmitterHooks } from '@intlify/devtools-types' import type { App, ComponentOptions } from 'vue' import type { Composer } from '../src/composer' import type { I18n } from '../src/i18n' -import type { VueI18n } from '../src/legacy' /* eslint-disable @typescript-eslint/no-explicit-any */ // allow any in error const container = document.createElement('div') @@ -59,38 +58,9 @@ afterEach(() => { setDevToolsHook(null) }) -describe('createI18n', () => { - test('legacy mode', () => { - const i18n = createI18n({}) - - expect(i18n.mode).toEqual('legacy') - }) - - test('composition mode', () => { - const i18n = createI18n({ - legacy: false - }) - - expect(i18n.mode).toEqual('composition') - }) -}) - describe('createI18n with flat json messages', () => { - test('legacy mode', () => { - const i18n = createI18n({ - flatJson: true, - messages: { - en: { 'mainMenu.buttonStart': 'Start!' } - } - }) - const messages = i18n.global.messages - // @ts-ignore - expect(messages.en.mainMenu.buttonStart).toEqual('Start!') - }) - test('composition mode', () => { - const i18n = createI18n({ - legacy: false, + const i18n = createI18n({ flatJson: true, messages: { en: { 'mainMenu.buttonStart': 'Start!' } @@ -116,7 +86,6 @@ describe('useI18n', () => { test('basic', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -149,7 +118,6 @@ describe('useI18n', () => { test('global scope', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -172,35 +140,8 @@ describe('useI18n', () => { expect((composer as Composer).locale.value).toEqual('ja') }) - test('global scope with legacy mode', async () => { - const i18n = createI18n({ - allowComposition: true, - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ - setup() { - const { locale, t } = useI18n({ - useScope: 'global' - }) - return { locale, t } - }, - i18n: {}, - template: `

{{ locale }}:{{ t('hello') }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

en:hello!

') - }) - test('parent scope', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -245,7 +186,6 @@ describe('useI18n', () => { test('not found parent composer with parent scope', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -278,7 +218,6 @@ describe('useI18n', () => { test('empty options', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -303,7 +242,6 @@ describe('useI18n', () => { test('empty options, when have i18n custom blocks', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -354,7 +292,6 @@ describe('useI18n', () => { test(errorMessages[I18nErrorCodes.NOT_INSTALLED], async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -378,224 +315,12 @@ describe('useI18n', () => { expect(error).toEqual(errorMessages[I18nErrorCodes.NOT_INSTALLED]) }) - describe('On legacy', () => { - describe('enable', () => { - describe('t', () => { - test('translation & locale changing', async () => { - const i18n = createI18n({ - allowComposition: true, - locale: 'ja', - messages: { - en: { - hello: 'hello!' - }, - ja: { - hello: 'こんにちは!' - } - } - }) - - const App = defineComponent({ - setup() { - const { locale, t } = useI18n() - return { locale, t } - }, - template: `

{{ t('hello') }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

こんにちは!

') - - i18n.global.locale = 'en' - await nextTick() - expect(html()).toEqual('

hello!

') - }) - - test('local scope', async () => { - const i18n = createI18n({ - allowComposition: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - }, - ja: {} - } - }) - - const App = defineComponent({ - setup() { - const { locale, t } = useI18n({ - useScope: 'local', - messages: { - en: { - world: 'world!' - }, - ja: { - world: '世界!' - } - } - }) - return { locale, t } - }, - i18n: {}, - template: `

{{ locale }}:{{ t('world') }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

en:world!

') - - i18n.global.locale = 'ja' - await nextTick() - expect(html()).toEqual('

ja:世界!

') - }) - - 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: `

{{ locale }}:{{ t('hello') }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

ja:こんにちは!

') - }) - }) - }) - - describe('d', () => { - test('datetime formatting', async () => { - const i18n = createI18n({ - allowComposition: true, - locale: 'en-US', - fallbackLocale: ['ja-JP'], - datetimeFormats: { - 'en-US': { - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - timeZone: 'America/New_York' - } - }, - 'ja-JP': { - long: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - timeZone: 'Asia/Tokyo' - }, - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - timeZone: 'Asia/Tokyo' - } - } - } - }) - - const App = defineComponent({ - setup() { - const { d } = useI18n() - const dt = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) - return { d, dt } - }, - template: `

{{ d(dt, 'long') }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

2012/12/20 12:00:00

') - }) - }) - - describe('n', () => { - test('number formatting', async () => { - const i18n = createI18n({ - allowComposition: true, - locale: 'en-US', - fallbackLocale: ['ja-JP'], - numberFormats: { - 'en-US': { - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - }, - decimal: { - style: 'decimal', - useGrouping: false - } - }, - 'ja-JP': { - currency: { - style: 'currency', - currency: 'JPY' /*, currencyDisplay: 'symbol'*/ - }, - numeric: { - style: 'decimal', - useGrouping: false - }, - percent: { - style: 'percent', - useGrouping: false - } - } - } - }) - - const App = defineComponent({ - setup() { - const { n } = useI18n() - const value = 0.99 - return { n, value } - }, - template: `

{{ n(value, { key: 'percent' }) }}

` - }) - const { html } = await mount(App, i18n) - expect(html()).toEqual('

99%

') - }) - }) - }) - test(errorMessages[I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE], async () => { const randCusumerTag = `my-consumer-${randStr()}` const randProviderTag = `my-provider-${randStr()}` const Provider = defineCustomElement({ setup() { - createI18n({ legacy: false }) + createI18n({}) return () => h(randCusumerTag) } }) @@ -635,93 +360,8 @@ describe('slot reactivity', () => { console.warn = org }) - test('legacy', async () => { - const i18n = createI18n({ - locale: 'ja', - fallbackLocale: ['en'], - messages: { - en: { - hello: 'hello!' - }, - ja: { - hello: 'こんにちは!' - } - } - }) - - const SlotChild = { - template: `

` - } - - const SubChild = { - template: ` -
-

Sub Child

-
- -
-

{{ $t('hello') }}

-
- ` - } - - const Child = { - components: { - SubChild, - SlotChild - }, - template: ` -
-

Child

-
- -
-

{{ $t('hello') }}

- - $t inside of slot - - {{ $t('hello') }} - - i18n-t inside of slot - - - -
- ` - } - - const App = defineComponent({ - components: { - Child - }, - template: ` -

Root

-
- -
-

{{ $t('hello') }}

- - ` - }) - const { html } = await mount(App, i18n) - expect(html()).toMatchSnapshot('ja') - i18n.global.locale = 'en' - await nextTick() - expect(html()).toMatchSnapshot('en') - }) - test('composable', async () => { - const i18n = createI18n({ - legacy: false, + const i18n = createI18n({ locale: 'ja', fallbackLocale: ['en'], messages: { @@ -816,7 +456,6 @@ describe('slot reactivity', () => { test('multi instance', async () => { const i18n1 = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -825,7 +464,6 @@ test('multi instance', async () => { } }) const i18n2 = createI18n({ - legacy: false, locale: 'en', messages: { ja: { @@ -857,7 +495,6 @@ test('multi instance', async () => { test('merge useI18n resources to global scope', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -933,7 +570,6 @@ test('merge useI18n resources to global scope', async () => { describe('merge i18n custom blocks to global scope', () => { test('composition mode', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { @@ -988,51 +624,6 @@ describe('merge i18n custom blocks to global scope', () => { foo: 'ふー!' }) }) - - test('legacy mode', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'ja', - messages: { - en: { - hi: { hello: 'hello!' } - }, - ja: { - hello: 'こんにちは!' - } - } - }) - - const App = defineComponent({ - __i18nGlobal: [ - { - locale: 'en', - resource: { - hi: { hi: 'hi!' }, - foo: 'foo!' - } - }, - { - locale: 'ja', - resource: { foo: 'ふー!' } - } - ], - template: `

foo

` - }) - await mount(App, i18n) - - expect(i18n.global.getLocaleMessage('en')).toEqual({ - hi: { - hi: 'hi!', - hello: 'hello!' - }, - foo: 'foo!' - }) - expect(i18n.global.getLocaleMessage('ja')).toEqual({ - hello: 'こんにちは!', - foo: 'ふー!' - }) - }) }) describe('custom pluralization', () => { @@ -1040,70 +631,8 @@ describe('custom pluralization', () => { // eslint-disable-next-line @typescript-eslint/no-empty-function mockWarn.mockImplementation(() => {}) - test('legacy', async () => { - const i18n = createI18n({ - locale: 'ru', - pluralizationRules: _pluralRules, - messages: { - ru: { - car: '0 машин | {n} машина | {n} машины | {n} машин' - } - } - }) - - const App = defineComponent({ - template: ` -

{{ $t('car', 1) }}

-

{{ $t('car', 2) }}

-

{{ $t('car', 4) }}

-

{{ $t('car', 12) }}

-

{{ $t('car', 21) }}

- ` - }) - const { find } = await mount(App, i18n) - await nextTick() - expect(find('p:nth-child(1)')!.innerHTML).toEqual('1 машина') - expect(find('p:nth-child(2)')!.innerHTML).toEqual('2 машины') - expect(find('p:nth-child(3)')!.innerHTML).toEqual('4 машины') - expect(find('p:nth-child(4)')!.innerHTML).toEqual('12 машин') - expect(find('p:nth-child(5)')!.innerHTML).toEqual('21 машина') - }) - - test('legacy + custom block', async () => { - const i18n = createI18n({ - locale: 'ru', - pluralizationRules: _pluralRules - }) - - const App = defineComponent({ - __i18n: [ - { - locale: 'ru', - resource: { - car: '0 машин | {n} машина | {n} машины | {n} машин' - } - } - ], - template: ` -

{{ $t('car', 1) }}

-

{{ $t('car', 2) }}

-

{{ $t('car', 4) }}

-

{{ $t('car', 12) }}

-

{{ $t('car', 21) }}

- ` - }) - const { find } = await mount(App, i18n) - await nextTick() - expect(find('p:nth-child(1)')!.innerHTML).toEqual('1 машина') - expect(find('p:nth-child(2)')!.innerHTML).toEqual('2 машины') - expect(find('p:nth-child(3)')!.innerHTML).toEqual('4 машины') - expect(find('p:nth-child(4)')!.innerHTML).toEqual('12 машин') - expect(find('p:nth-child(5)')!.innerHTML).toEqual('21 машина') - }) - test('composition', async () => { const i18n = createI18n({ - legacy: false, locale: 'ru', pluralRules: _pluralRules, messages: { @@ -1137,7 +666,6 @@ describe('custom pluralization', () => { test('composition + custom block', async () => { const i18n = createI18n({ - legacy: false, locale: 'ru' }) @@ -1223,7 +751,6 @@ describe('release global scope', () => { let error = '' try { const i18n = createI18n({ - legacy: false, locale: 'ja', messages: {} }) @@ -1251,9 +778,7 @@ describe('Composer & VueI18n extend hooking', () => { return composerDisposeSpy }) const vueI18nExtendSpy = vi.fn() - const i18n = createI18n({ - legacy: false - }) + const i18n = createI18n({}) const GrandChild = defineComponent({ setup() { @@ -1311,66 +836,6 @@ describe('Composer & VueI18n extend hooking', () => { app.unmount() expect(composerDisposeSpy).toHaveBeenCalledTimes(2) }) - - test('legacy', async () => { - const composerExtendSpy = vi.fn() - const vueI18nDisposeSpy = vi.fn() - let counter = 0 - const vueI18nExtendSpy = vi.fn().mockImplementation((vueI18n: VueI18n) => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - counter += 1 - ;(vueI18n as any).foo = `foo${counter}` - return vueI18nDisposeSpy - }) - const i18n = createI18n({ legacy: true }) - - const GrandChild = defineComponent({ - i18n: { - messages: { - en: { hello: 'hello, grand child!' } - } - }, - template: '{{ $i18n.foo }}' - }) - - const Child = defineComponent({ - components: { - GrandChild - }, - __i18n: [ - { - locale: '', - resource: { en: { hello: 'hello, child!' } } - } - ] as any, - template: '{{ $i18n.foo }}' - }) - const App = defineComponent({ - components: { - Child - }, - template: '

{{ $i18n.foo }}

' - }) - const { html, app } = await mount(App, i18n, { - pluginOptions: { - __composerExtend: composerExtendSpy, - __vueI18nExtend: vueI18nExtendSpy - } as any // eslint-disable-line @typescript-eslint/no-explicit-any - }) - - // Check that global is not extended - expect((i18n.global as any).foo).toBeUndefined() // eslint-disable-line @typescript-eslint/no-explicit-any - - expect(composerExtendSpy).not.toHaveBeenCalled() - expect(vueI18nExtendSpy).toHaveBeenCalledTimes(2) - expect(html()).toBe( - '

foo1foo2' - ) - - // dispose checking - app.unmount() - expect(vueI18nDisposeSpy).toHaveBeenCalledTimes(2) - }) }) describe('dollar prefixed API (component injections)', () => { @@ -1395,7 +860,6 @@ describe('dollar prefixed API (component injections)', () => { test('composition mode', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -1428,89 +892,6 @@ describe('dollar prefixed API (component injections)', () => { '

hello world!

hello, world!

hello, world!

no apples

りんご1個

default message

default msg

4 apples

default list msg

こんにちは、世界!

many apples

default named msg

こんにちは、世界!

hello world!

こんにちは、世界!

' ) }) - - test('legacy mode', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - const App = defineComponent({ - template: `
-

{{ $t('hello') }}

-

{{ $t('list', ['world']) }}

-

{{ $t('named', { name: 'world' }) }}

-

{{ $t('plural', 0) }}

-

{{ $t('plural', 1, { locale: 'ja' }) }}

-

{{ $t('default', 'default message') }}

-

{{ $t('default', 'default {msg}', { named: { msg: 'msg' } }) }}

-

{{ $t('plural', ['many'], 4) }}

-

{{ $t('default', ['list msg'], 'default {0}') }}

-

{{ $t('list', ['世界'], { locale: 'ja' }) }}

-

{{ $t('plural', { count: 'many' }, 4) }}

-

{{ $t('default', { msg: 'named msg' }, 'default {msg}') }}

-

{{ $t('named', { name: '世界' }, { locale: 'ja' }) }}

-

{{ $t('hello', {}, { locale: 'en' }) }}

-

{{ $t('hello', [], { locale: 'ja' }) }}

-
` - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual( - '

hello world!

hello, world!

hello, world!

no apples

りんご1個

default message

default msg

4 apples

default list msg

こんにちは、世界!

many apples

default named msg

こんにちは、世界!

hello world!

こんにちは、世界!

' - ) - }) -}) - -test('`t` on Legacy API mode', async () => { - const messages = { - en: { - hello: 'hello world!', - list: 'hello, {0}!', - named: 'hello, {name}!', - plural: 'no apples | one apple | {count} apples' - }, - ja: { - hello: 'こんにちは、世界!', - list: 'こんにちは、{0}!', - named: 'こんにちは、{name}!', - plural: 'りんご無い | りんご1個 | りんご{count}個' - } - } - - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - - expect(i18n.global.t('hello')).toEqual('hello world!') - expect(i18n.global.t('list', ['world'])).toEqual('hello, world!') - expect(i18n.global.t('named', { name: 'world' })).toEqual('hello, world!') - expect(i18n.global.t('plural', 0)).toEqual('no apples') - expect(i18n.global.t('plural', 1)).toEqual('one apple') - expect(i18n.global.t('default', 'default message')).toEqual('default message') - expect( - i18n.global.t('default', 'default {msg}', { named: { msg: 'msg' } }) - ).toEqual('default msg') - expect(i18n.global.t('plural', ['many'], 4)).toEqual('4 apples') - expect(i18n.global.t('default', ['list msg'], 'default {0}')).toEqual( - 'default list msg' - ) - expect(i18n.global.t('list', ['世界'], { locale: 'ja' })).toEqual( - 'こんにちは、世界!' - ) - expect(i18n.global.t('plural', { count: 'many' }, 4)).toEqual('many apples') - expect( - i18n.global.t('default', { msg: 'named msg' }, 'default {msg}') - ).toEqual('default named msg') - expect(i18n.global.t('named', { name: '世界' }, { locale: 'ja' })).toEqual( - 'こんにちは、世界!' - ) - expect(i18n.global.t('hello', {}, { locale: 'en' })).toEqual('hello world!') - expect(i18n.global.t('hello', [], { locale: 'ja' })).toEqual( - 'こんにちは、世界!' - ) }) test('`t` on Composition API mode', async () => { @@ -1530,7 +911,6 @@ test('`t` on Composition API mode', async () => { } const i18n = createI18n({ - legacy: false, locale: 'en', messages }) diff --git a/packages/vue-i18n-core/test/issues.test.ts b/packages/vue-i18n-core/test/issues.test.ts index 09c060c87..b08d9349b 100644 --- a/packages/vue-i18n-core/test/issues.test.ts +++ b/packages/vue-i18n-core/test/issues.test.ts @@ -131,99 +131,7 @@ const numberFormats: IntlNumberFormats = { } } -test('issue #708', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - - const C2 = defineComponent({ - template: `
C2 slot:
` - }) - - const C1 = defineComponent({ - components: { - C2 - }, - template: `
- C1: -
{{ $t("hello", { world: $t("world") }) }}
- - - - -
- - -
{{ $t("hello", { world: $t("world") }) }}
- - - -
-
`, - i18n: { - messages: { - en: { - hello: 'Hello {world}', - world: 'world!' - } - } - } - }) - - const App = defineComponent({ - components: { - C1 - }, - template: `` - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual( - `
C1:
Hello world!
Hello world!

C2 slot:
Hello world!
Hello world!
` - ) -}) - describe('issue #722', () => { - test('legacy', async () => { - const messages = { - en: { language: 'English' }, - ja: { language: '日本語' } - } - - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - - const App = defineComponent({ - template: ` - - - - `, - i18n: { - messages: { - en: { - hello: 'Hello {world}', - world: 'world!' - } - } - } - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual(`

Hello world!

`) - }) - test('composition', async () => { const messages = { en: { language: 'English' }, @@ -231,7 +139,6 @@ describe('issue #722', () => { } const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -262,43 +169,6 @@ describe('issue #722', () => { expect(wrapper.html()).toEqual(`

Hello world!

`) }) - test('v-if: legacy', async () => { - const messages = { - en: { language: 'English' }, - ja: { language: '日本語' } - } - - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - - const App = defineComponent({ - data() { - return { flag: true } - }, - template: `
- - - -
`, - i18n: { - messages: { - en: { - hello: 'Hello {world}', - world: 'world!' - } - } - } - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual(`

Hello world!

`) - }) - test('v-if: composition', async () => { const messages = { en: { language: 'English' }, @@ -306,7 +176,6 @@ describe('issue #722', () => { } const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -347,95 +216,8 @@ describe('issue #722', () => { }) }) -test('issue #729', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages - }) - - const C3 = defineComponent({ - template: `
C3 slot:
`, - i18n: { - messages: { - en: { - hello: 'Hello {world} - C3', - world: 'world! - C3' - } - } - } - }) - - const C2 = defineComponent({ - template: `
C2 slot:
`, - i18n: { - messages: { - en: { - goodbuy: 'Goodbuy!' - } - } - } - }) - - const C1 = defineComponent({ - components: { - C2, - C3 - }, - template: `
- C1: -
{{ $t("hello", { world: $t("world") }) }}
- - - - -
- - -
{{ $t("hello", { world: $t("world") }) }}
- - - -
- -
{{ $t("hello", { world: $t("world") }) }}
- - - -
-
`, - i18n: { - messages: { - en: { - hello: 'Hello {world}', - world: 'world!' - } - } - } - }) - - const App = defineComponent({ - components: { - C1 - }, - template: `` - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual( - `
C1:
Hello world!
Hello world!

C2 slot:
Hello world!
Hello world!
C3 slot:
Hello world!
Hello world!
` - ) -}) - test('issue #819: v-for', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -462,54 +244,12 @@ test('issue #819: v-for', async () => { }) describe('issue #853', () => { - test('legacy', async () => { - const mockWarn = vi.spyOn(shared, 'warn') - // eslint-disable-next-line @typescript-eslint/no-empty-function - mockWarn.mockImplementation(() => {}) - - const i18n = createI18n({ - locale: 'en', - fallbackLocale: 'en', - warnHtmlInMessage: 'off', - messages: { - en: { - hello: '

hello

' - } - } - }) - - const Child = defineComponent({ - i18n: { - messages: { - en: { child: '

child

' } - } - }, - template: `
` - }) - - const App = defineComponent({ - components: { - Child - }, - template: ` -
- -
-
` - }) - - await mount(App, i18n) - - expect(mockWarn).toHaveBeenCalledTimes(0) - }) - test('compostion', async () => { const mockWarn = vi.spyOn(shared, 'warn') // eslint-disable-next-line @typescript-eslint/no-empty-function mockWarn.mockImplementation(() => {}) const i18n = createI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', warnHtmlMessage: false, @@ -555,7 +295,6 @@ test('issue #854', async () => { mockWarn.mockImplementation(() => {}) const i18n = createI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { @@ -591,7 +330,6 @@ test('issue #854', async () => { test('issue #933', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { @@ -622,7 +360,6 @@ test('issue #933', async () => { test('issue #964', async () => { const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: 'en', messages: { @@ -692,7 +429,6 @@ test('issue #968', async () => { test('issue #1014', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -715,7 +451,6 @@ test('issue #1014', async () => { test('issue #1054, #1053', async () => { const i18n = createI18n({ - legacy: false, locale: 'en-US', datetimeFormats: {} }) @@ -743,7 +478,6 @@ test('issue #1054, #1053', async () => { test('issue #1083', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -796,7 +530,6 @@ test('issue #1083', async () => { test('issue #1123', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -827,7 +560,6 @@ test('issue #1123', async () => { test('issue #1365', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', flatJson: true, messages: { @@ -874,7 +606,6 @@ test('issue #1373', async () => { test('issue #1392', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { hello: 'world' } @@ -942,7 +673,6 @@ test('issue #1392', async () => { test('issue #1538', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { @@ -970,7 +700,6 @@ test('issue #1538', async () => { test('issue #1547', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { @@ -1005,7 +734,6 @@ test('issue #1547', async () => { test('issue #1559', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -1037,7 +765,6 @@ test('issue #1559', async () => { test('issue #1595', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', flatJson: true, messages: { @@ -1094,7 +821,6 @@ test('issue #1595', async () => { test('issue #1595 merge case', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', flatJson: true, messages: { @@ -1157,7 +883,6 @@ test('issue #1610', async () => { language: 'Languages' } const i18n = createI18n({ - legacy: false, locale: 'en', globalInjection: true, messages: { @@ -1201,7 +926,6 @@ test('issue #1615', async () => { })() } const i18n = createI18n({ - legacy: false, locale: 'en', globalInjection: true, messages: { @@ -1336,7 +1060,6 @@ test('#1809', async () => { test('#1912', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -1383,7 +1106,6 @@ test('#1912', async () => { test('#1972', () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -1424,7 +1146,6 @@ describe('CVE-2024-52809', () => { } } const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en @@ -1452,7 +1173,6 @@ describe('CVE-2024-52809', () => { } } const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en diff --git a/packages/vue-i18n-core/test/mixin.test.ts b/packages/vue-i18n-core/test/mixin.test.ts deleted file mode 100644 index d7cc1443a..000000000 --- a/packages/vue-i18n-core/test/mixin.test.ts +++ /dev/null @@ -1,264 +0,0 @@ -/** - * @vitest-environment jsdom - */ - -// utils -vi.mock('@intlify/shared', async () => { - const actual = await vi.importActual('@intlify/shared') - return { - ...actual, - warnOnce: vi.fn() - } -}) - -import { - compile, - fallbackWithLocaleChain, - registerLocaleFallbacker, - registerMessageCompiler, - registerMessageResolver, - resolveValue -} from '@intlify/core-base' -import { defineComponent, nextTick } from 'vue' -import { errorMessages, I18nErrorCodes } from '../src/errors' -import { createI18n } from '../src/index' -import { mount } from './helper' - -import type { VueI18n } from '../src/legacy' - -beforeAll(() => { - registerMessageCompiler(compile) - registerMessageResolver(resolveValue) - registerLocaleFallbacker(fallbackWithLocaleChain) -}) - -describe('beforeCreate', () => { - test('i18n option', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ - template: `

{{ $t('bye') }}

`, - i18n: { - locale: 'ja', - sync: false, - messages: { - ja: { - bye: 'さようなら' - } - } - } - }) - const { html } = await mount(App, i18n) - - expect(html()).toEqual('

さようなら

') - }) - - test('__i18n option', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const messages = { - en: { - bye: 'good bye!' - } - } - const App = defineComponent({ - template: `

{{ $t('bye') }}

`, - __i18n: [ - { - locale: '', - resource: messages as any // eslint-disable-line @typescript-eslint/no-explicit-any - } - ] - }) - const { html } = await mount(App, i18n) - - expect(html()).toEqual('

good bye!

') - }) -}) - -test('$t', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ template: '
' }) - const { vm } = await mount(App, i18n) - - expect(vm.$t!('hello')).toEqual('hello!') -}) - -test('$rt', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - contents: [ - { - title: 'Title {0}' - }, - { - title: () => 'Title 2' - } - ] - } - } - }) - - const App = defineComponent({ - template: `

{{ $rt(content.title, [index + 1]) }}

` - }) - const { html } = await mount(App, i18n) - - expect(html()).toEqual('

Title 1

Title 2

') -}) - -test('$te', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ template: '
' }) - const { vm } = await mount(App, i18n) - - expect(vm.$te!('hello')).toBe(true) - expect(vm.$te!('foo')).toBe(false) -}) - -test('$d', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en-US', - datetimeFormats: { - 'en-US': { - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - timeZone: 'America/New_York' - } - } - } - }) - - const App = defineComponent({ template: '
' }) - const { vm } = await mount(App, i18n) - - const dt = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) - expect(vm.$d!(dt, 'short')).toEqual('12/19/2012, 10:00 PM') -}) - -test('$n', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en-US', - numberFormats: { - 'en-US': { - percent: { - style: 'percent', - useGrouping: false - } - } - } - }) - - const App = defineComponent({ template: '
' }) - const { vm } = await mount(App, i18n) - - expect(vm.$n!(0.99, 'percent')).toEqual('99%') -}) - -test('$i18n', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ template: '
' }) - const { vm } = await mount(App, i18n) - - expect((vm.$i18n! as VueI18n).t('hello')).toEqual('hello!') -}) - -test.skip('beforeDestroy', async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ template: '
' }) - const { app, vm } = await mount(App, i18n) - - app.unmount() - await nextTick() - - expect(vm.$i18n).toBeUndefined() -}) - -describe.skip('errors', () => { - test(errorMessages[I18nErrorCodes.UNEXPECTED_ERROR], async () => { - const i18n = createI18n({ - legacy: true, - locale: 'en', - messages: { - en: { - hello: 'hello!' - } - } - }) - - const App = defineComponent({ - template: '

foo

' - }) - - let error: Error | null = null - try { - await mount(App, i18n) - } catch (e) { - error = e as Error - } - expect(error!.message).toEqual( - errorMessages[I18nErrorCodes.UNEXPECTED_ERROR] - ) - }) -}) diff --git a/packages/vue-i18n-core/test/wc.test.ts b/packages/vue-i18n-core/test/wc.test.ts index 187d668dd..94ef0933c 100644 --- a/packages/vue-i18n-core/test/wc.test.ts +++ b/packages/vue-i18n-core/test/wc.test.ts @@ -36,8 +36,7 @@ beforeEach(() => { }) test('basic', async () => { - const i18n = createI18n({ - legacy: false, + const i18n = createI18n({ locale: 'en', messages: { en: { @@ -83,8 +82,7 @@ test('basic', async () => { }) test('custom blocks', async () => { - const i18n = createI18n({ - legacy: false, + const i18n = createI18n({ locale: 'en', messages: { en: { From 1a55f2a65a5155e00baa808e72e4977c0aa826c0 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 17:45:55 +0900 Subject: [PATCH 03/18] update config --- packages/global.d.ts | 1 - rollup.config.mjs | 3 --- scripts/rolldown.ts | 3 --- vitest.config.ts | 1 - 4 files changed, 8 deletions(-) diff --git a/packages/global.d.ts b/packages/global.d.ts index 441f998ec..f9d912336 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -15,6 +15,5 @@ declare let __COMMIT__: string // Feature flags declare let __FEATURE_PROD_VUE_DEVTOOLS__: boolean declare let __FEATURE_PROD_INTLIFY_DEVTOOLS__: boolean -declare let __FEATURE_LEGACY_API__: boolean declare let __FEATURE_FULL_INSTALL__: boolean declare let __FEATURE_DROP_MESSAGE_COMPILER__: boolean diff --git a/rollup.config.mjs b/rollup.config.mjs index d017270bb..8b3be9ce9 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -354,9 +354,6 @@ function createReplacePlugin( __FEATURE_FULL_INSTALL__: isBundlerESMBuild ? `__VUE_I18N_FULL_INSTALL__` : `true`, - __FEATURE_LEGACY_API__: isBundlerESMBuild - ? `__VUE_I18N_LEGACY_API__` - : `true`, __FEATURE_PROD_VUE_DEVTOOLS__: ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild ? 'false' // tree-shake devtools diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts index 456070030..ceb700c64 100644 --- a/scripts/rolldown.ts +++ b/scripts/rolldown.ts @@ -238,9 +238,6 @@ export function createConfigsForPackage({ __FEATURE_FULL_INSTALL__: isBundlerESMBuild ? `__VUE_I18N_FULL_INSTALL__` : `true`, - __FEATURE_LEGACY_API__: isBundlerESMBuild - ? `__VUE_I18N_LEGACY_API__` - : `true`, __FEATURE_PROD_VUE_DEVTOOLS__: ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild ? 'false' // tree-shake devtools diff --git a/vitest.config.ts b/vitest.config.ts index befffed76..83ea2d92e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -18,7 +18,6 @@ export default defineConfig({ __NODE_JS__: true, __LITE__: false, __FEATURE_FULL_INSTALL__: true, - __FEATURE_LEGACY_API__: true, __FEATURE_DROP_MESSAGE_COMPILER__: false }, resolve: { From 1f743b9af825e9d0b6fb9ebac73b397fa04aa09b Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 17:49:23 +0900 Subject: [PATCH 04/18] fix e2e --- e2e/fallback/basic.spec.ts | 2 +- e2e/fallback/component.spec.ts | 2 +- e2e/fallback/format.spec.ts | 2 +- e2e/fallback/suppress.spec.ts | 2 +- e2e/formatting/linked.spec.ts | 2 +- e2e/formatting/list.spec.ts | 2 +- e2e/formatting/literal.spec.ts | 2 +- e2e/formatting/named.spec.ts | 2 +- e2e/functions/linked.spec.ts | 2 +- e2e/functions/list.spec.ts | 2 +- e2e/functions/named.spec.ts | 2 +- e2e/functions/plural.spec.ts | 2 +- e2e/missing/handler.spec.ts | 2 +- e2e/missing/suppress.spec.ts | 2 +- e2e/plural/basic.spec.ts | 2 +- e2e/plural/custom.spec.ts | 2 +- e2e/scope/global.spec.ts | 2 +- e2e/scope/inherit-locale.spec.ts | 2 +- e2e/scope/local.spec.ts | 2 +- e2e/started.spec.ts | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/e2e/fallback/basic.spec.ts b/e2e/fallback/basic.spec.ts index 36f9d6a3f..49757631c 100644 --- a/e2e/fallback/basic.spec.ts +++ b/e2e/fallback/basic.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { const warnings: string[] = [] beforeAll(async () => { diff --git a/e2e/fallback/component.spec.ts b/e2e/fallback/component.spec.ts index 5f283599b..e0f9c4641 100644 --- a/e2e/fallback/component.spec.ts +++ b/e2e/fallback/component.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/fallback/component.html`)) diff --git a/e2e/fallback/format.spec.ts b/e2e/fallback/format.spec.ts index 0ed626b25..40e18f49b 100644 --- a/e2e/fallback/format.spec.ts +++ b/e2e/fallback/format.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { const warnings: string[] = [] beforeAll(async () => { diff --git a/e2e/fallback/suppress.spec.ts b/e2e/fallback/suppress.spec.ts index 967aa1e41..11b2482e9 100644 --- a/e2e/fallback/suppress.spec.ts +++ b/e2e/fallback/suppress.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { const warnings: string[] = [] beforeAll(async () => { diff --git a/e2e/formatting/linked.spec.ts b/e2e/formatting/linked.spec.ts index 19080d419..6dea82e04 100644 --- a/e2e/formatting/linked.spec.ts +++ b/e2e/formatting/linked.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/formatting/linked.html`)) diff --git a/e2e/formatting/list.spec.ts b/e2e/formatting/list.spec.ts index 4a6e6f69a..8e23f6a04 100644 --- a/e2e/formatting/list.spec.ts +++ b/e2e/formatting/list.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/formatting/list.html`)) diff --git a/e2e/formatting/literal.spec.ts b/e2e/formatting/literal.spec.ts index 2f4cd7fad..ee483ac9a 100644 --- a/e2e/formatting/literal.spec.ts +++ b/e2e/formatting/literal.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/formatting/literal.html`)) diff --git a/e2e/formatting/named.spec.ts b/e2e/formatting/named.spec.ts index 8d11e1e14..549d9634f 100644 --- a/e2e/formatting/named.spec.ts +++ b/e2e/formatting/named.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/formatting/named.html`)) diff --git a/e2e/functions/linked.spec.ts b/e2e/functions/linked.spec.ts index e8d35ec1e..29ee3a9c0 100644 --- a/e2e/functions/linked.spec.ts +++ b/e2e/functions/linked.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/functions/linked.html`)) diff --git a/e2e/functions/list.spec.ts b/e2e/functions/list.spec.ts index 5b20308a7..c4483af3e 100644 --- a/e2e/functions/list.spec.ts +++ b/e2e/functions/list.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/functions/list.html`)) diff --git a/e2e/functions/named.spec.ts b/e2e/functions/named.spec.ts index 3b769034f..f6cbb53a2 100644 --- a/e2e/functions/named.spec.ts +++ b/e2e/functions/named.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/functions/named.html`)) diff --git a/e2e/functions/plural.spec.ts b/e2e/functions/plural.spec.ts index 28038ee40..f0edd9b5f 100644 --- a/e2e/functions/plural.spec.ts +++ b/e2e/functions/plural.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/functions/plural.html`)) diff --git a/e2e/missing/handler.spec.ts b/e2e/missing/handler.spec.ts index 304246857..579b961b9 100644 --- a/e2e/missing/handler.spec.ts +++ b/e2e/missing/handler.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { const warnings: string[] = [] beforeAll(async () => { diff --git a/e2e/missing/suppress.spec.ts b/e2e/missing/suppress.spec.ts index 78b7a6afc..d3201c499 100644 --- a/e2e/missing/suppress.spec.ts +++ b/e2e/missing/suppress.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { const warnings: string[] = [] beforeAll(async () => { diff --git a/e2e/plural/basic.spec.ts b/e2e/plural/basic.spec.ts index 18b41328c..2476890ac 100644 --- a/e2e/plural/basic.spec.ts +++ b/e2e/plural/basic.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/plural/basic.html`)) diff --git a/e2e/plural/custom.spec.ts b/e2e/plural/custom.spec.ts index d0f6f2a24..9c8c2d091 100644 --- a/e2e/plural/custom.spec.ts +++ b/e2e/plural/custom.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/plural/custom.html`)) diff --git a/e2e/scope/global.spec.ts b/e2e/scope/global.spec.ts index 4e34bea2c..cfa4b9d0d 100644 --- a/e2e/scope/global.spec.ts +++ b/e2e/scope/global.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/scope/global.html`)) diff --git a/e2e/scope/inherit-locale.spec.ts b/e2e/scope/inherit-locale.spec.ts index 39cd72b02..9173d1362 100644 --- a/e2e/scope/inherit-locale.spec.ts +++ b/e2e/scope/inherit-locale.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/scope/inherit-locale.html`)) diff --git a/e2e/scope/local.spec.ts b/e2e/scope/local.spec.ts index 7970df665..7b190c717 100644 --- a/e2e/scope/local.spec.ts +++ b/e2e/scope/local.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/scope/local.html`)) diff --git a/e2e/started.spec.ts b/e2e/started.spec.ts index bad7b5885..42a42eb6a 100644 --- a/e2e/started.spec.ts +++ b/e2e/started.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from './helper' -;['composition', 'petite', 'legacy'].forEach(pattern => { +;['composition', 'petite'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/started.html`)) From f8e6352ba832d6fc80bfeee60f236582972329e7 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 17:53:02 +0900 Subject: [PATCH 05/18] fix e2e --- e2e/components/datetime-format.spec.ts | 2 +- e2e/components/number-format.spec.ts | 2 +- e2e/components/translation.spec.ts | 2 +- e2e/datetime.spec.ts | 2 +- e2e/number.spec.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e/components/datetime-format.spec.ts b/e2e/components/datetime-format.spec.ts index f1a5af82c..fa75acc53 100644 --- a/e2e/components/datetime-format.spec.ts +++ b/e2e/components/datetime-format.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'legacy'].forEach(pattern => { +;['composition'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto( diff --git a/e2e/components/number-format.spec.ts b/e2e/components/number-format.spec.ts index 60eeeedb5..a9b299c9c 100644 --- a/e2e/components/number-format.spec.ts +++ b/e2e/components/number-format.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'legacy'].forEach(pattern => { +;['composition'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/components/number-format.html`)) diff --git a/e2e/components/translation.spec.ts b/e2e/components/translation.spec.ts index 26a261b42..a2287bd7a 100644 --- a/e2e/components/translation.spec.ts +++ b/e2e/components/translation.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from '../helper' -;['composition', 'legacy'].forEach(pattern => { +;['composition'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/components/translation.html`)) diff --git a/e2e/datetime.spec.ts b/e2e/datetime.spec.ts index 30e6e59fa..1785b256d 100644 --- a/e2e/datetime.spec.ts +++ b/e2e/datetime.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from './helper' -;['composition', 'legacy'].forEach(pattern => { +;['composition'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/datetime.html`)) diff --git a/e2e/number.spec.ts b/e2e/number.spec.ts index d33c1a39c..cbbc93eb8 100644 --- a/e2e/number.spec.ts +++ b/e2e/number.spec.ts @@ -1,5 +1,5 @@ import { getText, url } from './helper' -;['composition', 'legacy'].forEach(pattern => { +;['composition'].forEach(pattern => { describe(`${pattern}`, () => { beforeAll(async () => { await page.goto(url(`/examples/${pattern}/number.html`)) From 9fe87e097bcdc25aa7393ff552ed3dc181cd99b9 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 18:08:10 +0900 Subject: [PATCH 06/18] fix exports --- packages/petite-vue-i18n/src/index.ts | 17 - packages/petite-vue-i18n/src/runtime.ts | 16 +- packages/vue-i18n-core/src/index.ts | 23 +- packages/vue-i18n-core/src/legacy.ts | 1675 ------------------ packages/vue-i18n-core/src/petite.ts | 16 - packages/vue-i18n-core/src/types.ts | 19 +- packages/vue-i18n-core/test/legacy.test-d.ts | 231 --- packages/vue-i18n-core/test/legacy.test.ts | 592 ------- packages/vue-i18n/src/index.ts | 16 +- packages/vue-i18n/src/runtime.ts | 16 +- 10 files changed, 5 insertions(+), 2616 deletions(-) delete mode 100644 packages/vue-i18n-core/src/legacy.ts delete mode 100644 packages/vue-i18n-core/test/legacy.test-d.ts delete mode 100644 packages/vue-i18n-core/test/legacy.test.ts diff --git a/packages/petite-vue-i18n/src/index.ts b/packages/petite-vue-i18n/src/index.ts index da9cb0a51..3ede50164 100644 --- a/packages/petite-vue-i18n/src/index.ts +++ b/packages/petite-vue-i18n/src/index.ts @@ -78,23 +78,6 @@ export type { VueMessageType } from '@intlify/vue-i18n-core/petite' -export type { - Choice, - DateTimeFormatResult, - LocaleMessageObject, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - WarnHtmlInMessageLevel -} from '@intlify/vue-i18n-core/petite' - export type { IsEmptyObject, IsNever, diff --git a/packages/petite-vue-i18n/src/runtime.ts b/packages/petite-vue-i18n/src/runtime.ts index 6de23ca7e..058c6557e 100644 --- a/packages/petite-vue-i18n/src/runtime.ts +++ b/packages/petite-vue-i18n/src/runtime.ts @@ -48,7 +48,6 @@ export type { } from '@intlify/core-base' export { createI18n, useI18n, VERSION } from '@intlify/vue-i18n-core/petite' export type { - Choice, Composer, ComposerAdditionalOptions, ComposerCustom, @@ -60,7 +59,6 @@ export type { ComposerTranslation, CustomBlock, CustomBlocks, - DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, @@ -74,21 +72,9 @@ export type { I18nOptions, I18nPluginOptions, I18nScope, - LocaleMessageObject, MissingHandler, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, UseI18nOptions, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - VueMessageType, - WarnHtmlInMessageLevel + VueMessageType } from '@intlify/vue-i18n-core/petite' export type { diff --git a/packages/vue-i18n-core/src/index.ts b/packages/vue-i18n-core/src/index.ts index ab87baa54..18f9e3330 100644 --- a/packages/vue-i18n-core/src/index.ts +++ b/packages/vue-i18n-core/src/index.ts @@ -80,30 +80,9 @@ export type { I18nScope, UseI18nOptions } from './i18n' -export type { - Choice, - DateTimeFormatResult, - LocaleMessageObject, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - WarnHtmlInMessageLevel -} from './legacy' export { initDev, initFeatureFlags, VERSION } from './misc' export type { I18nPluginOptions } from './plugin' -export type { - Disposer, - GeneratedInstanceType, - GeneratedTypeConfig, - VueI18nInstance -} from './types' +export type { Disposer, GeneratedTypeConfig, VueI18nInstance } from './types' export type { IsEmptyObject, diff --git a/packages/vue-i18n-core/src/legacy.ts b/packages/vue-i18n-core/src/legacy.ts deleted file mode 100644 index 55a1fe408..000000000 --- a/packages/vue-i18n-core/src/legacy.ts +++ /dev/null @@ -1,1675 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { DEFAULT_LOCALE } from '@intlify/core-base' -import { - assign, - isArray, - isBoolean, - isFunction, - isPlainObject, - isRegExp, - isString -} from '@intlify/shared' -import { createComposer } from './composer' -import { DisableEmitter, EnableEmitter } from './symbols' - -import type { - DateTimeFormat, - DateTimeFormats as DateTimeFormatsType, - FallbackLocale, - FallbackLocales, - GeneratedLocale, - IsEmptyObject, - IsNever, - LinkedModifiers, - Locale, - LocaleMessage, - LocaleMessageDictionary, - LocaleMessages, - LocaleMessageValue, - LocaleParams, - MessageResolver, - NamedValue, - NumberFormat, - NumberFormats as NumberFormatsType, - Path, - PickupFormatKeys, - PickupFormatPathKeys, - PickupKeys, - PickupLocales, - PickupPaths, - PluralizationRule, - PluralizationRules, - PostTranslationHandler, - RemovedIndexResources, - RemoveIndexSignature, - SchemaParams, - TranslateOptions -} from '@intlify/core-base' -import type { VueDevToolsEmitter } from '@intlify/devtools-types' -import type { - Composer, - ComposerInternalOptions, - ComposerOptions, - ComposerResolveLocaleMessageTranslation, - DefaultDateTimeFormatSchema, - DefaultLocaleMessageSchema, - DefaultNumberFormatSchema, - DefineDateTimeFormat, - DefineLocaleMessage, - DefineNumberFormat, - MissingHandler, - VueMessageType -} from './composer' -import type { Disposer } from './types' - -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type TranslateResult = string -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type Choice = number -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type LocaleMessageObject = - LocaleMessageDictionary -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type PluralizationRulesMap = { [locale: string]: PluralizationRule } -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error' -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type DateTimeFormatResult = string -/** - * @deprecated will be removed at vue-i18n v12 - * @VueI18nLegacy - */ -export type NumberFormatResult = string -/** - * @deprecated will be removed at vue-i18n v12 - */ -export type VueI18nExtender = (vueI18n: VueI18n) => Disposer | undefined - -/** - * VueI18n Options - * - * @remarks - * This option is compatible with `VueI18n` class constructor options (offered with Vue I18n v8.x) - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nLegacy - */ -export interface VueI18nOptions< - Schema extends { - message?: unknown - datetime?: unknown - number?: unknown - } = { - message: DefaultLocaleMessageSchema - datetime: DefaultDateTimeFormatSchema - number: DefaultNumberFormatSchema - }, - Locales extends - | { - messages: unknown - datetimeFormats: unknown - numberFormats: unknown - } - | string = Locale, - Options extends ComposerOptions = ComposerOptions< - Schema, - Locales - > -> { - /** - * @remarks - * The locale of localization. - * - * If the locale contains a territory and a dialect, this locale contains an implicit fallback. - * - * @VueI18nSee [Scope and Locale Changing](../../guide/essentials/scope) - * - * @defaultValue `'en-US'` - */ - locale?: Options['locale'] - /** - * @remarks - * The locale of fallback localization. - * - * For more complex fallback definitions see fallback. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue The default `'en-US'` for the `locale` if it's not specified, or it's `locale` value - */ - fallbackLocale?: Options['fallbackLocale'] - /** - * @remarks - * The locale messages of localization. - * - * @VueI18nSee [Getting Started](../../guide/essentials/started) - * - * @defaultValue `{}` - */ - messages?: Options['messages'] - /** - * @remarks - * Allow use flat json messages or not - * - * @defaultValue `false` - */ - flatJson?: Options['flatJson'] - /** - * @remarks - * The datetime formats of localization. - * - * @VueI18nSee [Datetime Formatting](../../guide/essentials/datetime) - * - * @defaultValue `{}` - */ - datetimeFormats?: Options['datetimeFormats'] - /** - * @remarks - * The number formats of localization. - * - * @VueI18nSee [Number Formatting](../../guide/essentials/number) - * - * @defaultValue `{}` - */ - numberFormats?: Options['numberFormats'] - /** - * @remarks - * The list of available locales in messages in lexical order. - * - * @defaultValue `[]` - */ - availableLocales?: Locale[] - /** - * @remarks - * Custom Modifiers for linked messages. - * - * @VueI18nSee [Custom Modifiers](../../guide/essentials/syntax#custom-modifiers) - */ - modifiers?: Options['modifiers'] - /** - * @remarks - * A handler for localization missing. - * - * The handler gets called with the localization target locale, localization path key, the Vue instance and values. - * - * If missing handler is assigned, and occurred localization missing, it's not warned. - * - * @defaultValue `null` - */ - missing?: Options['missing'] - /** - * @remarks - * In the component localization, whether to fall back to root level (global scope) localization when localization fails. - * - * If `false`, it's not fallback to root. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue `true` - */ - fallbackRoot?: Options['fallbackRoot'] - /** - * @remarks - * Whether suppress warnings outputted when localization fails. - * - * If `true`, suppress localization fail warnings. - * - * If you use regular expression, you can suppress localization fail warnings that it match with translation key (e.g. `t`). - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue `false` - */ - silentTranslationWarn?: Options['missingWarn'] - /** - * @remarks - * Whether do template interpolation on translation keys when your language lacks a translation for a key. - * - * If `true`, skip writing templates for your "base" language; the keys are your templates. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue `false` - */ - silentFallbackWarn?: Options['fallbackWarn'] - /** - * @remarks - * Whether suppress warnings when falling back to either `fallbackLocale` or root. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue `false` - */ - formatFallbackMessages?: Options['fallbackFormat'] - /** - * @remarks - * Whether to allow the use locale messages of HTML formatting. - * - * See the warnHtmlInMessage property. - * - * @VueI18nSee [HTML Message](../../guide/essentials/syntax#html-message) - * @VueI18nSee [Change `warnHtmlInMessage` option default value](../../guide/migration/breaking#change-warnhtmlinmessage-option-default-value) - * - * @defaultValue `'off'` - */ - warnHtmlInMessage?: WarnHtmlInMessageLevel - /** - * @remarks - * If `escapeParameterHtml` is configured as true then interpolation parameters are escaped before the message is translated. - * - * This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. around a user provided value). - * - * This usage pattern mostly occurs when passing precomputed text strings into UI components. - * - * The escape process involves replacing the following symbols with their respective HTML character entities: `<`, `>`, `"`, `'`. - * - * Setting `escapeParameterHtml` as true should not break existing functionality but provides a safeguard against a subtle type of XSS attack vectors. - * - * @VueI18nSee [HTML Message](../../guide/essentials/syntax#html-message) - * - * @defaultValue `false` - */ - escapeParameterHtml?: Options['escapeParameter'] - /** - * @remarks - * The shared locale messages of localization for components. More detail see Component based localization. - * - * @VueI18nSee [Shared locale messages for components](../../guide/essentials/local#shared-locale-messages-for-components) - * - * @defaultValue `undefined` - */ - sharedMessages?: LocaleMessages - /** - * @remarks - * A set of rules for word pluralization - * - * @VueI18nSee [Custom Pluralization](../../guide/essentials/pluralization#custom-pluralization) - * - * @defaultValue `{}` - */ - pluralizationRules?: Options['pluralRules'] - /** - * @remarks - * A handler for post processing of translation. The handler gets after being called with the `$t`, and `t`. - * - * This handler is useful if you want to filter on translated text such as space trimming. - * - * @defaultValue `null` - */ - postTranslation?: Options['postTranslation'] - /** - * @remarks - * Whether synchronize the root level locale to the component localization locale. - * - * If `false`, regardless of the root level locale, localize for each component locale. - * - * @VueI18nSee [Local Scope](../../guide/essentials/scope#local-scope-2) - * - * @defaultValue `true` - */ - sync?: boolean - /** - * @remarks - * A message resolver to resolve [`messages`](legacy#messages). - * - * If not specified, the vue-i18n internal message resolver will be used by default. - * - * You need to implement a message resolver yourself that supports the following requirements: - * - * - Resolve the message using the locale message of [`locale`](legacy#locale) passed as the first argument of the message resolver, and the path passed as the second argument. - * - * - If the message could not be resolved, you need to return `null`. - * - * - If you will be returned `null`, the message resolver will also be called on fallback if [`fallbackLocale`](legacy#fallbacklocale-2) is enabled, so the message will need to be resolved as well. - * - * The message resolver is called indirectly by the following APIs: - * - * - [`t`](legacy#t-key) - * - * - [`te`](legacy#te-key-locale) - * - * - [`tm`](legacy#tm-key) - * - * - [Translation component](component#translation) - * - * @example - * Here is an example of how to set it up using your `createI18n`: - * ```js - * import { createI18n } from 'vue-i18n' - * - * // your message resolver - * function messageResolver(obj, path) { - * // simple message resolving! - * const msg = obj[path] - * return msg != null ? msg : null - * } - * - * // call with I18n option - * const i18n = createI18n({ - * locale: 'ja', - * messageResolver, // set your message resolver - * messages: { - * en: { ... }, - * ja: { ... } - * } - * }) - * - * // the below your something to do ... - * // ... - * ``` - * - * @VueI18nTip - * :new: v9.2+ - * - * @VueI18nWarning - * If you use the message resolver, the [`flatJson`](legacy#flatjson) setting will be ignored. That is, you need to resolve the flat JSON by yourself. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - * - * @defaultValue `undefined` - */ - messageResolver?: MessageResolver -} - -/** - * @internal - * - * @deprecated will be removed at vue-i18n v12 - */ -export interface VueI18nInternalOptions { - __extender?: VueI18nExtender -} - -/** - * Locale message translation functions for VueI18n legacy interfaces - * - * @remarks - * This is the interface for {@link VueI18n} - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nLegacy - */ -export interface VueI18nTranslation< - Messages extends Record = {}, - Locales = 'en-US', - DefinedLocaleMessage extends - RemovedIndexResources = RemovedIndexResources, - C = IsEmptyObject extends false - ? PickupPaths<{ - [K in keyof DefinedLocaleMessage]: DefinedLocaleMessage[K] - }> - : never, - M = IsEmptyObject extends false ? PickupKeys : never, - ResourceKeys extends C | M = IsNever extends false - ? IsNever extends false - ? C | M - : C - : IsNever extends false - ? M - : never -> { - /** - * Locale message translation. - * - * @remarks - * If this is used in a reactive context, it will re-evaluate once the locale changes. - * - * If [i18n component options](injection#i18n) is specified, it’s translated in preferentially local scope locale messages than global scope locale messages. - * - * If [i18n component options](injection#i18n) isn't specified, it’s translated with global scope locale messages. - * - * @param key - A target locale message key - * - * @returns Translated message - * - * @VueI18nSee [Scope and Locale Changing](../../guide/essentials/scope) - */ - (key: Key | ResourceKeys): TranslateResult - /** - * Locale message translation for plurals - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, return a pluralized translation message. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * @param key - A target locale message key - * @param plural - Which plural string to get. 1 returns the first one. - * - * @returns Translated message - * - * @VueI18nSee [Pluralization](../../guide/essentials/pluralization) - */ - (key: Key | ResourceKeys, plural: number): TranslateResult - /** - * Locale message translation for plurals - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, return a pluralized translation message. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * About details of options, see the {@link TranslateOptions}. - * - * @param key - A target locale message key - * @param plural - Which plural string to get. 1 returns the first one. - * @param options - Additional {@link TranslateOptions | options} for translation - * - * @returns Translated message - * - * @VueI18nSee [Pluralization](../../guide/essentials/pluralization) - */ - ( - key: Key | ResourceKeys, - plural: number, - options: TranslateOptions - ): TranslateResult - /** - * Locale message translation for missing default message - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, if no translation was found, return a default message. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * @param key - A target locale message key - * @param defaultMsg - A default message to return if no translation was found - * - * @returns Translated message - */ - ( - key: Key | ResourceKeys, - defaultMsg: string - ): TranslateResult - /** - * Locale message translation for missing default message - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, if no translation was found, return a default message. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * About details of options, see the {@link TranslateOptions}. - * - * @param key - A target locale message key - * @param defaultMsg - A default message to return if no translation was found - * @param options - Additional {@link TranslateOptions | options} for translation - * - * @returns Translated message - */ - ( - key: Key | ResourceKeys, - defaultMsg: string, - options: TranslateOptions - ): TranslateResult - /** - * Locale message translation. - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * @param key - A target locale message key - * @param list - A values of list interpolation - * - * @returns Translated message - * - * @VueI18nSee [List interpolation](../../guide/essentials/syntax#list-interpolation) - */ - ( - key: Key | ResourceKeys, - list: unknown[] - ): TranslateResult - /** - * Locale message translation for list interpolations and plurals - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and return a pluralized translation message. - * - * @param key - A target locale message key - * @param list - A values of list interpolation - * @param plural - Which plural string to get. 1 returns the first one. - * - * @returns Translated message - * - * @VueI18nSee [Pluralization](../../guide/essentials/pluralization) - * @VueI18nSee [List interpolation](../../guide/essentials/syntax#list-interpolation) - */ - ( - key: Key | ResourceKeys, - list: unknown[], - plural: number - ): TranslateResult - /** - * Locale message translation for list interpolations and missing default message - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and if no translation was found, return a default message. - * - * @param key - A target locale message key - * @param list - A values of list interpolation - * @param defaultMsg - A default message to return if no translation was found - * - * @returns Translated message - * - * @VueI18nSee [List interpolation](../../guide/essentials/syntax#list-interpolation) - */ - ( - key: Key | ResourceKeys, - list: unknown[], - defaultMsg: string - ): TranslateResult - /** - * Locale message translation for list interpolations - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * About details of options, see the {@link TranslateOptions}. - * - * @param key - A target locale message key - * @param list - A values of list interpolation - * @param options - Additional {@link TranslateOptions | options} for translation - * - * @returns Translated message - * - * @VueI18nSee [List interpolation](../../guide/essentials/syntax#list-interpolation) - */ - ( - key: Key | ResourceKeys, - list: unknown[], - options: TranslateOptions - ): TranslateResult - /** - * Locale message translation. - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * @param key - A target locale message key - * @param named - A values of named interpolation - * - * @returns Translated message - * - * @VueI18nSee [Named interpolation](../../guide/essentials/syntax#named-interpolation) - */ - ( - key: Key | ResourceKeys, - named: Record - ): TranslateResult - /** - * Locale message translation for named interpolations and plurals - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and return a pluralized translation message. - * - * @param key - A target locale message key - * @param named - A values of named interpolation - * @param plural - Which plural string to get. 1 returns the first one. - * - * @returns Translated message - * - * @VueI18nSee [Pluralization](../../guide/essentials/pluralization) - * @VueI18nSee [Named interpolation](../../guide/essentials/syntax#named-interpolation) - */ - ( - key: Key | ResourceKeys, - named: NamedValue, - plural: number - ): TranslateResult - /** - * Locale message translation for named interpolations and plurals - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and if no translation was found, return a default message. - * - * @param key - A target locale message key - * @param named - A values of named interpolation - * @param defaultMsg - A default message to return if no translation was found - * - * @returns Translated message - * - * @VueI18nSee [Named interpolation](../../guide/essentials/syntax#named-interpolation) - */ - ( - key: Key | ResourceKeys, - named: NamedValue, - defaultMsg: string - ): TranslateResult - /** - * Locale message translation for named interpolations - * - * @remarks - * Overloaded `t`. About details, see the [call signature](legacy#key-key-resourcekeys-translateresult) details. - * - * In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token. - * - * You can also suppress the warning, when the translation missing according to the options. - * - * About details of options, see the {@link TranslateOptions}. - * - * @param key - A target locale message key - * @param named - A values of named interpolation - * @param options - Additional {@link TranslateOptions | options} for translation - * - * @returns Translated message - * - * @VueI18nSee [Named interpolation](../../guide/essentials/syntax#named-interpolation) - */ - ( - key: Key | ResourceKeys, - named: NamedValue, - options: TranslateOptions - ): TranslateResult -} - -/** - * Resolve locale message translation functions for VueI18n legacy interfaces - * - * @deprecated will be removed at vue-i18n v12 - * - * @remarks - * This is the interface for {@link VueI18n}. This interface is an alias of {@link ComposerResolveLocaleMessageTranslation}. - * - * @VueI18nLegacy - */ -export type VueI18nResolveLocaleMessageTranslation = - ComposerResolveLocaleMessageTranslation - -/** - * Datetime formatting functions for VueI18n legacy interfaces - * - * @remarks - * This is the interface for {@link VueI18n} - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nLegacy - */ -export interface VueI18nDateTimeFormatting< - DateTimeFormats extends Record = {}, - Locales = 'en-US', - DefinedDateTimeFormat extends - RemovedIndexResources = RemovedIndexResources, - C = IsEmptyObject extends false - ? PickupFormatPathKeys<{ - [K in keyof DefinedDateTimeFormat]: DefinedDateTimeFormat[K] - }> - : never, - M = IsEmptyObject extends false - ? PickupFormatKeys - : never, - ResourceKeys extends C | M = IsNever extends false - ? IsNever extends false - ? C | M - : C - : IsNever extends false - ? M - : never -> { - /** - * Datetime formatting - * - * @remarks - * If this is used in a reactive context, it will re-evaluate once the locale changes. - * - * If [i18n component options](injection#i18n) is specified, it’s formatted in preferentially local scope datetime formats than global scope locale messages. - * - * If [i18n component options](injection#i18n) isn't specified, it’s formatted with global scope datetime formats. - * - * @param value - A value, timestamp number or `Date` instance - * - * @returns Formatted value - * - * @VueI18nSee [Datetime formatting](../../guide/essentials/datetime) - */ - (value: number | Date): DateTimeFormatResult - /** - * Datetime formatting - * - * @remarks - * Overloaded `d`. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details. - * - * @param value - A value, timestamp number or `Date` instance - * @param key - A key of datetime formats - * - * @returns Formatted value - */ - ( - value: Value, - key: Key | ResourceKeys - ): DateTimeFormatResult - /** - * Datetime formatting - * - * @remarks - * Overloaded `d`. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details. - * - * @param value - A value, timestamp number or `Date` instance - * @param key - A key of datetime formats - * @param locale - A locale, it will be used over than global scope or local scope. - * - * @returns Formatted value - */ - ( - value: Value, - key: Key | ResourceKeys, - locale: Locales - ): DateTimeFormatResult - /** - * Datetime formatting - * - * @remarks - * Overloaded `d`. About details, see the [call signature](legacy#value-number-date-datetimeformatresult) details. - * - * @param value - A value, timestamp number or `Date` instance - * @param args - An argument values - * - * @returns Formatted value - */ - ( - value: number | Date, - args: { [key: string]: string | boolean | number } - ): DateTimeFormatResult -} - -/** - * Number formatting functions for VueI18n legacy interfaces - * - * @remarks - * This is the interface for {@link VueI18n} - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nLegacy - */ -export interface VueI18nNumberFormatting< - NumberFormats extends Record = {}, - Locales = 'en-US', - DefinedNumberFormat extends - RemovedIndexResources = RemovedIndexResources, - C = IsEmptyObject extends false - ? PickupFormatPathKeys<{ - [K in keyof DefinedNumberFormat]: DefinedNumberFormat[K] - }> - : never, - M = IsEmptyObject extends false - ? PickupFormatKeys - : never, - ResourceKeys extends C | M = IsNever extends false - ? IsNever extends false - ? C | M - : C - : IsNever extends false - ? M - : never -> { - /** - * Number formatting - * - * @remarks - * If this is used in a reactive context, it will re-evaluate once the locale changes. - * - * If [i18n component options](injection#i18n) is specified, it’s formatted in preferentially local scope number formats than global scope locale messages. - * - * If [i18n component options](injection#i18n) isn't specified, it’s formatted with global scope number formats. - * - * @param value - A number value - * - * @returns Formatted value - * - * @VueI18nSee [Number formatting](../../guide/essentials/number) - */ - (value: number): NumberFormatResult - /** - * Number formatting - * - * @remarks - * Overloaded `n`. About details, see the [call signature](legacy#value-number-numberformatresult) details. - * - * @param value - A number value - * @param key - A key of number formats - * - * @returns Formatted value - */ - ( - value: number, - key: Key | ResourceKeys - ): NumberFormatResult - /** - * Number formatting - * - * @remarks - * Overloaded `n`. About details, see the [call signature](legacy#value-number-numberformatresult) details. - * - * @param value - A number value - * @param key - A key of number formats - * @param locale - A locale, it will be used over than global scope or local scope. - * - * @returns Formatted value - */ - ( - value: number, - key: Key | ResourceKeys, - locale: Locales - ): NumberFormatResult - /** - * Number formatting - * - * @remarks - * Overloaded `n`. About details, see the [call signature](legacy#value-number-numberformatresult) details. - * - * @param value - A number value - * @param args - An argument values - * - * @returns Formatted value - */ - ( - value: number, - args: { [key: string]: string | boolean | number } - ): NumberFormatResult -} - -/** - * VueI18n legacy interfaces - * - * @remarks - * This interface is compatible with interface of `VueI18n` class (offered with Vue I18n v8.x). - * - * @deprecated will be removed at vue-i18n v12 - * - * @VueI18nLegacy - */ -export interface VueI18n< - Messages extends Record = {}, - DateTimeFormats extends Record = {}, - NumberFormats extends Record = {}, - OptionLocale = Locale, - ResourceLocales = - | PickupLocales> - | PickupLocales> - | PickupLocales>, - Locales = Locale extends GeneratedLocale - ? GeneratedLocale - : OptionLocale extends string - ? [ResourceLocales] extends [never] - ? Locale - : ResourceLocales - : OptionLocale | ResourceLocales, - Composition extends Composer< - Messages, - DateTimeFormats, - NumberFormats, - OptionLocale - > = Composer -> { - /** - * @remarks - * Instance ID. - */ - id: number - /** - * @remarks - * The current locale this VueI18n instance is using. - * - * If the locale contains a territory and a dialect, this locale contains an implicit fallback. - * - * @VueI18nSee [Scope and Locale Changing](../../guide/essentials/scope) - */ - // locale: Locales - locale: Locales - /** - * @remarks - * The current fallback locales this VueI18n instance is using. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - */ - fallbackLocale: FallbackLocales - /** - * @remarks - * The list of available locales in `messages` in lexical order. - */ - readonly availableLocales: Locales[] - /** - * @remarks - * The locale messages of localization. - * - * @VueI18nSee [Getting Started](../../guide/essentials/started) - */ - readonly messages: { [K in keyof Messages]: Messages[K] } - /** - * @remarks - * The datetime formats of localization. - * - * @VueI18nSee [Datetime Formatting](../../guide/essentials/datetime) - */ - readonly datetimeFormats: { [K in keyof DateTimeFormats]: DateTimeFormats[K] } - /** - * @remarks - * The number formats of localization. - * - * @VueI18nSee [Number Formatting](../../guide/essentials/number) - */ - readonly numberFormats: { [K in keyof NumberFormats]: NumberFormats[K] } - /** - * @remarks - * Custom Modifiers for linked messages. - * - * @VueI18nSee [Custom Modifiers](../../guide/essentials/syntax#custom-modifiers) - */ - readonly modifiers: Composition['modifiers'] - /** - * @remarks - * A handler for localization missing. - */ - missing: MissingHandler | null - /** - * @remarks - * A handler for post processing of translation. - */ - postTranslation: PostTranslationHandler | null - /** - * @remarks - * Whether suppress warnings outputted when localization fails. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - */ - silentTranslationWarn: Composition['missingWarn'] - /** - * @remarks - * Whether suppress fallback warnings when localization fails. - */ - silentFallbackWarn: Composition['fallbackWarn'] - /** - * @remarks - * Whether suppress warnings when falling back to either `fallbackLocale` or root. - * - * @VueI18nSee [Fallbacking](../../guide/essentials/fallback) - */ - formatFallbackMessages: Composition['fallbackFormat'] - /** - * @remarks - * Whether synchronize the root level locale to the component localization locale. - * - * @VueI18nSee [Local Scope](../../guide/essentials/scope#local-scope-2) - */ - sync: Composition['inheritLocale'] - /** - * @remarks - * Whether to allow the use locale messages of HTML formatting. - * - * If you set `warn` or` error`, will check the locale messages on the VueI18n instance. - * - * If you are specified `warn`, a warning will be output at console. - * - * If you are specified `error` will occurred an Error. - * - * @VueI18nSee [HTML Message](../../guide/essentials/syntax#html-message) - * @VueI18nSee [Change `warnHtmlInMessage` option default value](../../guide/migration/breaking#change-warnhtmlinmessage-option-default-value) - */ - warnHtmlInMessage: WarnHtmlInMessageLevel - /** - * @remarks - * Whether interpolation parameters are escaped before the message is translated. - * - * @VueI18nSee [HTML Message](../../guide/essentials/syntax#html-message) - */ - escapeParameterHtml: Composition['escapeParameter'] - /** - * A set of rules for word pluralization - * - * @VueI18nSee [Custom Pluralization](../../guide/essentials/pluralization#custom-pluralization) - */ - pluralizationRules: Composition['pluralRules'] - /** - * Locale message translation - * - * @remarks - * About details functions, See the {@link VueI18nTranslation} - */ - t: VueI18nTranslation< - Messages, - Locales, - RemoveIndexSignature<{ - [K in keyof DefineLocaleMessage]: DefineLocaleMessage[K] - }> - > - /** - * Resolve locale message translation - * - * @remarks - * About details functions, See the {@link VueI18nResolveLocaleMessageTranslation} - */ - rt: VueI18nResolveLocaleMessageTranslation - /** - * Translation locale message exist - * - * @remarks - * whether do exist locale message on VueI18n instance [messages](legacy#messages). - * - * If you specified `locale`, check the locale messages of `locale`. - * - * @param key - A target locale message key - * @param locale - A target locale - * - * @returns If found locale message, `true`, else `false` - */ - te< - Str extends string, - Key extends PickupKeys = PickupKeys - >( - key: Str | Key, - locale?: Locales - ): boolean - /** - * Locale messages getter - * - * @remarks - * If [i18n component options](injection#i18n) is specified, it’s get in preferentially local scope locale messages than global scope locale messages. - * - * If [i18n component options](injection#i18n) isn't specified, it’s get with global scope locale messages. - * - * Based on the current `locale`, locale messages will be returned from Composer instance messages. - * - * If you change the `locale`, the locale messages returned will also correspond to the locale. - * - * If there are no locale messages for the given `key` in the composer instance messages, they will be returned with [fallbacking](../../guide/essentials/fallback). - * - * @VueI18nWarning - * You need to use `rt` for the locale message returned by `tm`. see the [rt](legacy#rt-message) details. - * - * @example - * template: - * ```html - *
- * - *
- * ``` - * - * ```js - * import { createI18n } from 'vue-i18n' - * - * const i18n = createI18n({ - * messages: { - * en: { - * contents: [ - * { - * title: 'Title1', - * // ... - * paragraphs: [ - * // ... - * ] - * } - * ] - * } - * } - * // ... - * }) - * ``` - * @param key - A target locale message key - * - * @return Locale messages - */ - tm: Composition['tm'] - /** - * Get locale message - * - * @remarks - * get locale message from VueI18n instance [messages](legacy#messages). - * - * @param locale - A target locale - * - * @returns Locale messages - */ - getLocaleMessage: Composition['getLocaleMessage'] - /** - * Set locale message - * - * @remarks - * Set locale message to VueI18n instance [messages](legacy#messages). - * - * @param locale - A target locale - * @param message - A message - */ - setLocaleMessage: Composition['setLocaleMessage'] - /** - * Merge locale message - * - * @remarks - * Merge locale message to VueI18n instance [messages](legacy#messages). - * - * @param locale - A target locale - * @param message - A message - */ - mergeLocaleMessage: Composition['mergeLocaleMessage'] - /** - * Datetime formatting - * - * @remarks - * About details functions, See the {@link VueI18nDateTimeFormatting} - */ - d: VueI18nDateTimeFormatting< - DateTimeFormats, - Locales, - RemoveIndexSignature<{ - [K in keyof DefineDateTimeFormat]: DefineDateTimeFormat[K] - }> - > - /** - * Get datetime format - * - * @remarks - * get datetime format from VueI18n instance [datetimeFormats](legacy#datetimeformats). - * - * @param locale - A target locale - * - * @returns Datetime format - */ - getDateTimeFormat: Composition['getDateTimeFormat'] - /** - * Set datetime format - * - * @remarks - * Set datetime format to VueI18n instance [datetimeFormats](legacy#datetimeformats). - * - * @param locale - A target locale - * @param format - A target datetime format - */ - setDateTimeFormat: Composition['setDateTimeFormat'] - /** - * Merge datetime format - * - * @remarks - * Merge datetime format to VueI18n instance [datetimeFormats](legacy#datetimeformats). - * - * @param locale - A target locale - * @param format - A target datetime format - */ - mergeDateTimeFormat: Composition['mergeDateTimeFormat'] - /** - * Number Formatting - * - * @remarks - * About details functions, See the {@link VueI18nNumberFormatting} - */ - n: VueI18nNumberFormatting< - NumberFormats, - Locales, - RemoveIndexSignature<{ - [K in keyof DefineNumberFormat]: DefineNumberFormat[K] - }> - > - /** - * Get number format - * - * @remarks - * get number format from VueI18n instance [numberFormats](legacy#numberFormats). - * - * @param locale - A target locale - * - * @returns Number format - */ - getNumberFormat: Composition['getNumberFormat'] - /** - * Set number format - * - * @remarks - * Set number format to VueI18n instance [numberFormats](legacy#numberFormats). - * - * @param locale - A target locale - * @param format - A target number format - */ - setNumberFormat: Composition['setNumberFormat'] - /** - * Merge number format - * - * @remarks - * Merge number format to VueI18n instance [numberFormats](legacy#numberFormats). - * - * @param locale - A target locale - * @param format - A target number format - */ - mergeNumberFormat: Composition['mergeNumberFormat'] -} - -/** - * @internal - * - * @deprecated will be removed at vue-i18n v12 - */ -export interface VueI18nInternal< - Messages extends Record = {}, - DateTimeFormats extends Record = {}, - NumberFormats extends Record = {} -> { - __composer: Composer - __enableEmitter?: (emitter: VueDevToolsEmitter) => void - __disableEmitter?: () => void - __extender?: VueI18nExtender - __disposer?: Disposer -} - -/** - * Convert to I18n Composer Options from VueI18n Options - * - * @internal - */ -function convertComposerOptions< - Messages extends Record = {}, - DateTimeFormats extends Record = {}, - NumberFormats extends Record = {} ->( - options: VueI18nOptions & - ComposerInternalOptions -): ComposerOptions & - ComposerInternalOptions { - const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE - const fallbackLocale = - isString(options.fallbackLocale) || - isArray(options.fallbackLocale) || - isPlainObject(options.fallbackLocale) || - options.fallbackLocale === false - ? options.fallbackLocale - : locale - const missing = isFunction(options.missing) ? options.missing : undefined - const missingWarn = - isBoolean(options.silentTranslationWarn) || - isRegExp(options.silentTranslationWarn) - ? !options.silentTranslationWarn - : true - const fallbackWarn = - isBoolean(options.silentFallbackWarn) || - isRegExp(options.silentFallbackWarn) - ? !options.silentFallbackWarn - : true - const fallbackRoot = isBoolean(options.fallbackRoot) - ? options.fallbackRoot - : true - const fallbackFormat = !!options.formatFallbackMessages - const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {} - const pluralizationRules = options.pluralizationRules - const postTranslation = isFunction(options.postTranslation) - ? options.postTranslation - : undefined - const warnHtmlMessage = isString(options.warnHtmlInMessage) - ? options.warnHtmlInMessage !== 'off' - : true - const escapeParameter = !!options.escapeParameterHtml - const inheritLocale = isBoolean(options.sync) ? options.sync : true - - let messages = options.messages - if (isPlainObject(options.sharedMessages)) { - const sharedMessages = options.sharedMessages - const locales: Locale[] = Object.keys(sharedMessages) - messages = locales.reduce( - (messages, locale) => { - const message = messages[locale] || (messages[locale] = {}) - assign(message, sharedMessages[locale]) - return messages - }, - (messages || {}) as LocaleMessages> - ) - } - const { __i18n, __root, __injectWithOption } = options - - const datetimeFormats = options.datetimeFormats - const numberFormats = options.numberFormats - const flatJson = options.flatJson - - return { - locale, - fallbackLocale, - messages, - flatJson, - datetimeFormats, - numberFormats, - missing, - missingWarn, - fallbackWarn, - fallbackRoot, - fallbackFormat, - modifiers, - pluralRules: pluralizationRules, - postTranslation, - warnHtmlMessage, - escapeParameter, - messageResolver: options.messageResolver, - inheritLocale, - __i18n, - __root, - __injectWithOption - } -} - -export function createVueI18n< - Options extends VueI18nOptions = VueI18nOptions, - Messages extends Record = Options['messages'] extends Record< - string, - any - > - ? Options['messages'] - : {}, - DateTimeFormats extends Record< - string, - any - > = Options['datetimeFormats'] extends Record - ? Options['datetimeFormats'] - : {}, - NumberFormats extends Record< - string, - any - > = Options['numberFormats'] extends Record - ? Options['numberFormats'] - : {} ->(options?: Options): VueI18n - -export function createVueI18n< - Schema extends object = DefaultLocaleMessageSchema, - Locales extends string | object = 'en-US', - Options extends VueI18nOptions< - SchemaParams, - LocaleParams - > = VueI18nOptions< - SchemaParams, - LocaleParams - >, - Messages extends Record = NonNullable< - Options['messages'] - > extends Record - ? NonNullable - : {}, - DateTimeFormats extends Record = NonNullable< - Options['datetimeFormats'] - > extends Record - ? NonNullable - : {}, - NumberFormats extends Record = NonNullable< - Options['numberFormats'] - > extends Record - ? NonNullable - : {} ->(options?: Options): VueI18n - -/** - * create VueI18n interface factory - * - * @internal - * - * @deprecated will be removed at vue-i18n v12 - */ - -export function createVueI18n(options: any = {}): any { - type Message = VueMessageType - - const composer = createComposer(convertComposerOptions(options)) as Composer - const { __extender } = options as unknown as VueI18nInternalOptions - - // defines VueI18n - const vueI18n = { - // id - id: composer.id, - - // locale - get locale(): Locale { - return composer.locale.value as Locale - }, - set locale(val: Locale) { - composer.locale.value = val as any - }, - - // fallbackLocale - get fallbackLocale(): FallbackLocale { - return composer.fallbackLocale.value as FallbackLocale - }, - set fallbackLocale(val: FallbackLocale) { - composer.fallbackLocale.value = val as any - }, - - // messages - get messages(): LocaleMessages { - return composer.messages.value - }, - - // datetimeFormats - get datetimeFormats(): DateTimeFormatsType { - return composer.datetimeFormats.value - }, - - // numberFormats - get numberFormats(): NumberFormatsType { - return composer.numberFormats.value - }, - - // availableLocales - get availableLocales(): Locale[] { - return composer.availableLocales.value - }, - - // missing - get missing(): MissingHandler | null { - return composer.getMissingHandler() - }, - set missing(handler: MissingHandler | null) { - composer.setMissingHandler(handler) - }, - - // silentTranslationWarn - get silentTranslationWarn(): boolean | RegExp { - return isBoolean(composer.missingWarn) - ? !composer.missingWarn - : composer.missingWarn - }, - set silentTranslationWarn(val: boolean | RegExp) { - composer.missingWarn = isBoolean(val) ? !val : val - }, - - // silentFallbackWarn - get silentFallbackWarn(): boolean | RegExp { - return isBoolean(composer.fallbackWarn) - ? !composer.fallbackWarn - : composer.fallbackWarn - }, - set silentFallbackWarn(val: boolean | RegExp) { - composer.fallbackWarn = isBoolean(val) ? !val : val - }, - - // modifiers - get modifiers(): LinkedModifiers { - return composer.modifiers - }, - - // formatFallbackMessages - get formatFallbackMessages(): boolean { - return composer.fallbackFormat - }, - set formatFallbackMessages(val: boolean) { - composer.fallbackFormat = val - }, - - // postTranslation - get postTranslation(): PostTranslationHandler | null { - return composer.getPostTranslationHandler() - }, - set postTranslation(handler: PostTranslationHandler | null) { - composer.setPostTranslationHandler(handler) - }, - - // sync - get sync(): boolean { - return composer.inheritLocale - }, - set sync(val: boolean) { - composer.inheritLocale = val - }, - - // warnInHtmlMessage - get warnHtmlInMessage(): WarnHtmlInMessageLevel { - return composer.warnHtmlMessage ? 'warn' : 'off' - }, - set warnHtmlInMessage(val: WarnHtmlInMessageLevel) { - composer.warnHtmlMessage = val !== 'off' - }, - - // escapeParameterHtml - get escapeParameterHtml(): boolean { - return composer.escapeParameter - }, - set escapeParameterHtml(val: boolean) { - composer.escapeParameter = val - }, - - // pluralizationRules - get pluralizationRules(): PluralizationRules { - return composer.pluralRules || {} - }, - - // for internal - __composer: composer, - - // t - t(...args: unknown[]): TranslateResult { - return Reflect.apply(composer.t, composer, [...args]) - }, - - // rt - rt(...args: unknown[]): TranslateResult { - return Reflect.apply(composer.rt, composer, [...args]) - }, - - // te - te(key: Path, locale?: Locale): boolean { - return composer.te(key, locale) - }, - - // tm - tm(key: Path): LocaleMessageValue | {} { - return composer.tm(key) - }, - - // getLocaleMessage - getLocaleMessage(locale: Locale): LocaleMessageDictionary { - return composer.getLocaleMessage(locale) - }, - - // setLocaleMessage - setLocaleMessage( - locale: Locale, - message: LocaleMessageDictionary - ): void { - composer.setLocaleMessage(locale, message) - }, - - // mergeLocaleMessage - mergeLocaleMessage( - locale: Locale, - message: LocaleMessageDictionary - ): void { - composer.mergeLocaleMessage(locale, message as any) - }, - - // d - d(...args: unknown[]): DateTimeFormatResult { - return Reflect.apply(composer.d, composer, [...args]) - }, - - // getDateTimeFormat - getDateTimeFormat(locale: Locale): DateTimeFormat { - return composer.getDateTimeFormat(locale) - }, - - // setDateTimeFormat - setDateTimeFormat(locale: Locale, format: DateTimeFormat): void { - composer.setDateTimeFormat(locale, format) - }, - - // mergeDateTimeFormat - mergeDateTimeFormat(locale: Locale, format: DateTimeFormat): void { - composer.mergeDateTimeFormat(locale, format) - }, - - // n - n(...args: unknown[]): NumberFormatResult { - return Reflect.apply(composer.n, composer, [...args]) - }, - - // getNumberFormat - getNumberFormat(locale: Locale): NumberFormat { - return composer.getNumberFormat(locale) - }, - - // setNumberFormat - setNumberFormat(locale: Locale, format: NumberFormat): void { - composer.setNumberFormat(locale, format) - }, - - // mergeNumberFormat - mergeNumberFormat(locale: Locale, format: NumberFormat): void { - composer.mergeNumberFormat(locale, format) - } - } - - // custom extender for vue-i18n-routing and nuxt i18n - ;(vueI18n as unknown as VueI18nInternal).__extender = __extender - - // for vue-devtools timeline event - if (__DEV__) { - ;(vueI18n as unknown as VueI18nInternal).__enableEmitter = ( - emitter: VueDevToolsEmitter - ): void => { - const __composer = composer as any - __composer[EnableEmitter] && __composer[EnableEmitter](emitter) - } - ;(vueI18n as unknown as VueI18nInternal).__disableEmitter = (): void => { - const __composer = composer as any - __composer[DisableEmitter] && __composer[DisableEmitter]() - } - } - - return vueI18n -} - -/* eslint-enable @typescript-eslint/no-explicit-any */ diff --git a/packages/vue-i18n-core/src/petite.ts b/packages/vue-i18n-core/src/petite.ts index c3031f00d..878d1b69d 100644 --- a/packages/vue-i18n-core/src/petite.ts +++ b/packages/vue-i18n-core/src/petite.ts @@ -62,22 +62,6 @@ export type { I18nScope, UseI18nOptions } from './i18n' -export type { - Choice, - DateTimeFormatResult, - LocaleMessageObject, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - WarnHtmlInMessageLevel -} from './legacy' export { initDev, initFeatureFlags, VERSION } from './misc' export type { I18nPluginOptions } from './plugin' export type { Disposer } from './types' diff --git a/packages/vue-i18n-core/src/types.ts b/packages/vue-i18n-core/src/types.ts index b83ab54bb..894b911ec 100644 --- a/packages/vue-i18n-core/src/types.ts +++ b/packages/vue-i18n-core/src/types.ts @@ -1,6 +1,4 @@ -import type { IsNever } from '@intlify/core-base' import type { ExportedGlobalComposer } from './i18n' -import type { VueI18n } from './legacy' export type Disposer = () => void @@ -26,20 +24,5 @@ export type Disposer = () => void export interface GeneratedTypeConfig {} -/** - * Narrowed i18n instance type based on `GeneratedTypeConfig['legacy']` - * - * - `never` (unset) resolves to `VueI18n | ExportedGlobalComposer` - * - `true` resolves to `VueI18n` - * - `false` resolves to `ExportedGlobalComposer` - */ -export type GeneratedInstanceType = - GeneratedTypeConfig extends Record<'legacy', infer Legacy> ? Legacy : never - /** @VueI18nGeneral */ -export type VueI18nInstance = - IsNever extends true - ? VueI18n | ExportedGlobalComposer - : GeneratedInstanceType extends true - ? VueI18n - : ExportedGlobalComposer +export type VueI18nInstance = ExportedGlobalComposer diff --git a/packages/vue-i18n-core/test/legacy.test-d.ts b/packages/vue-i18n-core/test/legacy.test-d.ts deleted file mode 100644 index eacc42e3e..000000000 --- a/packages/vue-i18n-core/test/legacy.test-d.ts +++ /dev/null @@ -1,231 +0,0 @@ -import { createVueI18n } from '../src/legacy' - -import type { - DateTimeFormat, - FallbackLocale, - Locale, - NumberFormat, - PickupFallbackLocales -} from '@intlify/core-base' -import type { ResourceSchema } from './schema' - -// loose options -const looseOptions = { - locale: 'en', - fallbackLocale: { - ja: ['en'] - }, - messages: { - en: { - foo: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error1'] - }, - ja: { - bar: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error2'] - } - }, - datetimeFormats: { - 'en-US': { - short: {} - } - }, - numberFormats: { - 'ja-JP': { - currency: {} - } - } -} - -// strict options -const strictOptions = { - locale: 'en', - fallbackLocale: { - ja: ['en'] - }, - messages: { - en: { - foo: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error1'] - }, - ja: { - foo: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error2'] - } - } -} - -test('loose legacy', () => { - const looseVueI18n = createVueI18n(looseOptions) - - expectTypeOf(looseVueI18n.locale).toEqualTypeOf< - 'en' | 'ja' | 'en-US' | 'ja-JP' - >() - expectTypeOf(looseVueI18n.fallbackLocale).toEqualTypeOf< - | 'en' - | 'ja' - | 'en-US' - | 'ja-JP' - | ('en' | 'ja' | 'en-US' | 'ja-JP')[] - | { - [x in string]: PickupFallbackLocales< - ['en' | 'ja' | 'en-US' | 'ja-JP'] - >[] - } - | false - >() - expectTypeOf(looseVueI18n.messages).toEqualTypeOf<{ - en: { foo: string; nest: { bar: string }; errors: string[] } - ja: { bar: string; nest: { bar: string }; errors: string[] } - }>() - expectTypeOf(looseVueI18n.datetimeFormats).toEqualTypeOf<{ - 'en-US': { short: {} } - }>() - expectTypeOf(looseVueI18n.numberFormats).toEqualTypeOf<{ - 'ja-JP': { currency: {} } - }>() - expectTypeOf(looseVueI18n.t('nest.bar')).toEqualTypeOf() - expectTypeOf(looseVueI18n.t('nest', 'en')).toEqualTypeOf() - expectTypeOf(looseVueI18n.t('foo', [1])).toEqualTypeOf() - expectTypeOf(looseVueI18n.t('nest', { foo: 1 })).toEqualTypeOf() - expectTypeOf(looseVueI18n.te('errors', 'en')).toEqualTypeOf() - expectTypeOf(looseVueI18n.tm('nest')).toEqualTypeOf<{ bar: string }>() - expectTypeOf(looseVueI18n.tm('errors')).toEqualTypeOf() - expectTypeOf(looseVueI18n.rt('foo')).toEqualTypeOf() - expectTypeOf(looseVueI18n.getLocaleMessage('en')).toEqualTypeOf<{ - foo: string - nest: { bar: string } - errors: string[] - }>() - expectTypeOf( - looseVueI18n.getLocaleMessage<{ japan: string }>('japan') - ).toEqualTypeOf<{ japan: string }>() - - looseVueI18n.setLocaleMessage('en', { - foo: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error1'] - }) - looseVueI18n.setLocaleMessage<{ dio: string }>('jojo', { dio: 'dio' }) - looseVueI18n.mergeLocaleMessage('en', { - bar: 'foo' - }) - looseVueI18n.setDateTimeFormat('ja-JP', { - short: { - hour: 'numeric' - } - }) - looseVueI18n.setDateTimeFormat<{ stop: { hour: string } }>('world', { - stop: { hour: 'infinity' } - }) - looseVueI18n.mergeDateTimeFormat('en-US', { - long: { hour: 'numeric' } - }) - looseVueI18n.mergeDateTimeFormat<{ stop: { hour: string } }>('en-US', { - stop: { hour: 'infinity' } - }) - - expectTypeOf(looseVueI18n.getDateTimeFormat('en-US')).toEqualTypeOf<{ - short: {} - }>() - expectTypeOf( - looseVueI18n.getDateTimeFormat<{ long: { hour: string } }>('en-US') - ).toEqualTypeOf<{ long: { hour: string } }>() - - looseVueI18n.setNumberFormat('en-US', { - currency: { - currecy: 'USD' - } - }) - looseVueI18n.setNumberFormat<{ echoes: { act: string } }>('stand', { - echoes: { act: '2' } - }) - looseVueI18n.mergeNumberFormat('ja-JP', { - weight: { - unit: 'kiro' - } - }) - looseVueI18n.mergeNumberFormat<{ echoes: { act: string } }>('ja-JP', { - echoes: { act: '2' } - }) -}) - -test('strict legacy', () => { - const strictVueI18n = createVueI18n<[ResourceSchema], 'en' | 'ja'>( - strictOptions - ) - - expectTypeOf(strictVueI18n.locale).toEqualTypeOf<'en' | 'ja'>() - expectTypeOf(strictVueI18n.fallbackLocale).toEqualTypeOf< - | 'en' - | 'ja' - | ('en' | 'ja')[] - | { [x in string]: PickupFallbackLocales<['en' | 'ja']>[] } - | false - >() - expectTypeOf(strictVueI18n.messages).toEqualTypeOf<{ - en: { foo: string; nest: { bar: string }; errors: string[] } - ja: { foo: string; nest: { bar: string }; errors: string[] } - }>() - expectTypeOf(strictVueI18n.datetimeFormats).toEqualTypeOf<{ - en: DateTimeFormat - ja: DateTimeFormat - }>() - expectTypeOf(strictVueI18n.numberFormats).toEqualTypeOf<{ - en: NumberFormat - ja: NumberFormat - }>() - expectTypeOf(strictVueI18n.t('nest.bar')).toEqualTypeOf() - expectTypeOf(strictVueI18n.t('nest', 'en')).toEqualTypeOf() - expectTypeOf(strictVueI18n.t('foo', [1])).toEqualTypeOf() - expectTypeOf(strictVueI18n.t('nest', { foo: 1 })).toEqualTypeOf() - expectTypeOf(strictVueI18n.te('errors', 'en')).toEqualTypeOf() - expectTypeOf(strictVueI18n.tm('nest')).toEqualTypeOf<{ bar: string }>() - expectTypeOf(strictVueI18n.tm('errors')).toEqualTypeOf() - expectTypeOf(strictVueI18n.rt('foo')).toEqualTypeOf() - expectTypeOf(strictVueI18n.getLocaleMessage('en')).toEqualTypeOf<{ - foo: string - nest: { bar: string } - errors: string[] - }>() - expectTypeOf( - strictVueI18n.getLocaleMessage<{ japan: string }>('japan') - ).toEqualTypeOf<{ japan: string }>() - - strictVueI18n.setLocaleMessage('en', { - foo: 'foo', - nest: { - bar: 'bar' - }, - errors: ['error1'] - }) - strictVueI18n.setLocaleMessage<{ dio: string }>('jojo', { - dio: 'The world!' - }) - strictVueI18n.mergeLocaleMessage('en', { - bar: 'foo' - }) - strictVueI18n.mergeLocaleMessage<{ dio: string }>('en', { - dio: 'The world!' - }) - - const nullVueI18n = createVueI18n({}) - expectTypeOf(nullVueI18n.locale).toEqualTypeOf() - nullVueI18n.locale = 'en' - expectTypeOf(nullVueI18n.fallbackLocale).toEqualTypeOf() - nullVueI18n.fallbackLocale = 'fr' -}) diff --git a/packages/vue-i18n-core/test/legacy.test.ts b/packages/vue-i18n-core/test/legacy.test.ts deleted file mode 100644 index 3e4bc1a76..000000000 --- a/packages/vue-i18n-core/test/legacy.test.ts +++ /dev/null @@ -1,592 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ - -// utils -import * as shared from '@intlify/shared' -vi.mock('@intlify/shared', async () => { - const actual = await vi.importActual('@intlify/shared') - return { - ...actual, - warn: vi.fn(), - warnOnce: vi.fn() - } -}) - -import { - compile, - registerMessageCompiler, - registerMessageResolver, - resolveValue -} from '@intlify/core-base' -import { nextTick, watchEffect } from 'vue' -import { createVueI18n } from '../src/legacy' -import { pluralRules as _pluralRules } from './helper' - -import type { MessageContext, Path, PathValue } from '@intlify/core-base' -import type { VueMessageType } from '../src/composer' - -beforeEach(() => { - registerMessageCompiler(compile) - registerMessageResolver(resolveValue) -}) - -test('locale', () => { - const i18n = createVueI18n() - expect(i18n.locale).toEqual('en-US') - i18n.locale = 'ja' - expect(i18n.locale).toEqual('ja') -}) - -test('fallbackLocale', () => { - const i18n = createVueI18n() - expect(i18n.fallbackLocale).toEqual('en-US') - i18n.fallbackLocale = 'ja' - expect(i18n.fallbackLocale).toEqual('ja') -}) - -describe('availableLocales', () => { - test('initialize messages', async () => { - const i18n = createVueI18n({ - messages: { - en: {}, - ja: {}, - fr: {} - } - }) - expect(i18n.availableLocales).toEqual(['en', 'ja', 'fr'].sort()) - }) - test('reactive update', () => { - const i18n = createVueI18n({ - messages: { - en: {}, - ja: {}, - fr: {} - } - }) - i18n.setLocaleMessage('ru', { hello: 'Привет мир!' }) - expect(i18n.availableLocales).toEqual(['en', 'ja', 'fr', 'ru'].sort()) - }) - test('trigger new value with watchEffect', async () => { - const i18n = createVueI18n({ - messages: { - ja: {} - } - }) - let locales = [] as string[] - - watchEffect(() => { - locales = i18n.availableLocales - }) - - i18n.setLocaleMessage('en', { hello: 'Hello' }) - await nextTick() - expect(locales.sort()).toEqual(['en', 'ja'].sort()) - }) -}) - -test('missing', () => { - const i18n = createVueI18n() - expect(i18n.missing).toEqual(null) - const handler = (_: unknown, key: string) => { - return key.toUpperCase() - } - i18n.missing = handler - expect(i18n.missing).toEqual(handler) - expect(i18n.t('foo.bar.buz')).toEqual('FOO.BAR.BUZ') -}) - -test('silentTranslationWarn', () => { - // default - const i18n = createVueI18n() - expect(i18n.silentTranslationWarn).toEqual(false) - i18n.silentTranslationWarn = true - expect(i18n.silentTranslationWarn).toEqual(true) - i18n.silentTranslationWarn = /^hi.*$/ - expect(i18n.silentTranslationWarn).toEqual(/^hi.*$/) - - // with option - const i18nWithOption = createVueI18n({ silentTranslationWarn: true }) - expect(i18nWithOption.silentTranslationWarn).toEqual(true) -}) - -test('silentFallbackWarn', () => { - // default - const i18n = createVueI18n() - expect(i18n.silentFallbackWarn).toEqual(false) - i18n.silentFallbackWarn = true - expect(i18n.silentFallbackWarn).toEqual(true) - i18n.silentFallbackWarn = /^hi.*$/ - expect(i18n.silentFallbackWarn).toEqual(/^hi.*$/) - - // with option - const i18nWithOption = createVueI18n({ silentFallbackWarn: true }) - expect(i18nWithOption.silentFallbackWarn).toEqual(true) -}) - -test('formatFallbackMessages', () => { - // default - const i18n = createVueI18n() - expect(i18n.formatFallbackMessages).toEqual(false) - i18n.formatFallbackMessages = true - expect(i18n.formatFallbackMessages).toEqual(true) - - // withOption - const i18nWithOption = createVueI18n({ formatFallbackMessages: true }) - expect(i18nWithOption.formatFallbackMessages).toEqual(true) -}) - -test('postTranslation', () => { - const i18n = createVueI18n() - expect(i18n.postTranslation).toEqual(null) - const postTranslation = (str: VueMessageType) => - shared.isString(str) ? str.trim() : str - i18n.postTranslation = postTranslation - expect(i18n.postTranslation).toEqual(postTranslation) -}) - -test('pluralizationRules', () => { - const i18n = createVueI18n({ - locale: 'ru', - pluralizationRules: _pluralRules, - messages: { - ru: { - car: '0 машин | {n} машина | {n} машины | {n} машин' - } - } - }) - - expect(i18n.pluralizationRules).toEqual(_pluralRules) - expect(i18n.t('car', 1)).toEqual('1 машина') - expect(i18n.t('car', 2)).toEqual('2 машины') - expect(i18n.t('car', 4)).toEqual('4 машины') - expect(i18n.t('car', 12)).toEqual('12 машин') - expect(i18n.t('car', 21)).toEqual('21 машина') -}) - -test('messages', () => { - const i18n = createVueI18n() - expect(i18n.messages).toEqual({ - 'en-US': {} - }) -}) - -test('datetimeFormats', () => { - const i18n = createVueI18n() - expect(i18n.datetimeFormats).toEqual({ - 'en-US': {} - }) -}) - -test('numberFormats', () => { - const i18n = createVueI18n() - expect(i18n.numberFormats).toEqual({ - 'en-US': {} - }) -}) - -describe('t', () => { - test('basic', () => { - const i18n = createVueI18n({ - locale: 'en', - messages: { - en: { - name: 'kazupon', - hello: 'Hello!', - hi: 'hi {name}!', - morning: 'good morning {0}', - linked: 'hi @.upper:name' - } - } - }) - - expect(i18n.t('hello')).toEqual('Hello!') - expect(i18n.t('hi', { name: 'kazupon' })).toEqual('hi kazupon!') - expect(i18n.t('morning', ['kazupon'])).toEqual('good morning kazupon') - expect(i18n.t('linked')).toEqual('hi KAZUPON') - }) -}) - -describe('rt', () => { - test('compilation', () => { - const i18n = createVueI18n({ - locale: 'en', - messages: { - en: { - text: 'hi dio!', - list: 'hi {0}!', - named: 'hi {name}!', - name: 'dio', - linked: 'hi @.upper:name !', - pural: 'no apples | one apple | {count} apples' - } - } - }) - - expect(i18n.rt(i18n.messages.en.text)).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.list, ['dio'])).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.named, { name: 'dio' })).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.linked)).toEqual('hi DIO !') - expect(i18n.rt(i18n.messages.en.pural, 2)).toEqual('2 apples') - }) - - test('message functions', () => { - const i18n = createVueI18n({ - locale: 'en', - messages: { - en: { - text: () => 'hi dio!', - list: (ctx: MessageContext) => `hi ${ctx.list(0)}!`, - named: (ctx: MessageContext) => - `hi ${ctx.named('name')}!`, - name: 'dio', - linked: (ctx: MessageContext) => - `hi ${ctx.linked('name', 'upper')} !`, - pural: (ctx: MessageContext) => - ctx.plural([ - 'no apples', - 'one apple', - `${ctx.named('count')} apples` - ]) as string - } - } - }) - - expect(i18n.rt(i18n.messages.en.text)).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.list, ['dio'])).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.named, { name: 'dio' })).toEqual('hi dio!') - expect(i18n.rt(i18n.messages.en.linked)).toEqual('hi DIO !') - expect(i18n.rt(i18n.messages.en.pural, 2)).toEqual('2 apples') - }) -}) - -test('te', () => { - const i18n = createVueI18n({ - locale: 'en', - messages: { - en: { - message: { - hello: 'Hello!' - } - }, - ja: {} - } - }) - - expect(i18n.te('message.hello')).toEqual(true) - expect(i18n.te('message.hallo')).toEqual(false) - expect(i18n.te('message.hallo', 'ja')).toEqual(false) -}) - -test('tm', async () => { - const i18n = createVueI18n({ - locale: 'ja', - messages: { - en: {}, - ja: { - foo: { - bar: { - buz: 'hello' - }, - codes: { - errors: ['error1', 'error2'] - } - } - } - } - }) - - let messages1 = i18n.tm('foo.bar') - let messages2 = i18n.tm('foo.codes') - expect(messages1).toEqual({ buz: 'hello' }) - expect(messages2).toEqual({ errors: ['error1', 'error2'] }) - - watchEffect(() => { - messages1 = i18n.tm('foo.bar') - messages2 = i18n.tm('foo.codes') - }) - - i18n.locale = 'en' - await nextTick() - - expect(messages1).toEqual({ buz: 'hello' }) - expect(messages2).toEqual({ errors: ['error1', 'error2'] }) -}) - -test('getLocaleMessage / setLocaleMessage / mergeLocaleMessage', () => { - const i18n = createVueI18n({ - messages: { - en: { hello: 'Hello!' } - } - }) - expect(i18n.getLocaleMessage('en')).toEqual({ hello: 'Hello!' }) - - i18n.setLocaleMessage<{ hi: { hi: string } }>('en', { hi: { hi: 'hi!' } }) - expect(i18n.getLocaleMessage('en')).toEqual({ hi: { hi: 'hi!' } }) - - i18n.mergeLocaleMessage('en', { hi: { hello: 'hello!' } }) - expect(i18n.getLocaleMessage('en')).toEqual({ - hi: { - hi: 'hi!', - hello: 'hello!' - } - }) -}) - -test('d', () => { - const i18n = createVueI18n({ - locale: 'en-US', - fallbackLocale: 'ja-JP', - datetimeFormats: { - 'en-US': { - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - timeZone: 'America/New_York' - } - }, - 'ja-JP': { - long: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - timeZone: 'Asia/Tokyo' - }, - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - timeZone: 'Asia/Tokyo' - } - } - } - }) - const dt = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) - expect(i18n.d(dt, 'short', 'ja-JP')).toEqual('2012/12/20 12:00') -}) - -test('n', () => { - const i18n = createVueI18n({ - locale: 'en-US', - fallbackLocale: 'ja-JP', - numberFormats: { - 'en-US': { - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - }, - decimal: { - style: 'decimal', - useGrouping: false - } - }, - 'ja-JP': { - currency: { - style: 'currency', - currency: 'JPY' /*, currencyDisplay: 'symbol'*/ - }, - numeric: { - style: 'decimal', - useGrouping: false - }, - percent: { - style: 'percent', - useGrouping: false - } - } - } - }) - expect(i18n.n(0.99, 'percent', 'ja-JP')).toEqual('99%') -}) - -test('getDateTimeFormat / setDateTimeFormat / mergeDateTimeFormat', () => { - const i18n = createVueI18n({ - datetimeFormats: { - 'en-US': { - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - } - } - } - }) - expect(i18n.getDateTimeFormat('en-US')).toEqual({ - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - } - }) - - i18n.setDateTimeFormat<{ - long: { - year: string - month: string - day: string - hour: string - minute: string - second: string - } - }>('en-US', { - long: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - } - }) - expect(i18n.getDateTimeFormat('en-US')).toEqual({ - long: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - } - }) - - i18n.mergeDateTimeFormat('en-US', { - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - } - }) - expect(i18n.getDateTimeFormat('en-US')).toEqual({ - short: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - }, - long: { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - } - }) -}) - -test('getNumberFormat / setNumberFormat / mergeNumberFormat', () => { - const i18n = createVueI18n({ - numberFormats: { - 'en-US': { - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - } - } - } - }) - expect(i18n.getNumberFormat('en-US')).toEqual({ - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - } - }) - - i18n.setNumberFormat<{ decimal: { style: string; useGrouping: boolean } }>( - 'en-US', - { - decimal: { - style: 'decimal', - useGrouping: false - } - } - ) - expect(i18n.getNumberFormat('en-US')).toEqual({ - decimal: { - style: 'decimal', - useGrouping: false - } - }) - - i18n.mergeNumberFormat('en-US', { - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - } - }) - expect(i18n.getNumberFormat('en-US')).toEqual({ - currency: { - style: 'currency', - currency: 'USD', - currencyDisplay: 'symbol' - }, - decimal: { - style: 'decimal', - useGrouping: false - } - }) -}) - -test('warnHtmlInMessage', () => { - const mockWarn = vi.spyOn(shared, 'warn') - mockWarn.mockImplementation(() => {}) - - const i18n = createVueI18n({ - locale: 'en', - messages: { - en: { - hello: '

hello

' - } - } - }) - - expect(i18n.t('hello')).toEqual('

hello

') - - i18n.warnHtmlInMessage = 'off' - expect(i18n.t('hello')).toEqual('

hello

') - - i18n.warnHtmlInMessage = 'error' - expect(i18n.t('hello')).toEqual('

hello

') - expect(mockWarn).toHaveBeenCalledTimes(2) -}) - -test('messageResolver', () => { - const mockMessageResolver = vi.fn() - mockMessageResolver.mockImplementation( - (obj: unknown, path: Path): PathValue => { - return path - } - ) - - const i18n = createVueI18n({ - locale: 'en', - messageResolver: mockMessageResolver, - messages: { - en: {} - } - }) - - expect(i18n.t('path.to.message')).toEqual('path.to.message') - expect(mockMessageResolver).toHaveBeenCalledTimes(1) - expect(mockMessageResolver.mock.calls[0][0]).toEqual({}) - expect(mockMessageResolver.mock.calls[0][1]).toEqual('path.to.message') -}) - -/* eslint-enable @typescript-eslint/no-empty-function */ diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index 409f75fc1..7aa2507e0 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -63,7 +63,6 @@ export { } from '@intlify/vue-i18n-core' export type { BaseFormatProps, - Choice, ComponentI18nScope, Composer, ComposerAdditionalOptions, @@ -78,7 +77,6 @@ export type { CustomBlocks, DatetimeFormat, DatetimeFormatProps, - DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, @@ -96,26 +94,14 @@ export type { I18nPluginOptions, I18nScope, I18nT, - LocaleMessageObject, MissingHandler, NumberFormat, NumberFormatProps, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, Translation, TranslationProps, UseI18nOptions, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, VueI18nInstance, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - VueMessageType, - WarnHtmlInMessageLevel + VueMessageType } from '@intlify/vue-i18n-core' export type { diff --git a/packages/vue-i18n/src/runtime.ts b/packages/vue-i18n/src/runtime.ts index 72664e491..a742ea098 100644 --- a/packages/vue-i18n/src/runtime.ts +++ b/packages/vue-i18n/src/runtime.ts @@ -62,7 +62,6 @@ export { } from '@intlify/vue-i18n-core' export type { BaseFormatProps, - Choice, ComponentI18nScope, Composer, ComposerAdditionalOptions, @@ -77,7 +76,6 @@ export type { CustomBlocks, DatetimeFormat, DatetimeFormatProps, - DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, @@ -95,25 +93,13 @@ export type { I18nPluginOptions, I18nScope, I18nT, - LocaleMessageObject, MissingHandler, NumberFormat, NumberFormatProps, - NumberFormatResult, - PluralizationRulesMap, - TranslateResult, Translation, TranslationProps, UseI18nOptions, - VueI18n, - VueI18nDateTimeFormatting, - VueI18nExtender, - VueI18nNumberFormatting, - VueI18nOptions, - VueI18nResolveLocaleMessageTranslation, - VueI18nTranslation, - VueMessageType, - WarnHtmlInMessageLevel + VueMessageType } from '@intlify/vue-i18n-core' export type { From 3c1488c5db1a2310ed87f6c85196ffabc7f77fab Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 18:17:33 +0900 Subject: [PATCH 07/18] fix others --- e2e/fallback/basic.spec.ts | 5 +---- e2e/fallback/default-format.spec.ts | 5 +---- e2e/fallback/format.spec.ts | 5 +---- e2e/fallback/option.spec.ts | 5 +---- e2e/fallback/suppress.spec.ts | 5 +---- e2e/missing/handler.spec.ts | 5 +---- e2e/missing/option.spec.ts | 5 +---- e2e/missing/suppress.spec.ts | 5 +---- 8 files changed, 8 insertions(+), 32 deletions(-) diff --git a/e2e/fallback/basic.spec.ts b/e2e/fallback/basic.spec.ts index 49757631c..bed9ef0e4 100644 --- a/e2e/fallback/basic.spec.ts +++ b/e2e/fallback/basic.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/fallback/default-format.spec.ts b/e2e/fallback/default-format.spec.ts index 35bdb9a73..f30ea86de 100644 --- a/e2e/fallback/default-format.spec.ts +++ b/e2e/fallback/default-format.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/fallback/format.spec.ts b/e2e/fallback/format.spec.ts index 40e18f49b..38ca9fca1 100644 --- a/e2e/fallback/format.spec.ts +++ b/e2e/fallback/format.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/fallback/option.spec.ts b/e2e/fallback/option.spec.ts index f3f42b85b..6021f2a1e 100644 --- a/e2e/fallback/option.spec.ts +++ b/e2e/fallback/option.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/fallback/suppress.spec.ts b/e2e/fallback/suppress.spec.ts index 11b2482e9..fe9029bf3 100644 --- a/e2e/fallback/suppress.spec.ts +++ b/e2e/fallback/suppress.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/missing/handler.spec.ts b/e2e/missing/handler.spec.ts index 579b961b9..68b42028c 100644 --- a/e2e/missing/handler.spec.ts +++ b/e2e/missing/handler.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/missing/option.spec.ts b/e2e/missing/option.spec.ts index b0f234f0f..0d5df96d2 100644 --- a/e2e/missing/option.spec.ts +++ b/e2e/missing/option.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } diff --git a/e2e/missing/suppress.spec.ts b/e2e/missing/suppress.spec.ts index d3201c499..29291a77b 100644 --- a/e2e/missing/suppress.spec.ts +++ b/e2e/missing/suppress.spec.ts @@ -6,10 +6,7 @@ import { getText, url } from '../helper' page.on('console', msg => { if (msg.type() === 'warning') { const text = msg.text() - if ( - !text.match(/^\[intlify\] Legacy API mode has been/) && - !text.match(/^\[intlify\] 'v-t' has been deprecated in v11/) - ) { + if (!text.match(/^\[intlify\] 'v-t' has been deprecated in v11/)) { warnings.push(msg.text()) } } From 25245cea6d509a626fd3f8278024213a2faccba7 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 18:46:14 +0900 Subject: [PATCH 08/18] remove mode --- packages/vue-i18n-core/src/i18n.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index 599c11d1f..f73970c06 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -383,10 +383,6 @@ export function createI18n(options: any = {}): any { } const i18n = { - // mode - get mode() { - return 'composition' - }, // install plugin async install(app: App, ...options: unknown[]): Promise { if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__) { From cf28db989eb6391f9dea975ca273698b9bee7eb0 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 19:18:29 +0900 Subject: [PATCH 09/18] fix others --- benchmark/complex-jit-aot.mjs | 1 - benchmark/complex-jit.mjs | 1 - benchmark/complex.mjs | 1 - benchmark/simple-jit-aot.mjs | 1 - benchmark/simple-jit.mjs | 1 - benchmark/simple.mjs | 1 - e2e/hotfix/CVE-2024-52809.html | 1 - examples/backend/src/main.ts | 1 - examples/composition/components/datetime-format.html | 1 - examples/composition/components/number-format.html | 1 - examples/composition/components/translation.html | 1 - examples/composition/datetime.html | 1 - examples/composition/fallback/basic.html | 1 - examples/composition/fallback/component.html | 1 - examples/composition/fallback/default-format.html | 1 - examples/composition/fallback/format.html | 1 - examples/composition/fallback/option.html | 1 - examples/composition/fallback/suppress.html | 1 - examples/composition/formatting/linked.html | 1 - examples/composition/formatting/list.html | 1 - examples/composition/formatting/literal.html | 1 - examples/composition/formatting/named.html | 1 - examples/composition/functions/linked.html | 1 - examples/composition/functions/list.html | 1 - examples/composition/functions/named.html | 1 - examples/composition/functions/plural.html | 1 - examples/composition/missing/handler.html | 1 - examples/composition/missing/option.html | 1 - examples/composition/missing/suppress.html | 1 - examples/composition/number.html | 1 - examples/composition/plural/basic.html | 1 - examples/composition/plural/custom.html | 1 - examples/composition/scope/global.html | 1 - examples/composition/scope/inherit-locale.html | 1 - examples/composition/scope/local.html | 1 - examples/composition/started.html | 1 - examples/frameworks/nuxt3/plugins/i18n.ts | 1 - examples/lazy-loading/vite/src/main.ts | 1 - examples/lazy-loading/webpack/src/main.js | 1 - examples/message-format/src/main.ts | 1 - examples/petite/plural/basic.html | 1 - examples/petite/plural/custom.html | 1 - examples/ssr/vite/src/i18n.js | 1 - examples/ssr/vitepress/.vitepress/theme/index.ts | 1 - examples/tsx/src/main.ts | 1 - .../type-safe/global-type-definition/src/main.ts | 1 - examples/type-safe/type-annotation/src/main.ts | 1 - .../web-components/src/components/I18nHost.ce.vue | 1 - examples/web-components/src/main.ts | 1 - packages/vue-i18n-core/src/composer.ts | 2 -- packages/vue-i18n-core/src/errors.ts | 12 ++---------- .../test/components/Translation.test.ts | 5 ----- packages/vue-i18n-core/test/errors.test.ts | 2 +- packages/vue-i18n-core/test/ssr.test.ts | 2 -- 54 files changed, 3 insertions(+), 69 deletions(-) diff --git a/benchmark/complex-jit-aot.mjs b/benchmark/complex-jit-aot.mjs index c1ed84488..da5613661 100644 --- a/benchmark/complex-jit-aot.mjs +++ b/benchmark/complex-jit-aot.mjs @@ -45,7 +45,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', modifiers: { caml: val => val diff --git a/benchmark/complex-jit.mjs b/benchmark/complex-jit.mjs index 154e9482e..de0d333a8 100644 --- a/benchmark/complex-jit.mjs +++ b/benchmark/complex-jit.mjs @@ -34,7 +34,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', modifiers: { caml: val => val diff --git a/benchmark/complex.mjs b/benchmark/complex.mjs index 5fa7aad19..55cc9b3b7 100644 --- a/benchmark/complex.mjs +++ b/benchmark/complex.mjs @@ -28,7 +28,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', modifiers: { caml: val => val diff --git a/benchmark/simple-jit-aot.mjs b/benchmark/simple-jit-aot.mjs index dcb91affa..6b0392286 100644 --- a/benchmark/simple-jit-aot.mjs +++ b/benchmark/simple-jit-aot.mjs @@ -40,7 +40,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: precompiledResources diff --git a/benchmark/simple-jit.mjs b/benchmark/simple-jit.mjs index 3bac413b8..61b8522c2 100644 --- a/benchmark/simple-jit.mjs +++ b/benchmark/simple-jit.mjs @@ -29,7 +29,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: resources diff --git a/benchmark/simple.mjs b/benchmark/simple.mjs index fe9874547..246206e68 100644 --- a/benchmark/simple.mjs +++ b/benchmark/simple.mjs @@ -23,7 +23,6 @@ const ctx = createCoreContext({ }) const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: resources diff --git a/e2e/hotfix/CVE-2024-52809.html b/e2e/hotfix/CVE-2024-52809.html index c2e6c3cbf..2a5c043e9 100644 --- a/e2e/hotfix/CVE-2024-52809.html +++ b/e2e/hotfix/CVE-2024-52809.html @@ -49,7 +49,6 @@ } const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en diff --git a/examples/backend/src/main.ts b/examples/backend/src/main.ts index cb40f41cd..443cacbf9 100644 --- a/examples/backend/src/main.ts +++ b/examples/backend/src/main.ts @@ -12,7 +12,6 @@ const messages = await load(locales) // create i18n instance const i18n = createI18n<[ResourceSchema], Locales, false>({ - legacy: false, locale: 'en', messages }) diff --git a/examples/composition/components/datetime-format.html b/examples/composition/components/datetime-format.html index 48521377e..47c840ba6 100644 --- a/examples/composition/components/datetime-format.html +++ b/examples/composition/components/datetime-format.html @@ -39,7 +39,6 @@

slot usages:

const { createI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en-US', datetimeFormats: { 'en-US': { diff --git a/examples/composition/components/number-format.html b/examples/composition/components/number-format.html index d09e9668a..cb8db41ea 100644 --- a/examples/composition/components/number-format.html +++ b/examples/composition/components/number-format.html @@ -47,7 +47,6 @@

slot usages:

const { createI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en-US', numberFormats: { 'en-US': { diff --git a/examples/composition/components/translation.html b/examples/composition/components/translation.html index e2d97578d..88a5d01dc 100644 --- a/examples/composition/components/translation.html +++ b/examples/composition/components/translation.html @@ -59,7 +59,6 @@

localize with using plural:

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/datetime.html b/examples/composition/datetime.html index 9a6e63753..4f02e0fe4 100644 --- a/examples/composition/datetime.html +++ b/examples/composition/datetime.html @@ -23,7 +23,6 @@

DateTime Localization for Composition API

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja-JP', messages: { 'en-US': { diff --git a/examples/composition/fallback/basic.html b/examples/composition/fallback/basic.html index a8310e795..ae3017148 100644 --- a/examples/composition/fallback/basic.html +++ b/examples/composition/fallback/basic.html @@ -15,7 +15,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], messages: { diff --git a/examples/composition/fallback/component.html b/examples/composition/fallback/component.html index db2d6879f..c2820145e 100644 --- a/examples/composition/fallback/component.html +++ b/examples/composition/fallback/component.html @@ -25,7 +25,6 @@

Root

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/fallback/default-format.html b/examples/composition/fallback/default-format.html index 243708fd2..66b06df03 100644 --- a/examples/composition/fallback/default-format.html +++ b/examples/composition/fallback/default-format.html @@ -27,7 +27,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], messages: { diff --git a/examples/composition/fallback/format.html b/examples/composition/fallback/format.html index 820bd7447..5d10a7db8 100644 --- a/examples/composition/fallback/format.html +++ b/examples/composition/fallback/format.html @@ -15,7 +15,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackFormat: true, // enable, fallback to locale message key messages: { diff --git a/examples/composition/fallback/option.html b/examples/composition/fallback/option.html index 303987b53..62e083da4 100644 --- a/examples/composition/fallback/option.html +++ b/examples/composition/fallback/option.html @@ -18,7 +18,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], messages: { diff --git a/examples/composition/fallback/suppress.html b/examples/composition/fallback/suppress.html index 3e3d08b40..ac4ac3858 100644 --- a/examples/composition/fallback/suppress.html +++ b/examples/composition/fallback/suppress.html @@ -15,7 +15,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], fallbackWarn: false, // warning off diff --git a/examples/composition/formatting/linked.html b/examples/composition/formatting/linked.html index 73c3b657a..af981fb50 100644 --- a/examples/composition/formatting/linked.html +++ b/examples/composition/formatting/linked.html @@ -27,7 +27,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/composition/formatting/list.html b/examples/composition/formatting/list.html index 6cba3469f..74fb77741 100644 --- a/examples/composition/formatting/list.html +++ b/examples/composition/formatting/list.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/formatting/literal.html b/examples/composition/formatting/literal.html index 86ce30eec..fddb3e08a 100644 --- a/examples/composition/formatting/literal.html +++ b/examples/composition/formatting/literal.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/formatting/named.html b/examples/composition/formatting/named.html index 34114fa99..3f24f693e 100644 --- a/examples/composition/formatting/named.html +++ b/examples/composition/formatting/named.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/functions/linked.html b/examples/composition/functions/linked.html index c61797d22..92edbd7f9 100644 --- a/examples/composition/functions/linked.html +++ b/examples/composition/functions/linked.html @@ -27,7 +27,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/composition/functions/list.html b/examples/composition/functions/list.html index f2176d649..e3044d991 100644 --- a/examples/composition/functions/list.html +++ b/examples/composition/functions/list.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/functions/named.html b/examples/composition/functions/named.html index 7d8752421..12b44bf8e 100644 --- a/examples/composition/functions/named.html +++ b/examples/composition/functions/named.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/functions/plural.html b/examples/composition/functions/plural.html index b13d11603..149e78a3d 100644 --- a/examples/composition/functions/plural.html +++ b/examples/composition/functions/plural.html @@ -26,7 +26,6 @@

Banana:

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/composition/missing/handler.html b/examples/composition/missing/handler.html index 8e1cfb3d7..b785c39e4 100644 --- a/examples/composition/missing/handler.html +++ b/examples/composition/missing/handler.html @@ -15,7 +15,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], missing: (locale, key, instance) => { diff --git a/examples/composition/missing/option.html b/examples/composition/missing/option.html index 19f8bf404..cbd53fb15 100644 --- a/examples/composition/missing/option.html +++ b/examples/composition/missing/option.html @@ -18,7 +18,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], messages: { diff --git a/examples/composition/missing/suppress.html b/examples/composition/missing/suppress.html index 63112f9cd..dc659cc81 100644 --- a/examples/composition/missing/suppress.html +++ b/examples/composition/missing/suppress.html @@ -15,7 +15,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', fallbackLocale: ['en'], missingWarn: false, // warning off diff --git a/examples/composition/number.html b/examples/composition/number.html index c475def1d..d3637ecf6 100644 --- a/examples/composition/number.html +++ b/examples/composition/number.html @@ -31,7 +31,6 @@

Number Localization for Composition API

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja-JP', messages: { 'en-US': { diff --git a/examples/composition/plural/basic.html b/examples/composition/plural/basic.html index 7a7ac5c07..793eec5c4 100644 --- a/examples/composition/plural/basic.html +++ b/examples/composition/plural/basic.html @@ -26,7 +26,6 @@

Banana:

const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/composition/plural/custom.html b/examples/composition/plural/custom.html index b7cabab60..b01e29b6a 100644 --- a/examples/composition/plural/custom.html +++ b/examples/composition/plural/custom.html @@ -43,7 +43,6 @@

Banana:

} const i18n = createI18n({ - legacy: false, locale: 'ru', pluralRules: { ru: customRule diff --git a/examples/composition/scope/global.html b/examples/composition/scope/global.html index b0ceb754c..a82113f3b 100644 --- a/examples/composition/scope/global.html +++ b/examples/composition/scope/global.html @@ -75,7 +75,6 @@

Child

} const i18n = createI18n({ - legacy: false, globalInjection: true, locale: 'ja', messages: { diff --git a/examples/composition/scope/inherit-locale.html b/examples/composition/scope/inherit-locale.html index 75ad7ac0b..aaa34b5dd 100644 --- a/examples/composition/scope/inherit-locale.html +++ b/examples/composition/scope/inherit-locale.html @@ -66,7 +66,6 @@

Child

} const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/scope/local.html b/examples/composition/scope/local.html index 2376a1bf9..39fe728d9 100644 --- a/examples/composition/scope/local.html +++ b/examples/composition/scope/local.html @@ -63,7 +63,6 @@

Child

} const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/composition/started.html b/examples/composition/started.html index 154f2c3f2..bf5ee444b 100644 --- a/examples/composition/started.html +++ b/examples/composition/started.html @@ -22,7 +22,6 @@ const { createI18n, useI18n } = VueI18n const i18n = createI18n({ - legacy: false, locale: 'ja', messages: { en: { diff --git a/examples/frameworks/nuxt3/plugins/i18n.ts b/examples/frameworks/nuxt3/plugins/i18n.ts index 05cb3eea4..b3fb3e892 100644 --- a/examples/frameworks/nuxt3/plugins/i18n.ts +++ b/examples/frameworks/nuxt3/plugins/i18n.ts @@ -5,7 +5,6 @@ import ja from '../locales/ja.json' export default defineNuxtPlugin(({ vueApp }) => { const i18n = createI18n({ - legacy: false, globalInjection: true, locale: 'en', messages: { diff --git a/examples/lazy-loading/vite/src/main.ts b/examples/lazy-loading/vite/src/main.ts index b308cbc6f..606e77905 100644 --- a/examples/lazy-loading/vite/src/main.ts +++ b/examples/lazy-loading/vite/src/main.ts @@ -6,7 +6,6 @@ import { setupI18n } from './i18n' import en from './locales/en.json' const i18n = setupI18n({ - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { diff --git a/examples/lazy-loading/webpack/src/main.js b/examples/lazy-loading/webpack/src/main.js index 882654807..85e478a9e 100644 --- a/examples/lazy-loading/webpack/src/main.js +++ b/examples/lazy-loading/webpack/src/main.js @@ -7,7 +7,6 @@ import en from './locales/en.json' const i18n = setupI18n({ globalInjection: true, - legacy: false, locale: 'en', fallbackLocale: 'en', messages: { diff --git a/examples/message-format/src/main.ts b/examples/message-format/src/main.ts index adf5777c3..8ce03b417 100644 --- a/examples/message-format/src/main.ts +++ b/examples/message-format/src/main.ts @@ -6,7 +6,6 @@ import App from './App.vue' import { messageCompiler } from './compilation' const i18n = createI18n({ - legacy: false, locale: 'en', messageCompiler, messages: { diff --git a/examples/petite/plural/basic.html b/examples/petite/plural/basic.html index 2bb6fe274..caa0d4c7f 100644 --- a/examples/petite/plural/basic.html +++ b/examples/petite/plural/basic.html @@ -26,7 +26,6 @@

Banana:

const { createI18n, useI18n } = PetiteVueI18n const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/petite/plural/custom.html b/examples/petite/plural/custom.html index 34d54f601..6aea11f83 100644 --- a/examples/petite/plural/custom.html +++ b/examples/petite/plural/custom.html @@ -43,7 +43,6 @@

Banana:

} const i18n = createI18n({ - legacy: false, locale: 'ru', pluralRules: { ru: customRule diff --git a/examples/ssr/vite/src/i18n.js b/examples/ssr/vite/src/i18n.js index 9fd13a3d1..9578bf128 100644 --- a/examples/ssr/vite/src/i18n.js +++ b/examples/ssr/vite/src/i18n.js @@ -9,7 +9,6 @@ export const SUPPORT_LOCALES = ['en', 'ja'] export function createI18n() { return _createI18n({ - legacy: false, globalInjection: true, locale: 'ja', fallbackLocale: 'en', diff --git a/examples/ssr/vitepress/.vitepress/theme/index.ts b/examples/ssr/vitepress/.vitepress/theme/index.ts index 5a65bd145..d4fdf0730 100644 --- a/examples/ssr/vitepress/.vitepress/theme/index.ts +++ b/examples/ssr/vitepress/.vitepress/theme/index.ts @@ -5,7 +5,6 @@ export default { extends: DefaultTheme, enhanceApp({ app, router, siteData }) { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/tsx/src/main.ts b/examples/tsx/src/main.ts index 4b68c8fd2..a1c3cd0e2 100644 --- a/examples/tsx/src/main.ts +++ b/examples/tsx/src/main.ts @@ -3,7 +3,6 @@ import { createI18n } from 'vue-i18n' import App from './App.vue' const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { diff --git a/examples/type-safe/global-type-definition/src/main.ts b/examples/type-safe/global-type-definition/src/main.ts index d44ffacc5..03c88c9d9 100644 --- a/examples/type-safe/global-type-definition/src/main.ts +++ b/examples/type-safe/global-type-definition/src/main.ts @@ -14,7 +14,6 @@ import jaJP from './locales/ja-JP.json' * you can check global type defition at `./vue-i18n.d.ts` */ const i18n = createI18n({ - legacy: false, locale: 'ja-JP', fallbackLocale: 'en-US', messages: { diff --git a/examples/type-safe/type-annotation/src/main.ts b/examples/type-safe/type-annotation/src/main.ts index 4abc52dd0..3bc436020 100644 --- a/examples/type-safe/type-annotation/src/main.ts +++ b/examples/type-safe/type-annotation/src/main.ts @@ -20,7 +20,6 @@ const i18n = createI18n< false >({ locale: 'en-US', - legacy: false, messages: { 'en-US': enUS }, diff --git a/examples/web-components/src/components/I18nHost.ce.vue b/examples/web-components/src/components/I18nHost.ce.vue index 5f1ea5122..69e486cc7 100644 --- a/examples/web-components/src/components/I18nHost.ce.vue +++ b/examples/web-components/src/components/I18nHost.ce.vue @@ -19,7 +19,6 @@ import { createI18n, I18nInjectionKey } from 'vue-i18n' * It will not work in legacy API mode. */ const i18n = createI18n({ - legacy: false, // must set to `false` locale: 'en', messages: { en: { diff --git a/examples/web-components/src/main.ts b/examples/web-components/src/main.ts index 826d6a32c..05630216c 100644 --- a/examples/web-components/src/main.ts +++ b/examples/web-components/src/main.ts @@ -13,7 +13,6 @@ customElements.define('hello-i18n', HelloI18nElement) customElements.define('hello-block', HelloBlockElement) const i18n = createI18n({ - legacy: false, locale: 'en', messages: {} }) diff --git a/packages/vue-i18n-core/src/composer.ts b/packages/vue-i18n-core/src/composer.ts index 7a5c5b8c9..f696e53aa 100644 --- a/packages/vue-i18n-core/src/composer.ts +++ b/packages/vue-i18n-core/src/composer.ts @@ -526,7 +526,6 @@ export interface ComposerOptions< * * // call with I18n option * const i18n = createI18n({ - * legacy: false, * locale: 'ja', * messageResolver, // set your message resolver * messages: { @@ -580,7 +579,6 @@ export interface ComposerOptions< * * // call with I18n option * const i18n = createI18n({ - * legacy: false, * locale: 'ja', * messageCompiler, // set your message compiler * messages: { diff --git a/packages/vue-i18n-core/src/errors.ts b/packages/vue-i18n-core/src/errors.ts index 961d62c9b..51aca94a6 100644 --- a/packages/vue-i18n-core/src/errors.ts +++ b/packages/vue-i18n-core/src/errors.ts @@ -22,11 +22,7 @@ export const I18nErrorCodes = { CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: 30, NOT_INSTALLED_WITH_PROVIDE: 31, // unexpected error - UNEXPECTED_ERROR: 32, - // not compatible legacy vue-i18n constructor - NOT_COMPATIBLE_LEGACY_VUE_I18N: 33, - // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly - NOT_AVAILABLE_COMPOSITION_IN_LEGACY: 34 + UNEXPECTED_ERROR: 32 } as const type I18nErrorCodes = (typeof I18nErrorCodes)[keyof typeof I18nErrorCodes] @@ -53,9 +49,5 @@ export const errorMessages: { [code: number]: string } = { [I18nErrorCodes.INVALID_VALUE]: `Invalid value`, [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`, [I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE]: - 'Need to install with `provide` function', - [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: - 'Not compatible legacy VueI18n.', - [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' + 'Need to install with `provide` function' } diff --git a/packages/vue-i18n-core/test/components/Translation.test.ts b/packages/vue-i18n-core/test/components/Translation.test.ts index 23af1e8f8..d99666464 100644 --- a/packages/vue-i18n-core/test/components/Translation.test.ts +++ b/packages/vue-i18n-core/test/components/Translation.test.ts @@ -80,7 +80,6 @@ test('slot contents', async () => { test('DOM contents', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -104,7 +103,6 @@ test('DOM contents', async () => { test('linked contents', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -128,7 +126,6 @@ test('linked contents', async () => { test('plural contents', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) @@ -153,7 +150,6 @@ test('plural contents', async () => { test('scope', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: { en: { @@ -280,7 +276,6 @@ test('message resolver', async () => { test('v-if / v-else', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages }) diff --git a/packages/vue-i18n-core/test/errors.test.ts b/packages/vue-i18n-core/test/errors.test.ts index a59b81ce4..46678b062 100644 --- a/packages/vue-i18n-core/test/errors.test.ts +++ b/packages/vue-i18n-core/test/errors.test.ts @@ -1,5 +1,5 @@ import { I18nErrorCodes } from '../src/errors' test('I18nErrorCodes', () => { - expect(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY).toBe(34) + expect(I18nErrorCodes.UNEXPECTED_RETURN_TYPE).toBe(24) }) diff --git a/packages/vue-i18n-core/test/ssr.test.ts b/packages/vue-i18n-core/test/ssr.test.ts index 0df8e4477..b945796e6 100644 --- a/packages/vue-i18n-core/test/ssr.test.ts +++ b/packages/vue-i18n-core/test/ssr.test.ts @@ -28,7 +28,6 @@ beforeAll(() => { test('composition mode', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: {} }) @@ -75,7 +74,6 @@ test('legacy mode', async () => { test('component: i18n-t', async () => { const i18n = createI18n({ - legacy: false, locale: 'en', messages: {} }) From 2d9b537905249d4f2b9d16281216b7424af550a5 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 19:21:20 +0900 Subject: [PATCH 10/18] fix others --- examples/type-safe/global-type-definition/src/main.ts | 6 +++--- examples/web-components/src/main.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/type-safe/global-type-definition/src/main.ts b/examples/type-safe/global-type-definition/src/main.ts index 03c88c9d9..3ad441f88 100644 --- a/examples/type-safe/global-type-definition/src/main.ts +++ b/examples/type-safe/global-type-definition/src/main.ts @@ -3,7 +3,7 @@ import { createI18n } from 'vue-i18n' import App from './App.vue' /** - * import locale messages resoruce from json for global scope + * import locale messages resource from json for global scope */ import enUS from './locales/en-US.json' import jaJP from './locales/ja-JP.json' @@ -11,9 +11,9 @@ import jaJP from './locales/ja-JP.json' /** * setup vue-i18n with i18n resources with global type definition. * if you define the i18n resource schema in your `*.d.ts`, these is checked with typeScript. - * you can check global type defition at `./vue-i18n.d.ts` + * you can check global type definition at `./vue-i18n.d.ts` */ -const i18n = createI18n({ +const i18n = createI18n({ locale: 'ja-JP', fallbackLocale: 'en-US', messages: { diff --git a/examples/web-components/src/main.ts b/examples/web-components/src/main.ts index 05630216c..a1320824d 100644 --- a/examples/web-components/src/main.ts +++ b/examples/web-components/src/main.ts @@ -12,7 +12,7 @@ customElements.define('i18n-host', I18nHostElement) customElements.define('hello-i18n', HelloI18nElement) customElements.define('hello-block', HelloBlockElement) -const i18n = createI18n({ +const i18n = createI18n({ locale: 'en', messages: {} }) From af2a1d0c9d597a11d31005496f0f198104d298b4 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 19:29:09 +0900 Subject: [PATCH 11/18] fix others --- .../global-type-definition/vite.config.ts | 3 +-- .../type-safe/type-annotation/vite.config.ts | 3 +-- .../size-check-petite-vue-i18n/vite.config.ts | 1 - packages/size-check-vue-i18n/vite.config.ts | 1 - packages/vue-i18n-core/src/warnings.ts | 20 ++----------------- 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/examples/type-safe/global-type-definition/vite.config.ts b/examples/type-safe/global-type-definition/vite.config.ts index a44776683..58ebd55a0 100644 --- a/examples/type-safe/global-type-definition/vite.config.ts +++ b/examples/type-safe/global-type-definition/vite.config.ts @@ -5,7 +5,6 @@ import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], define: { - __VUE_I18N_FULL_INSTALL__: true, - __VUE_I18N_LEGACY_API__: true + __VUE_I18N_FULL_INSTALL__: true } }) diff --git a/examples/type-safe/type-annotation/vite.config.ts b/examples/type-safe/type-annotation/vite.config.ts index a44776683..58ebd55a0 100644 --- a/examples/type-safe/type-annotation/vite.config.ts +++ b/examples/type-safe/type-annotation/vite.config.ts @@ -5,7 +5,6 @@ import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], define: { - __VUE_I18N_FULL_INSTALL__: true, - __VUE_I18N_LEGACY_API__: true + __VUE_I18N_FULL_INSTALL__: true } }) diff --git a/packages/size-check-petite-vue-i18n/vite.config.ts b/packages/size-check-petite-vue-i18n/vite.config.ts index 953c8b3fa..62b839256 100644 --- a/packages/size-check-petite-vue-i18n/vite.config.ts +++ b/packages/size-check-petite-vue-i18n/vite.config.ts @@ -15,7 +15,6 @@ export default defineConfig({ __RUNTIME__: true, // is targeting Node (SSR)? __NODE_JS__: false, - __VUE_I18N_LEGACY_API__: false, __VUE_I18N_FULL_INSTALL__: false, __VUE_PROD_DEVTOOLS__: false, __INTLIFY_DROP_MESSAGE_COMPILER__: true, diff --git a/packages/size-check-vue-i18n/vite.config.ts b/packages/size-check-vue-i18n/vite.config.ts index 0e46c4164..fa38e0d60 100644 --- a/packages/size-check-vue-i18n/vite.config.ts +++ b/packages/size-check-vue-i18n/vite.config.ts @@ -15,7 +15,6 @@ export default defineConfig({ __RUNTIME__: true, // is targeting Node (SSR)? __NODE_JS__: false, - __VUE_I18N_LEGACY_API__: false, __VUE_I18N_FULL_INSTALL__: false, __VUE_PROD_DEVTOOLS__: false, __INTLIFY_DROP_MESSAGE_COMPILER__: true, diff --git a/packages/vue-i18n-core/src/warnings.ts b/packages/vue-i18n-core/src/warnings.ts index 9bdd104a7..2caed918d 100644 --- a/packages/vue-i18n-core/src/warnings.ts +++ b/packages/vue-i18n-core/src/warnings.ts @@ -4,15 +4,7 @@ import { format } from '@intlify/shared' export const I18nWarnCodes = { FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT as number, // 8 NOT_FOUND_PARENT_SCOPE: 9, - IGNORE_OBJ_FLATTEN: 10, - /** - * @deprecated will be removed at vue-i18n v12 - */ - DEPRECATE_LEGACY_MODE: 11, - /** - * @deprecated will be removed at vue-i18n v12 - */ - DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE: 12 + IGNORE_OBJ_FLATTEN: 10 } as const type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes] @@ -20,15 +12,7 @@ type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes] export const warnMessages: { [code: number]: string } = { [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`, [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`, - [I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`, - /** - * @deprecated will be removed at vue-i18n v12 - */ - [I18nWarnCodes.DEPRECATE_LEGACY_MODE]: `Legacy API mode has been deprecated in v11. Use Composition API mode instead.\nAbout how to use the Composition API mode, see https://vue-i18n.intlify.dev/guide/advanced/composition.html`, - /** - * @deprecated will be removed at vue-i18n v12 - */ - [I18nWarnCodes.DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE]: `'v-t' has been deprecated in v11. Use translate APIs ('t' or '$t') instead.` + [I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value` } export function getWarnMessage( From 8de4d81c25d7af93c7bed1c162adb5e76f882943 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 19:33:22 +0900 Subject: [PATCH 12/18] fix others --- examples/lazy-loading/vite/src/i18n.ts | 28 +++---------------------- packages/vue-i18n-core/test/ssr.test.ts | 21 ------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/examples/lazy-loading/vite/src/i18n.ts b/examples/lazy-loading/vite/src/i18n.ts index 7e03d08f7..dfc2af44e 100644 --- a/examples/lazy-loading/vite/src/i18n.ts +++ b/examples/lazy-loading/vite/src/i18n.ts @@ -1,38 +1,16 @@ import { nextTick, isRef } from 'vue' import { createI18n } from 'vue-i18n' -import type { - I18n, - I18nOptions, - Locale, - VueI18n, - Composer, - I18nMode -} from 'vue-i18n' +import type { I18n, I18nOptions, Locale } from 'vue-i18n' export const SUPPORT_LOCALES = ['en', 'ja'] -function isComposer( - instance: VueI18n | Composer, - mode: I18nMode -): instance is Composer { - return mode === 'composition' && isRef(instance.locale) -} - export function getLocale(i18n: I18n): string { - if (isComposer(i18n.global, i18n.mode)) { - return i18n.global.locale.value - } else { - return i18n.global.locale - } + return i18n.global.locale.value } export function setLocale(i18n: I18n, locale: Locale): void { - if (isComposer(i18n.global, i18n.mode)) { - i18n.global.locale.value = locale - } else { - i18n.global.locale = locale - } + i18n.global.locale.value = locale } export function setupI18n(options: I18nOptions = { locale: 'en' }): I18n { diff --git a/packages/vue-i18n-core/test/ssr.test.ts b/packages/vue-i18n-core/test/ssr.test.ts index b945796e6..78134041a 100644 --- a/packages/vue-i18n-core/test/ssr.test.ts +++ b/packages/vue-i18n-core/test/ssr.test.ts @@ -51,27 +51,6 @@ test('composition mode', async () => { expect(await renderToString(app)).toMatch(`

こんにちは!

`) }) -test('legacy mode', async () => { - const mockWarn = vi.spyOn(shared, 'warnOnce') - // eslint-disable-next-line @typescript-eslint/no-empty-function - mockWarn.mockImplementation(() => {}) - - const i18n = createI18n({ - locale: 'ja', - messages: { - ja: { hello: 'こんにちは!' }, - en: { hello: 'hello!' } - } - }) - - // NOTE: template: `

{{ $t('hello') }}

` - const App = () => h('p', i18n.global.t('hello')) - const app = createSSRApp(App) - app.use(i18n) - - expect(await renderToString(app)).toMatch(`

こんにちは!

`) -}) - test('component: i18n-t', async () => { const i18n = createI18n({ locale: 'en', From efd660dfe179888eb6093aaba657fdef69158d03 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 20:39:06 +0900 Subject: [PATCH 13/18] fix jsdoc --- examples/lazy-loading/vite/src/i18n.ts | 2 +- packages/petite-vue-i18n/src/vue.d.ts | 21 +++++---------------- packages/vue-i18n-core/src/i18n.ts | 12 ++++-------- packages/vue-i18n/src/vue.d.ts | 23 ++--------------------- 4 files changed, 12 insertions(+), 46 deletions(-) diff --git a/examples/lazy-loading/vite/src/i18n.ts b/examples/lazy-loading/vite/src/i18n.ts index dfc2af44e..7bc2dc73a 100644 --- a/examples/lazy-loading/vite/src/i18n.ts +++ b/examples/lazy-loading/vite/src/i18n.ts @@ -1,4 +1,4 @@ -import { nextTick, isRef } from 'vue' +import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' import type { I18n, I18nOptions, Locale } from 'vue-i18n' diff --git a/packages/petite-vue-i18n/src/vue.d.ts b/packages/petite-vue-i18n/src/vue.d.ts index 296f85541..f5a6e6ead 100644 --- a/packages/petite-vue-i18n/src/vue.d.ts +++ b/packages/petite-vue-i18n/src/vue.d.ts @@ -9,9 +9,7 @@ import type { DefineLocaleMessage, ExportedGlobalComposer, RemovedIndexResources, - TranslateResult, - VueI18n, - VueI18nOptions + TranslateResult } from '@intlify/vue-i18n-core/petite' // --- THE CONTENT BELOW THIS LINE WILL BE APPENDED TO DTS FILE IN DIST DIRECTORY --- // @@ -25,13 +23,6 @@ declare module 'vue' { * @VueI18nInjection */ export interface ComponentCustomOptions { - /** - * VueI18n options - * - * @remarks - * See the {@link VueI18nOptions} - */ - i18n?: VueI18nOptions /** * For custom blocks options * @internal @@ -51,23 +42,21 @@ declare module 'vue' { */ export interface ComponentCustomProperties { /** - * Exported Global Composer instance, or global VueI18n instance. + * Exported Global Composer instance * * @remarks - * You can get the {@link ExportedGlobalComposer | exported composer instance} which are exported from global {@link Composer | composer instance} created with {@link createI18n}, or global {@link VueI18n | VueI18n instance}. - * You can get the exported composer instance in {@link I18nMode | Composition API mode}, or the Vuei18n instance in {@link I18nMode | Legacy API mode}, which is the instance you can refer to with this property. + * You can get the {@link ExportedGlobalComposer | exported composer instance} which are exported from global {@link Composer | composer instance} created with {@link createI18n} + * You can get the exported composer instance in {@link I18nMode | Composition API mode} * The locales, locale messages, and other resources managed by the instance referenced by this property are valid as global scope. * If the `i18n` component custom option is not specified, it's the same as the VueI18n instance that can be referenced by the i18n instance {@link I18n.global | global} property. */ - $i18n: VueI18n | ExportedGlobalComposer + $i18n: ExportedGlobalComposer /** * Locale message translation * * @remarks * If this is used in a reactive context, it will re-evaluate once the locale changes. * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#t | `VueI18n#t`}. - * * In {@link I18nMode | Composition API mode}, the `$t` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer, and it work on **global scope**. About that details, see {@link Composer#t | `Composer#t` }. * diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index f73970c06..4bc2dd365 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -53,10 +53,6 @@ import type { Disposer } from './types' /** * I18n Options for `createI18n` * - * @remarks - * `I18nOptions` is inherited {@link I18nAdditionalOptions}, {@link ComposerOptions} and {@link VueI18nOptions}, - * so you can specify these options. - * * @VueI18nGeneral */ export type I18nOptions< @@ -118,7 +114,7 @@ export interface I18n< > { // prettier-ignore /** - * The property accessible to the global Composer instance or VueI18n instance + * The property accessible to the global Composer instance * * An instance of this property is **global scope***. */ @@ -139,7 +135,7 @@ export interface I18n< export type ComposerExtender = (composer: Composer) => Disposer | undefined /** - * The hooks that give to extend Composer (Composition API) and VueI18n instance (Options API). + * The hooks that give to extend Composer (Composition API) * This hook is mainly for vue-i18n-routing and nuxt i18n. * * @internal @@ -393,10 +389,10 @@ export function createI18n(options: any = {}): any { app.__VUE_I18N_SYMBOL__ = symbol app.provide(app.__VUE_I18N_SYMBOL__, i18n as unknown as I18n) - // set composer & vuei18n extend hook options from plugin options + // set composer extend hook options from plugin options if (isPlainObject(options[0])) { const opts = options[0] as ExtendHooks - // Plugin options cannot be passed directly to the function that creates Composer & VueI18n, + // Plugin options cannot be passed directly to the function that creates Composer // so we keep it temporary ;(i18n as unknown as I18nInternal).__composerExtend = opts.__composerExtend diff --git a/packages/vue-i18n/src/vue.d.ts b/packages/vue-i18n/src/vue.d.ts index 970110936..c3a53f405 100644 --- a/packages/vue-i18n/src/vue.d.ts +++ b/packages/vue-i18n/src/vue.d.ts @@ -22,7 +22,6 @@ import type { TranslateResult, Translation, VueI18nInstance, - VueI18nOptions, VueMessageType } from '@intlify/vue-i18n-core' @@ -37,13 +36,6 @@ declare module 'vue' { * @VueI18nInjection */ export interface ComponentCustomOptions { - /** - * VueI18n options - * - * @remarks - * See the {@link VueI18nOptions} - */ - i18n?: VueI18nOptions /** * For custom blocks options * @internal @@ -63,11 +55,10 @@ declare module 'vue' { */ export interface ComponentCustomProperties { /** - * Exported Global Composer instance, or global VueI18n instance. + * Exported Global Composer instance * * @remarks - * You can get the {@link ExportedGlobalComposer | exported composer instance} which are exported from global {@link Composer | composer instance} created with {@link createI18n}, or global {@link VueI18n | VueI18n instance}. - * You can get the exported composer instance in {@link I18nMode | Composition API mode}, or the Vuei18n instance in {@link I18nMode | Legacy API mode}, which is the instance you can refer to with this property. + * You can get the {@link ExportedGlobalComposer | exported composer instance} which are exported from global {@link Composer | composer instance} created with {@link createI18n} * The locales, locale messages, and other resources managed by the instance referenced by this property are valid as global scope. * If the `i18n` component custom option is not specified, it's the same as the VueI18n instance that can be referenced by the i18n instance {@link I18n.global | global} property. */ @@ -78,8 +69,6 @@ declare module 'vue' { * @remarks * If this is used in a reactive context, it will re-evaluate once the locale changes. * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#t | `VueI18n#t`}. - * * In {@link I18nMode | Composition API mode}, the `$t` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer, and it work on **global scope**. About that details, see {@link Composer#t | `Composer#t` }. * @@ -422,8 +411,6 @@ declare module 'vue' { * @remarks * If this is used in a reactive context, it will re-evaluate once the locale changes. * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#rt | `VueI18n#rt`}. - * * In {@link I18nMode | Composition API mode}, the `$rt` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer, and it work on **global scope**. About that details, see {@link Composer#rt | `Composer#rt` }. * @@ -514,8 +501,6 @@ declare module 'vue' { * @remarks * If this is used in a reactive context, it will re-evaluate once the locale changes. * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#d | `VueI18n#d` }. - * * In {@link I18nMode | Composition API mode}, the `$d` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer instance, and it work on **global scope**. About that details, see {@link Composer#d | `Composer#d` }. * @@ -676,8 +661,6 @@ declare module 'vue' { * @remarks * If this is used in a reactive context, it will re-evaluate once the locale changes. * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#n | `VueI18n.n` }. - * * In {@link I18nMode | Composition API mode}, the `$n` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer instance, and it work on **global scope**. About that details, see {@link Composer#n | `Composer.n` }. * @@ -867,8 +850,6 @@ declare module 'vue' { /** * Locale messages getter * - * In {@link I18nMode | Legacy API mode}, the input / output is the same as for VueI18n instance. About that details, see {@link VueI18n#tm | `VueI18n#tm` }. - * * @remarks * In {@link I18nMode | Composition API mode}, the `$tm` is injected by `app.config.globalProperties`. * the input / output is the same as for Composer instance, and it work on **global scope**. About that details, see {@link Composer#tm | `Composer.tm` }. From 6d02502aba55f487d0251c9096f1307213e0a8ff Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 20:41:21 +0900 Subject: [PATCH 14/18] fix jsdoc --- packages/vue-i18n-core/src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vue-i18n-core/src/types.ts b/packages/vue-i18n-core/src/types.ts index 894b911ec..f2a01923e 100644 --- a/packages/vue-i18n-core/src/types.ts +++ b/packages/vue-i18n-core/src/types.ts @@ -16,7 +16,6 @@ export type Disposer = () => void * * declare module '@intlify/vue-i18n-core' { * interface GeneratedTypeConfig { - * legacy: false * } * } * ``` From 3f4fc09d8e5582d91b639fe7eb0879d76ee1cc78 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 22:20:39 +0900 Subject: [PATCH 15/18] remove legacy examples --- .../legacy/components/datetime-format.html | 76 ------------- examples/legacy/components/number-format.html | 86 --------------- examples/legacy/components/translation.html | 92 ---------------- examples/legacy/datetime.html | 69 ------------ examples/legacy/fallback/basic.html | 36 ------ examples/legacy/fallback/component.html | 68 ------------ examples/legacy/fallback/format.html | 32 ------ examples/legacy/fallback/suppress.html | 37 ------- examples/legacy/formatting/linked.html | 70 ------------ examples/legacy/formatting/list.html | 47 -------- examples/legacy/formatting/literal.html | 47 -------- examples/legacy/formatting/named.html | 47 -------- examples/legacy/functions/linked.html | 87 --------------- examples/legacy/functions/list.html | 47 -------- examples/legacy/functions/named.html | 47 -------- examples/legacy/functions/plural.html | 58 ---------- examples/legacy/missing/handler.html | 40 ------- examples/legacy/missing/suppress.html | 37 ------- examples/legacy/number.html | 69 ------------ examples/legacy/plural/basic.html | 44 -------- examples/legacy/plural/custom.html | 63 ----------- examples/legacy/scope/global.html | 104 ------------------ examples/legacy/scope/inherit-locale.html | 93 ---------------- examples/legacy/scope/local.html | 88 --------------- examples/legacy/started.html | 47 -------- 25 files changed, 1531 deletions(-) delete mode 100644 examples/legacy/components/datetime-format.html delete mode 100644 examples/legacy/components/number-format.html delete mode 100644 examples/legacy/components/translation.html delete mode 100644 examples/legacy/datetime.html delete mode 100644 examples/legacy/fallback/basic.html delete mode 100644 examples/legacy/fallback/component.html delete mode 100644 examples/legacy/fallback/format.html delete mode 100644 examples/legacy/fallback/suppress.html delete mode 100644 examples/legacy/formatting/linked.html delete mode 100644 examples/legacy/formatting/list.html delete mode 100644 examples/legacy/formatting/literal.html delete mode 100644 examples/legacy/formatting/named.html delete mode 100644 examples/legacy/functions/linked.html delete mode 100644 examples/legacy/functions/list.html delete mode 100644 examples/legacy/functions/named.html delete mode 100644 examples/legacy/functions/plural.html delete mode 100644 examples/legacy/missing/handler.html delete mode 100644 examples/legacy/missing/suppress.html delete mode 100644 examples/legacy/number.html delete mode 100644 examples/legacy/plural/basic.html delete mode 100644 examples/legacy/plural/custom.html delete mode 100644 examples/legacy/scope/global.html delete mode 100644 examples/legacy/scope/inherit-locale.html delete mode 100644 examples/legacy/scope/local.html delete mode 100644 examples/legacy/started.html diff --git a/examples/legacy/components/datetime-format.html b/examples/legacy/components/datetime-format.html deleted file mode 100644 index 47c840ba6..000000000 --- a/examples/legacy/components/datetime-format.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - DatetimeFormat component examples - - - - -

DatetimeFormat component examples

- -
-

basic usages:

- - - - -

slot usages:

- - - -
- - - diff --git a/examples/legacy/components/number-format.html b/examples/legacy/components/number-format.html deleted file mode 100644 index cb8db41ea..000000000 --- a/examples/legacy/components/number-format.html +++ /dev/null @@ -1,86 +0,0 @@ - - - - - NumberFormat component examples - - - - -

NumberFormat component examples

- -
-

basic usages:

- - - - -

slot usages:

- - - - - - -
- - - diff --git a/examples/legacy/components/translation.html b/examples/legacy/components/translation.html deleted file mode 100644 index 93fc0cc28..000000000 --- a/examples/legacy/components/translation.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - Translation component example - - - - -

Translation component example

- -
-

localize with slot contents:

- - - - -

localize with DOM contents:

- - {{ $t('message.language', [], { locale: 'en' }) }} - - -

localize with using linked:

- - - - -

localize with using plural:

-
- - -
- - - -
- - - diff --git a/examples/legacy/datetime.html b/examples/legacy/datetime.html deleted file mode 100644 index 28a5791ab..000000000 --- a/examples/legacy/datetime.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - Datetime localization - - - - -
-

DateTime Localization with Legacy API

-
- - -
-

{{ $t('current') }}: {{ $d(now, 'long') }}

-
- - - diff --git a/examples/legacy/fallback/basic.html b/examples/legacy/fallback/basic.html deleted file mode 100644 index c8369c845..000000000 --- a/examples/legacy/fallback/basic.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - Fallback basic example - - - - -
-

{{ $t("message.hello") }}

-
- - - diff --git a/examples/legacy/fallback/component.html b/examples/legacy/fallback/component.html deleted file mode 100644 index e4cd564ba..000000000 --- a/examples/legacy/fallback/component.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - Component fallback example - - - - - -
-

Root

-

{{ $t("message.hello") }}

- -
- - - diff --git a/examples/legacy/fallback/format.html b/examples/legacy/fallback/format.html deleted file mode 100644 index f25bd7b19..000000000 --- a/examples/legacy/fallback/format.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - Fallback format example - - - - -
-

{{ $t("hello, {name}!", { name: 'kazupon' }) }}

-
- - - diff --git a/examples/legacy/fallback/suppress.html b/examples/legacy/fallback/suppress.html deleted file mode 100644 index ddf2ff73c..000000000 --- a/examples/legacy/fallback/suppress.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - Fallback warning suppress example - - - - -
-

{{ $t("message.hello") }}

-
- - - diff --git a/examples/legacy/formatting/linked.html b/examples/legacy/formatting/linked.html deleted file mode 100644 index d82b605c5..000000000 --- a/examples/legacy/formatting/linked.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - Linked message example - - - - -
-
- - -
-

{{ $t('message.linked') }}

- -

{{ $t('message.missingHomeAddress') }}

-

- {{ $t('message.custom_modifier', { snake: 'message.snake' }) }} -

-
- - - diff --git a/examples/legacy/formatting/list.html b/examples/legacy/formatting/list.html deleted file mode 100644 index aa65659a0..000000000 --- a/examples/legacy/formatting/list.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - List interpolation example - - - - -
-
- - -
-

{{ $t('message.greeting', ['kazupon']) }}

-
- - - diff --git a/examples/legacy/formatting/literal.html b/examples/legacy/formatting/literal.html deleted file mode 100644 index 5a0f53ef6..000000000 --- a/examples/legacy/formatting/literal.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Literal interpolation example - - - - -
-
- - -
-

{{ $t('message.greeting') }}

-
- - - diff --git a/examples/legacy/formatting/named.html b/examples/legacy/formatting/named.html deleted file mode 100644 index 7b6928853..000000000 --- a/examples/legacy/formatting/named.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Named interpolation example - - - - -
-
- - -
-

{{ $t('message.greeting', { name: 'kazupon' }) }}

-
- - - diff --git a/examples/legacy/functions/linked.html b/examples/legacy/functions/linked.html deleted file mode 100644 index c83b17b67..000000000 --- a/examples/legacy/functions/linked.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Example: Linked message with message function - - - - -
-
- - -
-

{{ $t('message.linked') }}

- -

{{ $t('message.missingHomeAddress') }}

-

- {{ $t('message.custom_modifier', { snake: 'message.snake' }) }} -

-
- - - diff --git a/examples/legacy/functions/list.html b/examples/legacy/functions/list.html deleted file mode 100644 index 73b7d16de..000000000 --- a/examples/legacy/functions/list.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Example: List interpolation with Message Function - - - - -
-
- - -
-

{{ $t('message.greeting', ['kazupon']) }}

-
- - - diff --git a/examples/legacy/functions/named.html b/examples/legacy/functions/named.html deleted file mode 100644 index c87481373..000000000 --- a/examples/legacy/functions/named.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Example: Named interpolation with message function - - - - -
-
- - -
-

{{ $t('message.greeting', { name: 'kazupon' }) }}

-
- - - diff --git a/examples/legacy/functions/plural.html b/examples/legacy/functions/plural.html deleted file mode 100644 index fd8bf6756..000000000 --- a/examples/legacy/functions/plural.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - Example: plural with message functions - - - - -
-

Car:

-

{{ $t('car', 1) }}

-

{{ $t('car', 2) }}

-

Apple:

-

{{ $t('apple', 0) }}

-

{{ $t('apple', 1) }}

-

{{ $t('apple', { count: 10 }, 10) }}

-

{{ $t('apple', 10) }}

-

Banana:

-

{{ $t('banana', { n: 1 }, 1) }}

-

{{ $t('banana', 1) }}

-

{{ $t('banana', { n: 'too many' }, 100) }}

-
- - - diff --git a/examples/legacy/missing/handler.html b/examples/legacy/missing/handler.html deleted file mode 100644 index dc6f29c4b..000000000 --- a/examples/legacy/missing/handler.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - Missing handler example - - - - -
-

{{ $t("message.hello") }}

-
- - - diff --git a/examples/legacy/missing/suppress.html b/examples/legacy/missing/suppress.html deleted file mode 100644 index 9bee7fa6c..000000000 --- a/examples/legacy/missing/suppress.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - Missing warning suppress example - - - - -
-

{{ $t("message.hello") }}

-
- - - diff --git a/examples/legacy/number.html b/examples/legacy/number.html deleted file mode 100644 index d9a314e5b..000000000 --- a/examples/legacy/number.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - Number localization - - - - - -
-

Number Localization with Legacy API

-
- - -
-

{{ $t('money') }}: {{ $n(money, 'currency') }}

-
- - - diff --git a/examples/legacy/plural/basic.html b/examples/legacy/plural/basic.html deleted file mode 100644 index 11a10e86b..000000000 --- a/examples/legacy/plural/basic.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - plural basic usage examples - - - - -
-

Car:

-

{{ $t('car', 1) }}

-

{{ $t('car', 2) }}

-

Apple:

-

{{ $t('apple', 0) }}

-

{{ $t('apple', 1) }}

-

{{ $t('apple', { count: 10 }, 10) }}

-

{{ $t('apple', 10) }}

-

Banana:

-

{{ $t('banana', { n: 1 }, 1) }}

-

{{ $t('banana', 1) }}

-

{{ $t('banana', { n: 'too many' }, 10) }}

-
- - - diff --git a/examples/legacy/plural/custom.html b/examples/legacy/plural/custom.html deleted file mode 100644 index 221b0de53..000000000 --- a/examples/legacy/plural/custom.html +++ /dev/null @@ -1,63 +0,0 @@ - - - - - plural custom rule usage examples - - - - -
-

Car:

-

{{ $t('car', 1) }}

-

{{ $t('car', 2) }}

-

{{ $t('car', 4) }}

-

{{ $t('car', 12) }}

-

{{ $t('car', 21) }}

- -

Banana:

-

{{ $t('banana', 0) }}

-

{{ $t('banana', 4) }}

-

{{ $t('banana', 11) }}

-

{{ $t('banana', 31) }}

-
- - - diff --git a/examples/legacy/scope/global.html b/examples/legacy/scope/global.html deleted file mode 100644 index d4eaa80d9..000000000 --- a/examples/legacy/scope/global.html +++ /dev/null @@ -1,104 +0,0 @@ - - - - - Global scope example - - - - -
-

Root

-
- - -
-

{{ $t('message.hello') }}

- -
- - - diff --git a/examples/legacy/scope/inherit-locale.html b/examples/legacy/scope/inherit-locale.html deleted file mode 100644 index d7246468e..000000000 --- a/examples/legacy/scope/inherit-locale.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - Inherit locale example - - - - -
-

Root

-
- - -
-

{{ $t("message.hello") }}

- -
- - - diff --git a/examples/legacy/scope/local.html b/examples/legacy/scope/local.html deleted file mode 100644 index 346e10da2..000000000 --- a/examples/legacy/scope/local.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - Local scope example - - - - -
-

Root

-
- - -
-

{{ $t("message.hello") }}

- -
- - - diff --git a/examples/legacy/started.html b/examples/legacy/started.html deleted file mode 100644 index b246e1a80..000000000 --- a/examples/legacy/started.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Getting Started - - - - -
-
- - -
-

{{ $t("message.hello") }}

-
- - - From c7b5042e020812a984df1408e729c484c44cdcf9 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Thu, 13 Feb 2025 22:25:10 +0900 Subject: [PATCH 16/18] fix others --- examples/web-components/src/components/I18nHost.ce.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/web-components/src/components/I18nHost.ce.vue b/examples/web-components/src/components/I18nHost.ce.vue index 69e486cc7..fe7d2c0cd 100644 --- a/examples/web-components/src/components/I18nHost.ce.vue +++ b/examples/web-components/src/components/I18nHost.ce.vue @@ -16,9 +16,8 @@ import { createI18n, I18nInjectionKey } from 'vue-i18n' * * NOTE: * In web components only supports the composition API. - * It will not work in legacy API mode. */ -const i18n = createI18n({ +const i18n = createI18n({ locale: 'en', messages: { en: { From 35030b9603b8c751f9757d74ca108abfb82cc953 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Fri, 14 Feb 2025 13:35:30 +0900 Subject: [PATCH 17/18] fix others --- examples/backend/src/main.ts | 2 +- examples/type-safe/type-annotation/src/main.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/backend/src/main.ts b/examples/backend/src/main.ts index 443cacbf9..c94104227 100644 --- a/examples/backend/src/main.ts +++ b/examples/backend/src/main.ts @@ -11,7 +11,7 @@ import type { Locales } from './constants' const messages = await load(locales) // create i18n instance -const i18n = createI18n<[ResourceSchema], Locales, false>({ +const i18n = createI18n<[ResourceSchema], Locales>({ locale: 'en', messages }) diff --git a/examples/type-safe/type-annotation/src/main.ts b/examples/type-safe/type-annotation/src/main.ts index 3bc436020..aeaf4a996 100644 --- a/examples/type-safe/type-annotation/src/main.ts +++ b/examples/type-safe/type-annotation/src/main.ts @@ -16,8 +16,7 @@ const i18n = createI18n< message: MessageSchema number: NumberSchema }, - 'en-US', - false + 'en-US' >({ locale: 'en-US', messages: { From cd0c762630b40fb5f4f7a42a9c83b2947cc58466 Mon Sep 17 00:00:00 2001 From: babu-ch Date: Sat, 15 Feb 2025 10:51:47 +0900 Subject: [PATCH 18/18] rollup test cases --- .../test/__snapshots__/i18n.test.ts.snap | 8 +- packages/vue-i18n-core/test/i18n.test.ts | 456 +++++++++--------- packages/vue-i18n-core/test/issues.test.ts | 4 +- packages/vue-i18n-core/test/ssr.test.ts | 2 +- 4 files changed, 227 insertions(+), 243 deletions(-) diff --git a/packages/vue-i18n-core/test/__snapshots__/i18n.test.ts.snap b/packages/vue-i18n-core/test/__snapshots__/i18n.test.ts.snap index d2ba3da67..eac7ea62f 100644 --- a/packages/vue-i18n-core/test/__snapshots__/i18n.test.ts.snap +++ b/packages/vue-i18n-core/test/__snapshots__/i18n.test.ts.snap @@ -1,9 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`slot reactivity > composable > en 1`] = `"

Root

hello!

Child

hello!

Sub Child

hello!

t inside of slot

hello!

i18n-t inside of slot

hello!

"`; +exports[`slot reactivity > en 1`] = `"

Root

hello!

Child

hello!

Sub Child

hello!

t inside of slot

hello!

i18n-t inside of slot

hello!

"`; -exports[`slot reactivity > composable > ja 1`] = `"

Root

こんにちは!

Child

こんにちは!

Sub Child

こんにちは!

t inside of slot

こんにちは!

i18n-t inside of slot

こんにちは!

"`; - -exports[`slot reactivity > legacy > en 1`] = `"

Root

hello!

Child

hello!

Sub Child

hello!

$t inside of slot

hello!

i18n-t inside of slot

hello!

"`; - -exports[`slot reactivity > legacy > ja 1`] = `"

Root

こんにちは!

Child

こんにちは!

Sub Child

こんにちは!

$t inside of slot

こんにちは!

i18n-t inside of slot

こんにちは!

"`; +exports[`slot reactivity > ja 1`] = `"

Root

こんにちは!

Child

こんにちは!

Sub Child

こんにちは!

t inside of slot

こんにちは!

i18n-t inside of slot

こんにちは!

"`; diff --git a/packages/vue-i18n-core/test/i18n.test.ts b/packages/vue-i18n-core/test/i18n.test.ts index cd265f895..01816a30f 100644 --- a/packages/vue-i18n-core/test/i18n.test.ts +++ b/packages/vue-i18n-core/test/i18n.test.ts @@ -58,18 +58,16 @@ afterEach(() => { setDevToolsHook(null) }) -describe('createI18n with flat json messages', () => { - test('composition mode', () => { - const i18n = createI18n({ - flatJson: true, - messages: { - en: { 'mainMenu.buttonStart': 'Start!' } - } - }) - const messages = i18n.global.messages.value - // @ts-ignore - expect(messages.en.mainMenu.buttonStart).toEqual('Start!') +test('createI18n with flat json messages', () => { + const i18n = createI18n({ + flatJson: true, + messages: { + en: { 'mainMenu.buttonStart': 'Start!' } + } }) + const messages = i18n.global.messages.value + // @ts-ignore + expect(messages.en.mainMenu.buttonStart).toEqual('Start!') }) describe('useI18n', () => { @@ -348,7 +346,7 @@ describe('useI18n', () => { }) }) -describe('slot reactivity', () => { +test('slot reactivity', async () => { let org: any // eslint-disable-line @typescript-eslint/no-explicit-any let spy: any // eslint-disable-line @typescript-eslint/no-explicit-any beforeEach(() => { @@ -360,98 +358,96 @@ describe('slot reactivity', () => { console.warn = org }) - test('composable', async () => { - const i18n = createI18n({ - locale: 'ja', - fallbackLocale: ['en'], - messages: { - en: { - hello: 'hello!' - }, - ja: { - hello: 'こんにちは!' - } + const i18n = createI18n({ + locale: 'ja', + fallbackLocale: ['en'], + messages: { + en: { + hello: 'hello!' + }, + ja: { + hello: 'こんにちは!' } - }) - - const SlotChild = { - template: `

` } + }) - const SubChild = { - template: ` -
-

Sub Child

-
- -
-

{{ t('hello') }}

-
- `, - setup() { - return useI18n() - } + const SlotChild = { + template: `

` + } + + const SubChild = { + template: ` +
+

Sub Child

+
+ +
+

{{ t('hello') }}

+
+ `, + setup() { + return useI18n() } + } - const Child = { - components: { - SubChild, - SlotChild - }, - template: ` -
-

Child

-
- -
-

{{ t('hello') }}

- - t inside of slot - - {{ t('hello') }} - - i18n-t inside of slot - - - -
- `, - setup() { - return useI18n() - } + const Child = { + components: { + SubChild, + SlotChild + }, + template: ` +
+

Child

+
+ +
+

{{ t('hello') }}

+ + t inside of slot + + {{ t('hello') }} + + i18n-t inside of slot + + + +
+ `, + setup() { + return useI18n() } + } - const App = defineComponent({ - components: { - Child - }, - setup() { - return useI18n() - }, - template: ` -

Root

-
- -
-

{{ t('hello') }}

- - ` - }) - const { html } = await mount(App, i18n as any) // eslint-disable-line @typescript-eslint/no-explicit-any - expect(html()).toMatchSnapshot('ja') - i18n.global.locale.value = 'en' - await nextTick() - expect(html()).toMatchSnapshot('en') - }) + const App = defineComponent({ + components: { + Child + }, + setup() { + return useI18n() + }, + template: ` +

Root

+
+ +
+

{{ t('hello') }}

+ + ` + }) + const { html } = await mount(App, i18n as any) // eslint-disable-line @typescript-eslint/no-explicit-any + expect(html()).toMatchSnapshot('ja') + i18n.global.locale.value = 'en' + await nextTick() + expect(html()).toMatchSnapshot('en') }) test('multi instance', async () => { @@ -567,62 +563,60 @@ test('merge useI18n resources to global scope', async () => { }) }) -describe('merge i18n custom blocks to global scope', () => { - test('composition mode', async () => { - const i18n = createI18n({ - locale: 'ja', - messages: { - en: { - hi: { hello: 'hello!' } - } +test('merge i18n custom blocks to global scope', async () => { + const i18n = createI18n({ + locale: 'ja', + messages: { + en: { + hi: { hello: 'hello!' } } - }) + } + }) - const App = defineComponent({ - setup() { - const instance = getCurrentInstance() - if (instance == null) { - throw new Error() - } - const options = instance.type as ComponentOptions - options.__i18nGlobal = [ - { - locale: 'en', - resource: { - hi: { hi: 'hi!' }, - foo: 'foo!' - } - }, - { - locale: 'ja', - resource: { foo: 'ふー!' } + const App = defineComponent({ + setup() { + const instance = getCurrentInstance() + if (instance == null) { + throw new Error() + } + const options = instance.type as ComponentOptions + options.__i18nGlobal = [ + { + locale: 'en', + resource: { + hi: { hi: 'hi!' }, + foo: 'foo!' } - ] - useI18n({ - useScope: 'global', - messages: { - ja: { - hello: 'こんにちは!' - } + }, + { + locale: 'ja', + resource: { foo: 'ふー!' } + } + ] + useI18n({ + useScope: 'global', + messages: { + ja: { + hello: 'こんにちは!' } - }) - return {} - }, - template: `

foo

` - }) - await mount(App, i18n) + } + }) + return {} + }, + template: `

foo

` + }) + await mount(App, i18n) - expect(i18n.global.getLocaleMessage('en')).toEqual({ - hi: { - hi: 'hi!', - hello: 'hello!' - }, - foo: 'foo!' - }) - expect(i18n.global.getLocaleMessage('ja')).toEqual({ - hello: 'こんにちは!', - foo: 'ふー!' - }) + expect(i18n.global.getLocaleMessage('en')).toEqual({ + hi: { + hi: 'hi!', + hello: 'hello!' + }, + foo: 'foo!' + }) + expect(i18n.global.getLocaleMessage('ja')).toEqual({ + hello: 'こんにちは!', + foo: 'ふー!' }) }) @@ -631,7 +625,7 @@ describe('custom pluralization', () => { // eslint-disable-next-line @typescript-eslint/no-empty-function mockWarn.mockImplementation(() => {}) - test('composition', async () => { + test('pluralization', async () => { const i18n = createI18n({ locale: 'ru', pluralRules: _pluralRules, @@ -664,7 +658,7 @@ describe('custom pluralization', () => { expect(find('p:nth-child(5)')!.innerHTML).toEqual('21 машина') }) - test('composition + custom block', async () => { + test('custom block', async () => { const i18n = createI18n({ locale: 'ru' }) @@ -765,80 +759,76 @@ describe('release global scope', () => { }) }) -describe('Composer & VueI18n extend hooking', () => { - test('composition', async () => { - const composerDisposeSpy = vi.fn() - let counter = 0 - const composerExtendSpy = vi - .fn() - .mockImplementation((composer: Composer) => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - counter += 1 - ;(composer as any).foo = ref(`foo${counter}`) - return composerDisposeSpy - }) - const vueI18nExtendSpy = vi.fn() - const i18n = createI18n({}) +test('Composer & VueI18n extend hooking', async () => { + const composerDisposeSpy = vi.fn() + let counter = 0 + const composerExtendSpy = vi.fn().mockImplementation((composer: Composer) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + counter += 1 + ;(composer as any).foo = ref(`foo${counter}`) + return composerDisposeSpy + }) + const vueI18nExtendSpy = vi.fn() + const i18n = createI18n({}) - const GrandChild = defineComponent({ - setup() { - // @ts-ignore - const { foo } = useI18n({ - useScope: 'local' - }) - return { foo } - }, - template: '

{{ foo }}

' - }) + const GrandChild = defineComponent({ + setup() { + // @ts-ignore + const { foo } = useI18n({ + useScope: 'local' + }) + return { foo } + }, + template: '

{{ foo }}

' + }) - const Child = defineComponent({ - components: { - GrandChild - }, - setup() { - // @ts-ignore - const { foo } = useI18n({ - useScope: 'local' - }) - return { foo } - }, - template: '

{{ foo }}

' - }) + const Child = defineComponent({ + components: { + GrandChild + }, + setup() { + // @ts-ignore + const { foo } = useI18n({ + useScope: 'local' + }) + return { foo } + }, + template: '

{{ foo }}

' + }) - const App = defineComponent({ - components: { - Child - }, - setup() { - // @ts-ignore - const { foo } = useI18n() // global scope - return { foo } - }, - template: '

{{ foo }}

' - }) - const { html, app } = await mount(App, i18n, { - pluginOptions: { - __composerExtend: composerExtendSpy, - __vueI18nExtend: vueI18nExtendSpy - } as any // eslint-disable-line @typescript-eslint/no-explicit-any - }) + const App = defineComponent({ + components: { + Child + }, + setup() { + // @ts-ignore + const { foo } = useI18n() // global scope + return { foo } + }, + template: '

{{ foo }}

' + }) + const { html, app } = await mount(App, i18n, { + pluginOptions: { + __composerExtend: composerExtendSpy, + __vueI18nExtend: vueI18nExtendSpy + } as any // eslint-disable-line @typescript-eslint/no-explicit-any + }) - // Check that global is not extended - expect((i18n.global as any).foo).toBeUndefined() // eslint-disable-line @typescript-eslint/no-explicit-any + // Check that global is not extended + expect((i18n.global as any).foo).toBeUndefined() // eslint-disable-line @typescript-eslint/no-explicit-any - expect(html()).toBe( - '

foo1

foo2

' - ) - expect(composerExtendSpy).toHaveBeenCalledTimes(2) - expect(vueI18nExtendSpy).not.toHaveBeenCalled() + expect(html()).toBe( + '

foo1

foo2

' + ) + expect(composerExtendSpy).toHaveBeenCalledTimes(2) + expect(vueI18nExtendSpy).not.toHaveBeenCalled() - // dispose checking - app.unmount() - expect(composerDisposeSpy).toHaveBeenCalledTimes(2) - }) + // dispose checking + app.unmount() + expect(composerDisposeSpy).toHaveBeenCalledTimes(2) }) -describe('dollar prefixed API (component injections)', () => { +test('dollar prefixed API (component injections)', async () => { const mockWarn = vi.spyOn(shared, 'warn') // eslint-disable-next-line @typescript-eslint/no-empty-function mockWarn.mockImplementation(() => {}) @@ -858,17 +848,16 @@ describe('dollar prefixed API (component injections)', () => { } } - test('composition mode', async () => { - const i18n = createI18n({ - locale: 'en', - messages - }) - const App = defineComponent({ - setup() { - useI18n() - return {} - }, - template: `
+ const i18n = createI18n({ + locale: 'en', + messages + }) + const App = defineComponent({ + setup() { + useI18n() + return {} + }, + template: `

{{ $t('hello') }}

{{ $t('list', ['world']) }}

{{ $t('named', { name: 'world' }) }}

@@ -885,16 +874,15 @@ describe('dollar prefixed API (component injections)', () => {

{{ $t('hello', {}, { locale: 'en' }) }}

{{ $t('hello', [], { locale: 'ja' }) }}

` - }) - const wrapper = await mount(App, i18n) - - expect(wrapper.html()).toEqual( - '

hello world!

hello, world!

hello, world!

no apples

りんご1個

default message

default msg

4 apples

default list msg

こんにちは、世界!

many apples

default named msg

こんにちは、世界!

hello world!

こんにちは、世界!

' - ) }) + const wrapper = await mount(App, i18n) + + expect(wrapper.html()).toEqual( + '

hello world!

hello, world!

hello, world!

no apples

りんご1個

default message

default msg

4 apples

default list msg

こんにちは、世界!

many apples

default named msg

こんにちは、世界!

hello world!

こんにちは、世界!

' + ) }) -test('`t` on Composition API mode', async () => { +test('`t`', async () => { const messages = { en: { hello: 'hello world!', diff --git a/packages/vue-i18n-core/test/issues.test.ts b/packages/vue-i18n-core/test/issues.test.ts index b08d9349b..d39ab3707 100644 --- a/packages/vue-i18n-core/test/issues.test.ts +++ b/packages/vue-i18n-core/test/issues.test.ts @@ -132,7 +132,7 @@ const numberFormats: IntlNumberFormats = { } describe('issue #722', () => { - test('composition', async () => { + test('issue #722', async () => { const messages = { en: { language: 'English' }, ja: { language: '日本語' } @@ -169,7 +169,7 @@ describe('issue #722', () => { expect(wrapper.html()).toEqual(`

Hello world!

`) }) - test('v-if: composition', async () => { + test('v-if', async () => { const messages = { en: { language: 'English' }, ja: { language: '日本語' } diff --git a/packages/vue-i18n-core/test/ssr.test.ts b/packages/vue-i18n-core/test/ssr.test.ts index 78134041a..ac8c549da 100644 --- a/packages/vue-i18n-core/test/ssr.test.ts +++ b/packages/vue-i18n-core/test/ssr.test.ts @@ -26,7 +26,7 @@ beforeAll(() => { registerLocaleFallbacker(fallbackWithLocaleChain) }) -test('composition mode', async () => { +test('ssr', async () => { const i18n = createI18n({ locale: 'en', messages: {}