Skip to content

Commit 0c92dcc

Browse files
authored
breaking: drop fully getChoiceIndex on Legacy API (#1829)
1 parent 1d9459a commit 0c92dcc

File tree

6 files changed

+8
-39
lines changed

6 files changed

+8
-39
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,3 @@ Below is the mapping table:
531531
| `getNumberFormat` | `getNumberFormat` |
532532
| `setNumberFormat` | `setNumberFormat` |
533533
| `mergeNumberFormat` | `mergeNumberFormat` |
534-
| `getChoiceIndex` | N/A |

docs/guide/advanced/composition.md

-1
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,3 @@ Below is the mapping table:
500500
| `getNumberFormat` | `getNumberFormat` |
501501
| `setNumberFormat` | `setNumberFormat` |
502502
| `mergeNumberFormat` | `mergeNumberFormat` |
503-
| `getChoiceIndex` | N/A |

docs/guide/migration/breaking.md

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ Similar to *[Translation API return value](#translation-api-return-value)*, the
149149

150150
### Remove `getChoiceIndex`
151151

152+
> [!CAUTION]
153+
> `getChoiceIndex` option implementation code is be going to fully remove in v10.
154+
152155
To customize the pluralization rules, Vue I18n v8.x extends `getChoiceIndex` of VueI18n class.
153156

154157
Vue I18n v8.x:

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { createComposer, DefineLocaleMessage } from './composer'
3-
import { I18nWarnCodes, getWarnMessage } from './warnings'
43
import { createI18nError, I18nErrorCodes } from './errors'
54
import { EnableEmitter, DisableEmitter } from './symbols'
65
import { DEFAULT_LOCALE } from '@intlify/core-base'
@@ -12,8 +11,7 @@ import {
1211
isBoolean,
1312
isFunction,
1413
isRegExp,
15-
assign,
16-
warn
14+
assign
1715
} from '@intlify/shared'
1816

1917
import type {
@@ -1236,15 +1234,6 @@ export interface VueI18n<
12361234
* @param format - A target number format
12371235
*/
12381236
mergeNumberFormat: Composition['mergeNumberFormat']
1239-
/**
1240-
* Get choice index
1241-
*
1242-
* @remarks
1243-
* Get pluralization index for current pluralizing number and a given amount of choices.
1244-
*
1245-
* @deprecated Use `pluralizationRules` option instead of `getChoiceIndex`.
1246-
*/
1247-
getChoiceIndex: (choice: Choice, choicesLength: number) => number
12481237
}
12491238

12501239
/**
@@ -1691,14 +1680,6 @@ export function createVueI18n(options: any = {}): any {
16911680
// mergeNumberFormat
16921681
mergeNumberFormat(locale: Locale, format: NumberFormat): void {
16931682
composer.mergeNumberFormat(locale, format)
1694-
},
1695-
1696-
// getChoiceIndex
1697-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1698-
getChoiceIndex(choice: Choice, choicesLength: number): number {
1699-
__DEV__ &&
1700-
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX))
1701-
return -1
17021683
}
17031684
}
17041685

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ const inc = incrementer(code)
66

77
export const I18nWarnCodes = {
88
FALLBACK_TO_ROOT: code, // 8
9-
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 9
10-
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 10
11-
NOT_FOUND_PARENT_SCOPE: inc(), // 11
12-
IGNORE_OBJ_FLATTEN: inc(), // 12
13-
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 13
9+
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 9
10+
NOT_FOUND_PARENT_SCOPE: inc(), // 10
11+
IGNORE_OBJ_FLATTEN: inc(), // 11
12+
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 12
1413
} as const
1514

1615
type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes]
1716

1817
export const warnMessages: { [code: number]: string } = {
1918
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
20-
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
2119
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
2220
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
2321
[I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,

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

-11
Original file line numberDiff line numberDiff line change
@@ -567,17 +567,6 @@ test('getNumberFormat / setNumberFormat / mergeNumberFormat', () => {
567567
})
568568
})
569569

570-
test('getChoiceIndex', () => {
571-
const mockWarn = vi.spyOn(shared, 'warn')
572-
mockWarn.mockImplementation(() => {})
573-
574-
const i18n = createVueI18n({})
575-
i18n.getChoiceIndex(1, 2)
576-
expect(mockWarn.mock.calls[0][0]).toEqual(
577-
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX)
578-
)
579-
})
580-
581570
test('warnHtmlInMessage', () => {
582571
const mockWarn = vi.spyOn(shared, 'warn')
583572
mockWarn.mockImplementation(() => {})

0 commit comments

Comments
 (0)