Skip to content

Commit

Permalink
fix: warning once
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Feb 29, 2024
1 parent ff54ca9 commit c25f507
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
15 changes: 13 additions & 2 deletions packages/vue-i18n-core/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
assign,
inBrowser,
deepCopy,
hasOwn
hasOwn,
warnOnce
} from '@intlify/shared'
import {
isTranslateFallbackWarn,
Expand Down Expand Up @@ -1876,9 +1877,19 @@ export function createComposer(options: any = {}, VueI18nLegacy?: any): any {
>
const _isGlobal = __root === undefined
const flatJson = options.flatJson
const translateExistCompatible = !!options.translateExistCompatible
const _ref = inBrowser ? ref : shallowRef

const translateExistCompatible = !!options.translateExistCompatible
if (__DEV__) {
if (translateExistCompatible && !__TEST__) {
warnOnce(
getWarnMessage(
I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG
)
)
}
}

let _inheritLocale = isBoolean(options.inheritLocale)
? options.inheritLocale
: true
Expand Down
24 changes: 12 additions & 12 deletions packages/vue-i18n-core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ export interface I18n<
* An instance of this property is **global scope***.
*/
readonly global: Legacy extends true
? VueI18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
: Legacy extends false
? Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale>
: unknown
? VueI18n<Messages, DateTimeFormats, NumberFormats, OptionLocale>
: Legacy extends false
? Composer<Messages, DateTimeFormats, NumberFormats, OptionLocale>
: unknown
/**
* The property whether or not the Composition API is available
*
Expand Down Expand Up @@ -529,17 +529,17 @@ export function createI18n(options: any = {}, VueI18nLegacy?: any): any {
// prettier-ignore
const __legacyMode = __LITE__
? false
: __FEATURE_LEGACY_API__ && isBoolean(options.legacy)
: __FEATURE_LEGACY_API__ && isBoolean(options.legacy)
? options.legacy
: __FEATURE_LEGACY_API__
// prettier-ignore
const __globalInjection = isBoolean(options.globalInjection)
? options.globalInjection
: true
? options.globalInjection
: true
// prettier-ignore
const __allowComposition = __LITE__
? true
: __FEATURE_LEGACY_API__ && __legacyMode
: __FEATURE_LEGACY_API__ && __legacyMode
? !!options.allowComposition
: true
const __instances = new Map<ComponentInternalInstance, VueI18n | Composer>()
Expand Down Expand Up @@ -1228,10 +1228,10 @@ function useI18nForLegacy(
const _locale = ref<Locale>(
// prettier-ignore
!isLocalScope || _inheritLocale
? root.locale.value
: isString(options.locale)
? options.locale
: DEFAULT_LOCALE
? root.locale.value
: isString(options.locale)
? options.locale
: DEFAULT_LOCALE
)

const _fallbackLocale = ref<FallbackLocale>(
Expand Down
3 changes: 3 additions & 0 deletions packages/vue-i18n-core/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ function convertComposerOptions<
const datetimeFormats = options.datetimeFormats
const numberFormats = options.numberFormats
const flatJson = options.flatJson
const translateExistCompatible = (options as unknown as ComposerOptions)
.translateExistCompatible

return {
locale,
Expand All @@ -1396,6 +1398,7 @@ function convertComposerOptions<
escapeParameter,
messageResolver: options.messageResolver,
inheritLocale,
translateExistCompatible,
__i18n,
__root,
__injectWithOption
Expand Down
6 changes: 4 additions & 2 deletions packages/vue-i18n-core/src/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const I18nWarnCodes = {
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 14
NOT_FOUND_PARENT_SCOPE: inc(), // 15
IGNORE_OBJ_FLATTEN: inc(), // 16
NOTICE_DROP_ALLOW_COMPOSITION: inc() // 17
NOTICE_DROP_ALLOW_COMPOSITION: inc(), // 17
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 18
} as const

type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes]
Expand All @@ -27,7 +28,8 @@ export const warnMessages: { [code: number]: string } = {
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
[I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,
[I18nWarnCodes.NOTICE_DROP_ALLOW_COMPOSITION]: `'allowComposition' option will be dropped in the next major version. For more information, please see 👉 https://tinyurl.com/2p97mcze`
[I18nWarnCodes.NOTICE_DROP_ALLOW_COMPOSITION]: `'allowComposition' option will be dropped in the next major version. For more information, please see 👉 https://tinyurl.com/2p97mcze`,
[I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG]: `'translateExistCompatible' option will be dropped in the next major version.`
}

export function getWarnMessage(
Expand Down

0 comments on commit c25f507

Please sign in to comment.