refactor(i18n): use JSON with flattened key and namespace (#30114)

Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Stephen Zhou
2025-12-29 14:52:32 +08:00
committed by GitHub
parent 09be869f58
commit 6d0e36479b
2552 changed files with 111159 additions and 142972 deletions

View File

@ -120,7 +120,7 @@ const BaseField = ({
help,
].map(v => getTranslatedContent({ content: v, render: renderI18nObject }))
if (!results[1])
results[1] = t('common.placeholder.input')
results[1] = t('placeholder.input', { ns: 'common' })
return results
}, [label, placeholder, tooltip, description, help, renderI18nObject])
@ -257,12 +257,12 @@ const BaseField = ({
disabled={disabled || isDynamicOptionsLoading}
placeholder={
isDynamicOptionsLoading
? t('common.dynamicSelect.loading')
? t('dynamicSelect.loading', { ns: 'common' })
: translatedPlaceholder
}
{...(dynamicOptionsError
? { popupProps: { title: t('common.dynamicSelect.error'), titleClassName: 'text-text-destructive-secondary' } }
: (!dynamicOptions.length ? { popupProps: { title: t('common.dynamicSelect.noData') } } : {}))}
? { popupProps: { title: t('dynamicSelect.error', { ns: 'common' }), titleClassName: 'text-text-destructive-secondary' } }
: (!dynamicOptions.length ? { popupProps: { title: t('dynamicSelect.noData', { ns: 'common' }) } } : {}))}
triggerPopupSameWidth
multiple={multiple}
/>

View File

@ -1,3 +1,5 @@
import type { InputType } from './types'
import type { I18nKeysByPrefix } from '@/types/i18n'
import {
RiAlignLeft,
RiCheckboxLine,
@ -11,11 +13,17 @@ import { useTranslation } from 'react-i18next'
import { PipelineInputVarType } from '@/models/pipeline'
import { InputTypeEnum } from './types'
const i18nFileTypeMap: Record<string, string> = {
type VariableConfigKeySuffix = I18nKeysByPrefix<'appDebug', 'variableConfig.'>
const i18nFileTypeMap = {
'text-input': 'text-input',
'paragraph': 'paragraph',
'number': 'number',
'select': 'select',
'checkbox': 'checkbox',
'file': 'single-file',
'file-list': 'multi-files',
}
} satisfies Record<InputType, VariableConfigKeySuffix>
const INPUT_TYPE_ICON = {
[PipelineInputVarType.textInput]: RiTextSnippet,
@ -44,7 +52,7 @@ export const useInputTypeOptions = (supportFile: boolean) => {
return options.map((value) => {
return {
value,
label: t(`appDebug.variableConfig.${i18nFileTypeMap[value] || value}` as any),
label: t(`variableConfig.${i18nFileTypeMap[value]}`, { ns: 'appDebug' }),
Icon: INPUT_TYPE_ICON[value],
type: DATA_TYPE[value],
}

View File

@ -29,7 +29,7 @@ const Trigger = ({
</>
)
: (
<span className="grow p-1">{t('common.placeholder.select')}</span>
<span className="grow p-1">{t('placeholder.select', { ns: 'common' })}</span>
)}
<RiArrowDownSLine
className={cn(

View File

@ -36,7 +36,7 @@ const UploadMethodField = ({
/>
<div className="grid grid-cols-3 gap-2">
<OptionCard
title={t('appDebug.variableConfig.localUpload')}
title={t('variableConfig.localUpload', { ns: 'appDebug' })}
selected={value.length === 1 && value.includes(TransferMethod.local_file)}
onSelect={handleUploadMethodChange.bind(null, TransferMethod.local_file)}
/>
@ -46,7 +46,7 @@ const UploadMethodField = ({
onSelect={handleUploadMethodChange.bind(null, TransferMethod.remote_url)}
/>
<OptionCard
title={t('appDebug.variableConfig.both')}
title={t('variableConfig.both', { ns: 'appDebug' })}
selected={value.includes(TransferMethod.local_file) && value.includes(TransferMethod.remote_url)}
onSelect={handleUploadMethodChange.bind(null, TransferMethod.all)}
/>

View File

@ -35,7 +35,7 @@ const Actions = ({
loading={isSubmitting}
onClick={() => form.handleSubmit()}
>
{t('common.operation.submit')}
{t('operation.submit', { ns: 'common' })}
</Button>
)
}

View File

@ -30,7 +30,7 @@ const Label = ({
>
{label}
</label>
{!isRequired && showOptional && <div className="system-xs-regular ml-1 text-text-tertiary">{t('common.label.optional')}</div>}
{!isRequired && showOptional && <div className="system-xs-regular ml-1 text-text-tertiary">{t('label.optional', { ns: 'common' })}</div>}
{isRequired && <div className="system-xs-regular ml-1 text-text-destructive-secondary">*</div>}
{tooltip && (
<Tooltip

View File

@ -33,15 +33,15 @@ export const useGetValidators = () => {
mergedValidators = {
onMount: ({ value }: any) => {
if (!value)
return t('common.errorMsg.fieldRequired', { field: memorizedLabel || name })
return t('errorMsg.fieldRequired', { ns: 'common', field: memorizedLabel || name })
},
onChange: ({ value }: any) => {
if (!value)
return t('common.errorMsg.fieldRequired', { field: memorizedLabel || name })
return t('errorMsg.fieldRequired', { ns: 'common', field: memorizedLabel || name })
},
onBlur: ({ value }: any) => {
if (!value)
return t('common.errorMsg.fieldRequired', { field: memorizedLabel })
return t('errorMsg.fieldRequired', { ns: 'common', field: memorizedLabel })
},
}
}