Skip to content

Commit 17bfe78

Browse files
authored
breaking: drop translation component v8.x compatibility (#1844)
1 parent 5ff1b1d commit 17bfe78

File tree

7 files changed

+12
-103
lines changed

7 files changed

+12
-103
lines changed

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

+2-26
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { Translation } from './components/Translation'
22
import { NumberFormat } from './components/NumberFormat'
33
import { DatetimeFormat } from './components/DatetimeFormat'
44
import { vTDirective } from './directive'
5-
import { I18nWarnCodes, getWarnMessage } from './warnings'
6-
import { isPlainObject, warn, isBoolean } from '@intlify/shared'
5+
import { isPlainObject, isBoolean } from '@intlify/shared'
76

87
import type { App } from 'vue'
98
import type { I18n } from './i18n'
@@ -17,17 +16,6 @@ import type { I18n } from './i18n'
1716
* @VueI18nGeneral
1817
*/
1918
export interface I18nPluginOptions {
20-
/**
21-
* Whether to use the tag name `i18n` for Translation Component
22-
*
23-
* @remarks
24-
* This option is used for compatibility with Vue I18n v8.x.
25-
*
26-
* If you can't migrate right away, you can temporarily enable this option, and you can work Translation Component.
27-
*
28-
* @defaultValue `false`
29-
*/
30-
useI18nComponentName?: boolean
3119
/**
3220
* Whether to globally install the components that is offered by Vue I18n
3321
*
@@ -45,25 +33,13 @@ export function apply(app: App, i18n: I18n, ...options: unknown[]): void {
4533
const pluginOptions = isPlainObject(options[0])
4634
? (options[0] as I18nPluginOptions)
4735
: {}
48-
const useI18nComponentName = !!pluginOptions.useI18nComponentName
4936
const globalInstall = isBoolean(pluginOptions.globalInstall)
5037
? pluginOptions.globalInstall
5138
: true
5239

53-
if (__DEV__ && globalInstall && useI18nComponentName) {
54-
warn(
55-
getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
56-
name: Translation.name
57-
})
58-
)
59-
}
60-
6140
if (!__LITE__ && globalInstall) {
6241
// install components
63-
app.component(
64-
!useI18nComponentName ? Translation.name : 'i18n',
65-
Translation
66-
)
42+
app.component(Translation.name, Translation)
6743
app.component(NumberFormat.name, NumberFormat)
6844
app.component(DatetimeFormat.name, DatetimeFormat)
6945
}

packages/vue-i18n-core/src/plugin/next.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { Translation } from '../components/Translation'
22
import { NumberFormat } from '../components/NumberFormat'
33
import { DatetimeFormat } from '../components/DatetimeFormat'
44
import { vTDirective } from '../directive'
5-
import { I18nWarnCodes, getWarnMessage } from '../warnings'
6-
import { isPlainObject, warn, isBoolean } from '@intlify/shared'
5+
import { isPlainObject, isBoolean } from '@intlify/shared'
76

87
import type { App } from 'vue'
98
import type { I18n } from '../i18n'
@@ -13,23 +12,14 @@ export function apply(app: App, i18n: I18n, ...options: unknown[]): void {
1312
const pluginOptions = isPlainObject(options[0])
1413
? (options[0] as I18nPluginOptions)
1514
: {}
16-
const useI18nComponentName = !!pluginOptions.useI18nComponentName
1715
const globalInstall = isBoolean(pluginOptions.globalInstall)
1816
? pluginOptions.globalInstall
1917
: true
2018

21-
if (__DEV__ && globalInstall && useI18nComponentName) {
22-
warn(
23-
getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
24-
name: Translation.name
25-
})
26-
)
27-
}
28-
2919
if (!__LITE__ && globalInstall) {
3020
// install components
31-
;[!useI18nComponentName ? Translation.name : 'i18n', 'I18nT'].forEach(
32-
name => app.component(name, Translation)
21+
;[Translation.name, 'I18nT'].forEach(name =>
22+
app.component(name, Translation)
3323
)
3424
;[NumberFormat.name, 'I18nN'].forEach(name =>
3525
app.component(name, NumberFormat)

packages/vue-i18n-core/src/plugin/types.ts

-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
* @VueI18nGeneral
88
*/
99
export interface I18nPluginOptions {
10-
/**
11-
* Whether to use the tag name `i18n` for Translation Component
12-
*
13-
* @remarks
14-
* This option is used for compatibility with Vue I18n v8.x.
15-
*
16-
* If you can't migrate right away, you can temporarily enable this option, and you can work Translation Component.
17-
*
18-
* @defaultValue `false`
19-
*/
20-
useI18nComponentName?: boolean
2110
/**
2211
* Whether to globally install the components that is offered by Vue I18n
2312
*

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ const inc = incrementer(code)
66

77
export const I18nWarnCodes = {
88
FALLBACK_TO_ROOT: code, // 8
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
13-
DEPRECATE_TC: inc(), // 13
14-
__EXTEND_POINT__: inc() // 14
9+
NOT_FOUND_PARENT_SCOPE: inc(), // 9
10+
IGNORE_OBJ_FLATTEN: inc(), // 10
11+
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc(), // 11
12+
DEPRECATE_TC: inc(), // 12
13+
__EXTEND_POINT__: inc() // 13
1514
} as const
1615

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

1918
export const warnMessages: { [code: number]: string } = {
2019
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
21-
[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`,
2422
[I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG]: `'translateExistCompatible' option will be dropped in the next major version.`,

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ export function mount<
9696
const pluginOptions: I18nPluginOptions = isPlainObject(options.pluginOptions)
9797
? options.pluginOptions
9898
: {
99-
globalInstall: true,
100-
useI18nComponentName: false
99+
globalInstall: true
101100
}
102101
if (pluginOptions.globalInstall == null) {
103102
pluginOptions.globalInstall = true
104103
}
105-
if (pluginOptions.useI18nComponentName == null) {
106-
pluginOptions.useI18nComponentName = false
107-
}
108104

109105
return new Promise((resolve, reject) => {
110106
// NOTE: only supports props as an object

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

-40
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,9 @@
33
// directive
44
vitest.mock('../src/directive')
55

6-
// utils
7-
import * as shared from '@intlify/shared'
8-
vi.mock('@intlify/shared', async () => {
9-
const actual = await vi.importActual<object>('@intlify/shared')
10-
return {
11-
...actual,
12-
warn: vi.fn()
13-
}
14-
})
15-
166
import { createApp } from 'vue'
177
import { I18n, I18nInternal } from '../src/i18n'
188
import { apply } from '../src/plugin/next'
19-
import { getWarnMessage, I18nWarnCodes } from '../src/warnings'
20-
21-
describe('useI18nComponentName option', () => {
22-
test('default', () => {
23-
const mockWarn = vi.spyOn(shared, 'warn')
24-
mockWarn.mockImplementation(() => {})
25-
26-
const app = createApp({})
27-
const i18n = {} as I18n & I18nInternal
28-
29-
apply(app, i18n)
30-
expect(mockWarn).not.toHaveBeenCalled()
31-
})
32-
33-
test('true', () => {
34-
const mockWarn = vi.spyOn(shared, 'warn')
35-
mockWarn.mockImplementation(() => {})
36-
37-
const app = createApp({})
38-
const i18n = {} as I18n & I18nInternal
39-
40-
apply(app, i18n, { useI18nComponentName: true })
41-
expect(mockWarn).toHaveBeenCalled()
42-
expect(mockWarn.mock.calls[0][0]).toEqual(
43-
getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
44-
name: 'i18n-t'
45-
})
46-
)
47-
})
48-
})
499

5010
describe('globalInstall option', () => {
5111
test('default', () => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { I18nWarnCodes } from '../src/warnings'
22

33
test('I18nWarnCodes', () => {
4-
expect(I18nWarnCodes.__EXTEND_POINT__).toBe(14)
4+
expect(I18nWarnCodes.__EXTEND_POINT__).toBe(13)
55
})

0 commit comments

Comments
 (0)