Skip to content

Commit b7392ee

Browse files
authored
breaking: drop fully formatter option codes (#1826)
1 parent 5e8ee34 commit b7392ee

File tree

11 files changed

+10
-80
lines changed

11 files changed

+10
-80
lines changed

docs/.ja/guide/advanced/composition.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ Below is the mapping table:
508508
| `datetimeFormats` | `datetimeFormats` |
509509
| `numberFormats` | `numberFormats` |
510510
| `modifiers` | `modifiers` |
511-
| `formatter` | N/A |
512511
| `missing` | `getMissingHandler` / `setMissingHandler` |
513512
| `postTranslation` | `getPostTranslationHandler` / `setPostTranslationHandler`|
514513
| `silentTranslationWarn` | `missingWarn` |

docs/guide/advanced/composition.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ Below is the mapping table:
477477
| `datetimeFormats` | `datetimeFormats` |
478478
| `numberFormats` | `numberFormats` |
479479
| `modifiers` | `modifiers` |
480-
| `formatter` | N/A |
481480
| `missing` | `getMissingHandler` / `setMissingHandler` |
482481
| `postTranslation` | `getPostTranslationHandler` / `setPostTranslationHandler`|
483482
| `silentTranslationWarn` | `missingWarn` |

docs/guide/migration/breaking.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ console.log(VueI18n.availability)
306306

307307
**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/)
308308

309+
> [!CAUTION]
310+
> `formatter` option implementation code is be going to fully remove in v10.
311+
> As an alternative, vue-i18n has the [custome message format](../advanced/format.md) as an experimental feature.
312+
309313
### Remove `preserveDirectiveContent` option
310314

311315
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.

packages/petite-vue-i18n/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export {
8181
WarnHtmlInMessageLevel,
8282
DateTimeFormatResult,
8383
NumberFormatResult,
84-
Formatter,
8584
VueI18nOptions,
8685
VueI18n,
8786
VueI18nTranslation,

packages/petite-vue-i18n/src/runtime.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export {
7373
WarnHtmlInMessageLevel,
7474
DateTimeFormatResult,
7575
NumberFormatResult,
76-
Formatter,
7776
VueI18nOptions,
7877
VueI18n,
7978
VueI18nTranslation,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export {
6363
WarnHtmlInMessageLevel,
6464
DateTimeFormatResult,
6565
NumberFormatResult,
66-
Formatter,
6766
VueI18nOptions,
6867
VueI18n,
6968
VueI18nTranslation,

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ export type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error'
7676
export type DateTimeFormatResult = string
7777
/** @VueI18nLegacy */
7878
export type NumberFormatResult = string
79-
export interface Formatter {
80-
interpolate(message: string, values: any, path: string): Array<any> | null
81-
}
8279
export type VueI18nExtender = (vueI18n: VueI18n) => Disposer | undefined
8380

8481
/**
@@ -181,13 +178,6 @@ export interface VueI18nOptions<
181178
* @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
182179
*/
183180
modifiers?: Options['modifiers']
184-
/**
185-
* @remarks
186-
* The formatter that implemented with Formatter interface.
187-
*
188-
* @deprecated See the [here](../guide/migration/breaking#remove-custom-formatter)
189-
*/
190-
formatter?: Formatter
191181
/**
192182
* @remarks
193183
* A handler for localization missing.
@@ -968,13 +958,6 @@ export interface VueI18n<
968958
* @VueI18nSee [Custom Modifiers](../guide/essentials/syntax#custom-modifiers)
969959
*/
970960
readonly modifiers: Composition['modifiers']
971-
/**
972-
* @remarks
973-
* The formatter that implemented with Formatter interface.
974-
*
975-
* @deprecated See the [here](../guide/migration/breaking#remove-custom-formatter)
976-
*/
977-
formatter: Formatter
978961
/**
979962
* @remarks
980963
* A handler for localization missing.
@@ -1349,10 +1332,6 @@ function convertComposerOptions<
13491332
const escapeParameter = !!options.escapeParameterHtml
13501333
const inheritLocale = isBoolean(options.sync) ? options.sync : true
13511334

1352-
if (__DEV__ && options.formatter) {
1353-
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
1354-
}
1355-
13561335
if (__DEV__ && options.preserveDirectiveContent) {
13571336
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE))
13581337
}
@@ -1512,20 +1491,6 @@ export function createVueI18n(options: any = {}): any {
15121491
return composer.availableLocales as Locale[]
15131492
},
15141493

1515-
// formatter
1516-
get formatter(): Formatter {
1517-
__DEV__ && warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
1518-
// dummy
1519-
return {
1520-
interpolate() {
1521-
return []
1522-
}
1523-
}
1524-
},
1525-
set formatter(val: Formatter) {
1526-
__DEV__ && warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER))
1527-
},
1528-
15291494
// missing
15301495
get missing(): MissingHandler | null {
15311496
return composer.getMissingHandler()

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ const inc = incrementer(code)
77
export const I18nWarnCodes = {
88
FALLBACK_TO_ROOT: code, // 8
99
NOT_SUPPORTED_PRESERVE: inc(), // 9
10-
NOT_SUPPORTED_FORMATTER: inc(), // 10
11-
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc(), // 11
12-
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 12
13-
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 13
14-
NOT_FOUND_PARENT_SCOPE: inc(), // 14
15-
IGNORE_OBJ_FLATTEN: inc(), // 15
16-
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 16
10+
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc(), // 10
11+
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 11
12+
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 12
13+
NOT_FOUND_PARENT_SCOPE: inc(), // 13
14+
IGNORE_OBJ_FLATTEN: inc(), // 14
15+
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 15
1716
} as const
1817

1918
type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes]
2019

2120
export const warnMessages: { [code: number]: string } = {
2221
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
2322
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
24-
[I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supported 'formatter'.`,
2523
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
2624
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
2725
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,

packages/vue-i18n-core/test/legacy.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,6 @@ test('availableLocales', () => {
5757
expect(i18n.availableLocales).toEqual(['en', 'ja', 'ru', 'fr'].sort())
5858
})
5959

60-
test('formatter', () => {
61-
const mockWarn = vi.spyOn(shared, 'warn')
62-
mockWarn.mockImplementation(() => {})
63-
64-
const i18n = createVueI18n({
65-
formatter: {
66-
interpolate() {
67-
return []
68-
}
69-
}
70-
})
71-
72-
expect(i18n.formatter).not.toBeUndefined()
73-
i18n.formatter = {
74-
interpolate() {
75-
return []
76-
}
77-
}
78-
expect(mockWarn).toHaveBeenCalledTimes(3)
79-
expect(mockWarn.mock.calls[0][0]).toEqual(
80-
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
81-
)
82-
expect(mockWarn.mock.calls[1][0]).toEqual(
83-
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
84-
)
85-
expect(mockWarn.mock.calls[2][0]).toEqual(
86-
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
87-
)
88-
})
89-
9060
test('missing', () => {
9161
const i18n = createVueI18n()
9262
expect(i18n.missing).toEqual(null)

packages/vue-i18n/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export {
9191
WarnHtmlInMessageLevel,
9292
DateTimeFormatResult,
9393
NumberFormatResult,
94-
Formatter,
9594
VueI18nOptions,
9695
VueI18n,
9796
VueI18nTranslation,

0 commit comments

Comments
 (0)