wip(i18n): Config i18n
parent
d7d0ada558
commit
3e002a68f2
@ -1,39 +1,47 @@
|
|||||||
// import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
// const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
console.log(t)
|
||||||
|
|
||||||
|
interface PlaceholderMoel {
|
||||||
|
placeholder?: string
|
||||||
|
startPlaceholder?: string
|
||||||
|
endPlaceholder?: string
|
||||||
|
rangeSeparator?: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param schema 对应组件数据
|
* @param schema 对应组件数据
|
||||||
* @description 用于自动设置placeholder
|
* @description 用于自动设置placeholder
|
||||||
*/
|
*/
|
||||||
export function setTextPlaceholder(schema: VFormSchema): {
|
export function setTextPlaceholder(schema: VFormSchema): PlaceholderMoel {
|
||||||
placeholder?: string
|
|
||||||
startPlaceholder?: string
|
|
||||||
endPlaceholder?: string
|
|
||||||
} {
|
|
||||||
console.log(schema)
|
console.log(schema)
|
||||||
// const textMap = ['Input', 'Autocomplete', 'InputNumber']
|
const textMap = ['Input', 'Autocomplete', 'InputNumber']
|
||||||
// const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
|
const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
|
||||||
// if (textMap.includes(schema?.component as string)) {
|
if (textMap.includes(schema?.component as string)) {
|
||||||
// return {
|
console.log(t('common.inputText'))
|
||||||
// placeholder: t('common.inputText')
|
return {
|
||||||
// }
|
placeholder: t('common.inputText')
|
||||||
// }
|
}
|
||||||
// if (selectMap.includes(schema?.component as string)) {
|
}
|
||||||
// // 一些范围选择器
|
if (selectMap.includes(schema?.component as string)) {
|
||||||
// const twoTextMap = ['datetimerange', 'daterange', 'monthrange', 'datetimerange', 'daterange']
|
// 一些范围选择器
|
||||||
// if (
|
const twoTextMap = ['datetimerange', 'daterange', 'monthrange', 'datetimerange', 'daterange']
|
||||||
// twoTextMap.includes(schema?.componentProps?.type || schema?.componentProps?.isRange) as string
|
if (
|
||||||
// ) {
|
twoTextMap.includes(
|
||||||
// return {
|
(schema?.componentProps?.type || schema?.componentProps?.isRange) as string
|
||||||
// startPlaceholder: t('common.startTimeText'),
|
)
|
||||||
// endPlaceholder: t('common.endTimeText'),
|
) {
|
||||||
// rangeSeparator: '-'
|
return {
|
||||||
// }
|
startPlaceholder: t('common.startTimeText'),
|
||||||
// } else {
|
endPlaceholder: t('common.endTimeText'),
|
||||||
// return {
|
rangeSeparator: '-'
|
||||||
// placeholder: t('common.selectText')
|
}
|
||||||
// }
|
} else {
|
||||||
// }
|
return {
|
||||||
// }
|
placeholder: t('common.selectText')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,50 +1,51 @@
|
|||||||
// // import { i18n } from '@/plugins/i18n'
|
import { i18n } from '@/plugins/i18n'
|
||||||
|
|
||||||
// type I18nGlobalTranslation = {
|
type I18nGlobalTranslation = {
|
||||||
// (key: string): string
|
(key: string): string
|
||||||
// (key: string, locale: string): string
|
(key: string, locale: string): string
|
||||||
// (key: string, locale: string, list: unknown[]): string
|
(key: string, locale: string, list: unknown[]): string
|
||||||
// (key: string, locale: string, named: Record<string, unknown>): string
|
(key: string, locale: string, named: Record<string, unknown>): string
|
||||||
// (key: string, list: unknown[]): string
|
(key: string, list: unknown[]): string
|
||||||
// (key: string, named: Record<string, unknown>): string
|
(key: string, named: Record<string, unknown>): string
|
||||||
// }
|
}
|
||||||
|
|
||||||
// type I18nTranslationRestParameters = [string, any]
|
type I18nTranslationRestParameters = [string, any]
|
||||||
|
|
||||||
// function getKey(namespace: string | undefined, key: string) {
|
function getKey(namespace: string | undefined, key: string) {
|
||||||
// if (!namespace) {
|
if (!namespace) {
|
||||||
// return key
|
return key
|
||||||
// }
|
}
|
||||||
// if (key.startsWith(namespace)) {
|
if (key.startsWith(namespace)) {
|
||||||
// return key
|
return key
|
||||||
// }
|
}
|
||||||
// return `${namespace}.${key}`
|
return `${namespace}.${key}`
|
||||||
// }
|
}
|
||||||
|
|
||||||
// export function useI18n(namespace?: string): {
|
export function useI18n(namespace?: string): {
|
||||||
// t: I18nGlobalTranslation
|
t: I18nGlobalTranslation
|
||||||
// } {
|
} {
|
||||||
// const normalFn = {
|
const normalFn = {
|
||||||
// t: (key: string) => {
|
t: (key: string) => {
|
||||||
// return getKey(namespace, key)
|
return getKey(namespace, key)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
console.log(i18n)
|
||||||
// if (!i18n) {
|
|
||||||
// return normalFn
|
if (!i18n) {
|
||||||
// }
|
return normalFn
|
||||||
|
}
|
||||||
// const { t, ...methods } = i18n.global
|
|
||||||
|
const { t, ...methods } = i18n.global
|
||||||
// const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
|
|
||||||
// if (!key) return ''
|
const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
|
||||||
// if (!key.includes('.') && !namespace) return key
|
if (!key) return ''
|
||||||
// return t(getKey(namespace, key), ...(arg as I18nTranslationRestParameters))
|
if (!key.includes('.') && !namespace) return key
|
||||||
// }
|
return t(getKey(namespace, key), ...(arg as I18nTranslationRestParameters))
|
||||||
// return {
|
}
|
||||||
// ...methods,
|
return {
|
||||||
// t: tFn
|
...methods,
|
||||||
// }
|
t: tFn
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// export const t = (key: string) => key
|
// export const t = (key: string) => key
|
||||||
|
|||||||
Loading…
Reference in New Issue