Skip to content

Commit 9170ec0

Browse files
authored
breaking: drop te behavior v8.x compatibility on v9 (#1845)
1 parent 17bfe78 commit 9170ec0

File tree

6 files changed

+10
-114
lines changed

6 files changed

+10
-114
lines changed

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

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
assign,
1414
inBrowser,
1515
deepCopy,
16-
hasOwn,
17-
warnOnce
16+
hasOwn
1817
} from '@intlify/shared'
1918
import {
2019
isTranslateFallbackWarn,
@@ -611,24 +610,6 @@ export interface ComposerOptions<
611610
* @defaultValue `undefined`
612611
*/
613612
messageCompiler?: MessageCompiler
614-
/**
615-
* @remarks
616-
* An option to make `te` behavior specification before v9.6
617-
*
618-
* @VueI18nTip
619-
* :new: v9.10+
620-
*
621-
* @VueI18nWarning
622-
* This flag will be removed in v10.
623-
*
624-
* @VueI18nSee [GitHub Issue](https://github.com/intlify/vue-i18n-next/issues/1738)
625-
*
626-
* @VueI18nSee [`te`](composition#te-key-locale)
627-
*
628-
* @defaultValue `false`
629-
*
630-
*/
631-
translateExistCompatible?: boolean
632613
}
633614

634615
/**
@@ -1954,17 +1935,6 @@ export function createComposer(options: any = {}): any {
19541935
const flatJson = options.flatJson
19551936
const _ref = inBrowser ? ref : shallowRef
19561937

1957-
const translateExistCompatible = !!options.translateExistCompatible
1958-
if (__DEV__) {
1959-
if (translateExistCompatible && !__TEST__) {
1960-
warnOnce(
1961-
getWarnMessage(
1962-
I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG
1963-
)
1964-
)
1965-
}
1966-
}
1967-
19681938
let _inheritLocale = isBoolean(options.inheritLocale)
19691939
? options.inheritLocale
19701940
: true
@@ -2414,11 +2384,11 @@ export function createComposer(options: any = {}): any {
24142384
const targetLocale = isString(locale) ? locale : _locale.value
24152385
const message = getLocaleMessage(targetLocale)
24162386
const resolved = _context.messageResolver(message, key)
2417-
return !translateExistCompatible
2418-
? isMessageAST(resolved) ||
2419-
isMessageFunction(resolved) ||
2420-
isString(resolved)
2421-
: resolved != null
2387+
return (
2388+
isMessageAST(resolved) ||
2389+
isMessageFunction(resolved) ||
2390+
isString(resolved)
2391+
)
24222392
},
24232393
() => [key],
24242394
'translate exists',

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,6 @@ function convertComposerOptions<
14871487
const datetimeFormats = options.datetimeFormats
14881488
const numberFormats = options.numberFormats
14891489
const flatJson = options.flatJson
1490-
const translateExistCompatible = (options as unknown as ComposerOptions)
1491-
.translateExistCompatible
14921490

14931491
return {
14941492
locale,
@@ -1509,7 +1507,6 @@ function convertComposerOptions<
15091507
escapeParameter,
15101508
messageResolver: options.messageResolver,
15111509
inheritLocale,
1512-
translateExistCompatible,
15131510
__i18n,
15141511
__root,
15151512
__injectWithOption

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export const I18nWarnCodes = {
88
FALLBACK_TO_ROOT: code, // 8
99
NOT_FOUND_PARENT_SCOPE: inc(), // 9
1010
IGNORE_OBJ_FLATTEN: inc(), // 10
11-
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc(), // 11
12-
DEPRECATE_TC: inc(), // 12
13-
__EXTEND_POINT__: inc() // 13
11+
DEPRECATE_TC: inc(), // 11
12+
__EXTEND_POINT__: inc() // 12
1413
} as const
1514

1615
type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes]
@@ -19,7 +18,6 @@ export const warnMessages: { [code: number]: string } = {
1918
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
2019
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
2120
[I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,
22-
[I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG]: `'translateExistCompatible' option will be dropped in the next major version.`,
2321
[I18nWarnCodes.DEPRECATE_TC]: `'tc' and '$tc' has been deprecated in v10. Use 't' or '$t' instead. 'tc' and '$tc’ are going to remove in v11.`
2422
}
2523

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

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,75 +1268,6 @@ test('issue #1717', async () => {
12681268
})
12691269
})
12701270

1271-
test('issue #1738', async () => {
1272-
const resources = {
1273-
en: {
1274-
messages: {
1275-
common: {
1276-
actions: {
1277-
cancel: 'Cancel'
1278-
}
1279-
}
1280-
}
1281-
},
1282-
nl: {
1283-
messages: {
1284-
common: {
1285-
actions: {
1286-
cancel: 'Cancel'
1287-
}
1288-
}
1289-
}
1290-
}
1291-
}
1292-
1293-
function loadTranslations(): Promise<typeof resources> {
1294-
return new Promise(resolve => resolve(resources))
1295-
}
1296-
1297-
function delay(ms: number) {
1298-
return new Promise(resolve => setTimeout(resolve, ms))
1299-
}
1300-
1301-
const i18n = createI18n({
1302-
locale: 'nl',
1303-
legacy: false,
1304-
translateExistCompatible: true,
1305-
fallbackLocale: 'en',
1306-
missingWarn: false,
1307-
silentFallbackWarn: true
1308-
})
1309-
1310-
const App = defineComponent({
1311-
setup() {
1312-
const { mergeLocaleMessage, te } = useI18n()
1313-
onMounted(() => {
1314-
setTimeout(async () => {
1315-
const data = await loadTranslations()
1316-
1317-
for (const key in data) {
1318-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1319-
const { messages } = (data as any)[key]
1320-
mergeLocaleMessage(key, messages)
1321-
}
1322-
}, 100)
1323-
})
1324-
return { te }
1325-
},
1326-
template: `<div>
1327-
<p id="te1">{{ te('common') }} - expected true</p>
1328-
<p id="te2">{{ te('common.actions') }} - expected true</p>
1329-
</div>`
1330-
})
1331-
1332-
const wrapper = await mount(App, i18n)
1333-
1334-
await delay(110)
1335-
1336-
expect(wrapper.find('#te1')?.textContent).toEqual(`true - expected true`)
1337-
expect(wrapper.find('#te2')?.textContent).toEqual(`true - expected true`)
1338-
})
1339-
13401271
describe('issue #1768', () => {
13411272
test('Implicit fallback using locales', async () => {
13421273
const mockWarn = vi.spyOn(shared, 'warn')
Lines changed: 1 addition & 1 deletion
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(13)
4+
expect(I18nWarnCodes.__EXTEND_POINT__).toBe(12)
55
})

packages/vue-i18n/src/vue.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ declare module '@vue/runtime-core' {
718718
* @param key - A target locale message key
719719
* @param locale - A locale, optional, override locale that global scope or local scope
720720
*
721-
* @returns If found locale message, `true`, else `false`, Note that `false` is returned even if the value present in the key is not translatable, yet if `translateExistCompatible` is set to `true`, it will return `true` if the key is available, even if the value is not translatable.
721+
* @returns If found locale message, `true`, else `false`, Note that `false` is returned even if the value present in the key is not translatable.
722722
*/
723723
$te<
724724
Key extends string,

0 commit comments

Comments
 (0)