/
warnings.ts
30 lines (25 loc) · 1.2 KB
/
warnings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { format, incrementer } from '@intlify/shared'
import { CoreWarnCodes } from '@intlify/core-base'
const code = CoreWarnCodes.__EXTEND_POINT__
const inc = incrementer(code)
export const I18nWarnCodes = {
FALLBACK_TO_ROOT: code, // 8
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 9
NOT_FOUND_PARENT_SCOPE: inc(), // 10
IGNORE_OBJ_FLATTEN: inc(), // 11
NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc() // 12
} as const
type I18nWarnCodes = (typeof I18nWarnCodes)[keyof typeof I18nWarnCodes]
export const warnMessages: { [code: number]: string } = {
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
[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_TRANSLATE_EXIST_COMPATIBLE_FLAG]: `'translateExistCompatible' option will be dropped in the next major version.`
}
export function getWarnMessage(
code: I18nWarnCodes,
...args: unknown[]
): string {
return format(warnMessages[code], ...args)
}