Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

breaking: drop fully formatter option codes on Legacy API #1826

Merged
merged 1 commit into from Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/.ja/guide/advanced/composition.md
Expand Up @@ -508,7 +508,6 @@ Below is the mapping table:
| `datetimeFormats` | `datetimeFormats` |
| `numberFormats` | `numberFormats` |
| `modifiers` | `modifiers` |
| `formatter` | N/A |
| `missing` | `getMissingHandler` / `setMissingHandler` |
| `postTranslation` | `getPostTranslationHandler` / `setPostTranslationHandler`|
| `silentTranslationWarn` | `missingWarn` |
Expand Down
1 change: 0 additions & 1 deletion docs/guide/advanced/composition.md
Expand Up @@ -477,7 +477,6 @@ Below is the mapping table:
| `datetimeFormats` | `datetimeFormats` |
| `numberFormats` | `numberFormats` |
| `modifiers` | `modifiers` |
| `formatter` | N/A |
| `missing` | `getMissingHandler` / `setMissingHandler` |
| `postTranslation` | `getPostTranslationHandler` / `setPostTranslationHandler`|
| `silentTranslationWarn` | `missingWarn` |
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/migration/breaking.md
Expand Up @@ -306,6 +306,10 @@ console.log(VueI18n.availability)

**Reason**: Due to hard to provide custom formats in the new compiler and runtime APIs. We are planning to support it in the next major version to support in these APIs. If you would like to use ICU message format, you can use the [@formatjs/vue-intl](https://formatjs.io/docs/vue-intl/)

> [!CAUTION]
> `formatter` option implementation code is be going to fully remove in v10.
> As an alternative, vue-i18n has the [custome message format](../advanced/format.md) as an experimental feature.

### Remove `preserveDirectiveContent` option

The `v-t` directive for Vue 3 now preserves the default content. Therefore, this option and its properties have been removed from the VueI18n instance.
Expand Down
1 change: 0 additions & 1 deletion packages/petite-vue-i18n/src/index.ts
Expand Up @@ -81,7 +81,6 @@ export {
WarnHtmlInMessageLevel,
DateTimeFormatResult,
NumberFormatResult,
Formatter,
VueI18nOptions,
VueI18n,
VueI18nTranslation,
Expand Down
1 change: 0 additions & 1 deletion packages/petite-vue-i18n/src/runtime.ts
Expand Up @@ -73,7 +73,6 @@ export {
WarnHtmlInMessageLevel,
DateTimeFormatResult,
NumberFormatResult,
Formatter,
VueI18nOptions,
VueI18n,
VueI18nTranslation,
Expand Down
1 change: 0 additions & 1 deletion packages/vue-i18n-core/src/index.ts
Expand Up @@ -63,7 +63,6 @@ export {
WarnHtmlInMessageLevel,
DateTimeFormatResult,
NumberFormatResult,
Formatter,
VueI18nOptions,
VueI18n,
VueI18nTranslation,
Expand Down
35 changes: 0 additions & 35 deletions packages/vue-i18n-core/src/legacy.ts
Expand Up @@ -76,9 +76,6 @@ export type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error'
export type DateTimeFormatResult = string
/** @VueI18nLegacy */
export type NumberFormatResult = string
export interface Formatter {
interpolate(message: string, values: any, path: string): Array<any> | null
}
export type VueI18nExtender = (vueI18n: VueI18n) => Disposer | undefined

/**
Expand Down Expand Up @@ -181,13 +178,6 @@ export interface VueI18nOptions<
* @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
*/
modifiers?: Options['modifiers']
/**
* @remarks
* The formatter that implemented with Formatter interface.
*
* @deprecated See the [here](../guide/migration/breaking#remove-custom-formatter)
*/
formatter?: Formatter
/**
* @remarks
* A handler for localization missing.
Expand Down Expand Up @@ -968,13 +958,6 @@ export interface VueI18n<
* @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
*/
readonly modifiers: Composition['modifiers']
/**
* @remarks
* The formatter that implemented with Formatter interface.
*
* @deprecated See the [here](../guide/migration/breaking#remove-custom-formatter)
*/
formatter: Formatter
/**
* @remarks
* A handler for localization missing.
Expand Down Expand Up @@ -1349,10 +1332,6 @@ function convertComposerOptions<
const escapeParameter = !!options.escapeParameterHtml
const inheritLocale = isBoolean(options.sync) ? options.sync : true

if (__DEV__ && options.formatter) {
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
}

if (__DEV__ && options.preserveDirectiveContent) {
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE))
}
Expand Down Expand Up @@ -1512,20 +1491,6 @@ export function createVueI18n(options: any = {}): any {
return composer.availableLocales as Locale[]
},

// formatter
get formatter(): Formatter {
__DEV__ && warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
// dummy
return {
interpolate() {
return []
}
}
},
set formatter(val: Formatter) {
__DEV__ && warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
},

// missing
get missing(): MissingHandler | null {
return composer.getMissingHandler()
Expand Down
14 changes: 6 additions & 8 deletions packages/vue-i18n-core/src/warnings.ts
Expand Up @@ -7,21 +7,19 @@ const inc = incrementer(code)
export const I18nWarnCodes = {
FALLBACK_TO_ROOT: code, // 8
NOT_SUPPORTED_PRESERVE: inc(), // 9
NOT_SUPPORTED_FORMATTER: inc(), // 10
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc(), // 11
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 12
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 13
NOT_FOUND_PARENT_SCOPE: inc(), // 14
IGNORE_OBJ_FLATTEN: inc(), // 15
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 16
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc(), // 10
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 11
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 12
NOT_FOUND_PARENT_SCOPE: inc(), // 13
IGNORE_OBJ_FLATTEN: inc(), // 14
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 15
} as const

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_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
[I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supported 'formatter'.`,
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
Expand Down
30 changes: 0 additions & 30 deletions packages/vue-i18n-core/test/legacy.test.ts
Expand Up @@ -57,36 +57,6 @@ test('availableLocales', () => {
expect(i18n.availableLocales).toEqual(['en', 'ja', 'ru', 'fr'].sort())
})

test('formatter', () => {
const mockWarn = vi.spyOn(shared, 'warn')
mockWarn.mockImplementation(() => {})

const i18n = createVueI18n({
formatter: {
interpolate() {
return []
}
}
})

expect(i18n.formatter).not.toBeUndefined()
i18n.formatter = {
interpolate() {
return []
}
}
expect(mockWarn).toHaveBeenCalledTimes(3)
expect(mockWarn.mock.calls[0][0]).toEqual(
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
)
expect(mockWarn.mock.calls[1][0]).toEqual(
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
)
expect(mockWarn.mock.calls[2][0]).toEqual(
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
)
})

test('missing', () => {
const i18n = createVueI18n()
expect(i18n.missing).toEqual(null)
Expand Down
1 change: 0 additions & 1 deletion packages/vue-i18n/src/index.ts
Expand Up @@ -91,7 +91,6 @@ export {
WarnHtmlInMessageLevel,
DateTimeFormatResult,
NumberFormatResult,
Formatter,
VueI18nOptions,
VueI18n,
VueI18nTranslation,
Expand Down
1 change: 0 additions & 1 deletion packages/vue-i18n/src/runtime.ts
Expand Up @@ -83,7 +83,6 @@ export {
WarnHtmlInMessageLevel,
DateTimeFormatResult,
NumberFormatResult,
Formatter,
VueI18nOptions,
VueI18n,
VueI18nTranslation,
Expand Down