Skip to content

Commit 1d9459a

Browse files
authored
breaking: drop fully preserve modifier codes on v-t directive (#1828)
1 parent f2c31d4 commit 1d9459a

File tree

4 files changed

+10
-50
lines changed

4 files changed

+10
-50
lines changed

docs/guide/migration/breaking.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ console.log(VueI18n.availability)
314314

315315
> [!CAUTION]
316316
> `preserveDirectiveContent` option implementation code is be going to fully remove in v10.
317-
> As an alternative.
318317
319318
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.
320319

@@ -420,6 +419,9 @@ const messages = {
420419

421420
### Remove `preserve` modifier
422421

422+
> [!CAUTION]
423+
> `preserve` modifier implementation code is be going to fully remove in v10.
424+
423425
Similar to *[Remove `preserveDirectiveContent` option](#remove-preservedirectivecontent-option)*, the `v-t` directive for Vue 3 now preserves the default content. Therefore, `preserve` modifier and it’s have been removed from `v-t` directive.
424426

425427
Vue I18n v8.x:

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { watch } from 'vue'
2-
import { I18nWarnCodes, getWarnMessage } from './warnings'
32
import { createI18nError, I18nErrorCodes } from './errors'
4-
import {
5-
isString,
6-
isPlainObject,
7-
isNumber,
8-
warn,
9-
inBrowser
10-
} from '@intlify/shared'
3+
import { isString, isPlainObject, isNumber, inBrowser } from '@intlify/shared'
114

125
import type {
136
DirectiveBinding,
@@ -89,16 +82,13 @@ export type TranslationDirective<T = HTMLElement> = ObjectDirective<T>
8982

9083
export function vTDirective(i18n: I18n): TranslationDirective<HTMLElement> {
9184
const _process = (binding: DirectiveBinding): [string, Composer] => {
92-
const { instance, modifiers, value } = binding
85+
const { instance, value } = binding
9386
/* istanbul ignore if */
9487
if (!instance || !instance.$) {
9588
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR)
9689
}
9790

9891
const composer = getComposer(i18n, instance.$)
99-
if (__DEV__ && modifiers.preserve) {
100-
warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE))
101-
}
10292

10393
const parsedValue = parseValue(value)
10494
return [

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

Lines changed: 5 additions & 7 deletions
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-
NOT_SUPPORTED_PRESERVE: inc(), // 9
10-
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 10
11-
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 11
12-
NOT_FOUND_PARENT_SCOPE: inc(), // 12
13-
IGNORE_OBJ_FLATTEN: inc(), // 13
14-
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 14
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
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.NOT_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
2220
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
2321
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
2422
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,36 +141,6 @@ test('plural', async () => {
141141
expect(wrapper.html()).toEqual('<p>2 bananas</p>')
142142
})
143143

144-
test('preserve modifier', async () => {
145-
const mockWarn = vi.spyOn(shared, 'warn')
146-
mockWarn.mockImplementation(() => {})
147-
148-
const i18n = createI18n({
149-
locale: 'en',
150-
messages: {
151-
en: {
152-
hello: 'hello!'
153-
}
154-
}
155-
})
156-
157-
const App = defineComponent({
158-
setup() {
159-
// <p v-t.preserve="'hello'"></p>
160-
const t = resolveDirective('t')
161-
return () => {
162-
return withDirectives(h('p'), [[t!, 'hello', '', { preserve: true }]])
163-
}
164-
}
165-
})
166-
await mount(App, i18n)
167-
168-
expect(mockWarn).toHaveBeenCalledTimes(1)
169-
expect(mockWarn.mock.calls[0][0]).toEqual(
170-
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE)
171-
)
172-
})
173-
174144
test('legacy mode', async () => {
175145
const i18n = createI18n({
176146
legacy: true,

0 commit comments

Comments
 (0)