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

@ -31,7 +31,7 @@ const Installed: FC<Props> = ({
return (
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<p className="system-md-regular text-text-secondary">{(isFailed && errMsg) ? errMsg : t(`plugin.installModal.${isFailed ? 'installFailedDesc' : 'installedSuccessfullyDesc'}`)}</p>
<p className="system-md-regular text-text-secondary">{(isFailed && errMsg) ? errMsg : t(`installModal.${isFailed ? 'installFailedDesc' : 'installedSuccessfullyDesc'}`, { ns: 'plugin' })}</p>
{payload && (
<div className="flex flex-wrap content-start items-start gap-1 self-stretch rounded-2xl bg-background-section-burn p-2">
<Card
@ -51,7 +51,7 @@ const Installed: FC<Props> = ({
className="min-w-[72px]"
onClick={handleClose}
>
{t('common.operation.close')}
{t('operation.close', { ns: 'common' })}
</Button>
</div>
</>

View File

@ -31,10 +31,10 @@ const LoadingError: FC = () => {
</div>
<div className="ml-3 grow">
<div className="system-md-semibold flex h-5 items-center text-text-destructive">
{t('plugin.installModal.pluginLoadError')}
{t('installModal.pluginLoadError', { ns: 'plugin' })}
</div>
<div className="system-xs-regular mt-0.5 text-text-tertiary">
{t('plugin.installModal.pluginLoadErrorDesc')}
{t('installModal.pluginLoadErrorDesc', { ns: 'plugin' })}
</div>
</div>
</div>

View File

@ -10,7 +10,7 @@ import { InstallStep } from '../../types'
import useHideLogic from '../hooks/use-hide-logic'
import ReadyToInstall from './ready-to-install'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
export enum InstallType {
fromLocal = 'fromLocal',
@ -42,11 +42,11 @@ const InstallBundle: FC<Props> = ({
const getTitle = useCallback(() => {
if (step === InstallStep.uploadFailed)
return t(`${i18nPrefix}.uploadFailed`)
return t(`${i18nPrefix}.uploadFailed`, { ns: 'plugin' })
if (step === InstallStep.installed)
return t(`${i18nPrefix}.installComplete`)
return t(`${i18nPrefix}.installComplete`, { ns: 'plugin' })
return t(`${i18nPrefix}.installPlugin`)
return t(`${i18nPrefix}.installPlugin`, { ns: 'plugin' })
}, [step, t])
return (

View File

@ -20,7 +20,7 @@ import checkTaskStatus from '../../base/check-task-status'
import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
import InstallMulti from './install-multi'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type Props = {
allPlugins: Dependency[]
@ -173,7 +173,7 @@ const Install: FC<Props> = ({
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.${selectedPluginsNum > 1 ? 'readyToInstallPackages' : 'readyToInstallPackage'}`, { num: selectedPluginsNum })}</p>
<p>{t(`${i18nPrefix}.${selectedPluginsNum > 1 ? 'readyToInstallPackages' : 'readyToInstallPackage'}`, { ns: 'plugin', num: selectedPluginsNum })}</p>
</div>
<div className="w-full space-y-1 rounded-2xl bg-background-section-burn p-2">
<InstallMulti
@ -195,14 +195,14 @@ const Install: FC<Props> = ({
{canInstall && (
<div className="flex items-center gap-x-2" onClick={handleClickSelectAll}>
<Checkbox checked={isSelectAll} indeterminate={isIndeterminate} />
<p className="system-sm-medium cursor-pointer text-text-secondary">{isSelectAll ? t('common.operation.deSelectAll') : t('common.operation.selectAll')}</p>
<p className="system-sm-medium cursor-pointer text-text-secondary">{isSelectAll ? t('operation.deSelectAll', { ns: 'common' }) : t('operation.selectAll', { ns: 'common' })}</p>
</div>
)}
</div>
<div className="flex items-center justify-end gap-2 self-stretch">
{!canInstall && (
<Button variant="secondary" className="min-w-[72px]" onClick={handleCancel}>
{t('common.operation.cancel')}
{t('operation.cancel', { ns: 'common' })}
</Button>
)}
<Button
@ -212,7 +212,7 @@ const Install: FC<Props> = ({
onClick={handleInstall}
>
{isInstalling && <RiLoader2Line className="h-4 w-4 animate-spin-slow" />}
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`, { ns: 'plugin' })}</span>
</Button>
</div>
</div>

View File

@ -54,7 +54,7 @@ const Installed: FC<Props> = ({
className="min-w-[72px]"
onClick={onCancel}
>
{t('common.operation.close')}
{t('operation.close', { ns: 'common' })}
</Button>
</div>
)}

View File

@ -20,7 +20,7 @@ import Loaded from './steps/loaded'
import SelectPackage from './steps/selectPackage'
import SetURL from './steps/setURL'
const i18nPrefix = 'plugin.installFromGitHub'
const i18nPrefix = 'installFromGitHub'
type InstallFromGitHubProps = {
updatePayload?: UpdateFromGitHubPayload
@ -71,11 +71,11 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
const getTitle = useCallback(() => {
if (state.step === InstallStepFromGitHub.installed)
return t(`${i18nPrefix}.installedSuccessfully`)
return t(`${i18nPrefix}.installedSuccessfully`, { ns: 'plugin' })
if (state.step === InstallStepFromGitHub.installFailed)
return t(`${i18nPrefix}.installFailed`)
return t(`${i18nPrefix}.installFailed`, { ns: 'plugin' })
return updatePayload ? t(`${i18nPrefix}.updatePlugin`) : t(`${i18nPrefix}.installPlugin`)
return updatePayload ? t(`${i18nPrefix}.updatePlugin`, { ns: 'plugin' }) : t(`${i18nPrefix}.installPlugin`, { ns: 'plugin' })
}, [state.step, t, updatePayload])
const handleUrlSubmit = async () => {
@ -83,7 +83,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
if (!isValid || !owner || !repo) {
Toast.notify({
type: 'error',
message: t('plugin.error.inValidGitHubUrl'),
message: t('error.inValidGitHubUrl', { ns: 'plugin' }),
})
return
}
@ -99,20 +99,20 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
else {
Toast.notify({
type: 'error',
message: t('plugin.error.noReleasesFound'),
message: t('error.noReleasesFound', { ns: 'plugin' }),
})
}
}
catch {
Toast.notify({
type: 'error',
message: t('plugin.error.fetchReleasesError'),
message: t('error.fetchReleasesError', { ns: 'plugin' }),
})
}
}
const handleError = (e: any, isInstall: boolean) => {
const message = e?.response?.message || t('plugin.installModal.installFailedDesc')
const message = e?.response?.message || t('installModal.installFailedDesc', { ns: 'plugin' })
setErrorMsg(message)
setState(prevState => ({ ...prevState, step: isInstall ? InstallStepFromGitHub.installFailed : InstallStepFromGitHub.uploadFailed }))
}
@ -179,7 +179,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
{getTitle()}
</div>
<div className="system-xs-regular self-stretch text-text-tertiary">
{!([InstallStepFromGitHub.uploadFailed, InstallStepFromGitHub.installed, InstallStepFromGitHub.installFailed].includes(state.step)) && t('plugin.installFromGitHub.installNote')}
{!([InstallStepFromGitHub.uploadFailed, InstallStepFromGitHub.installed, InstallStepFromGitHub.installFailed].includes(state.step)) && t('installFromGitHub.installNote', { ns: 'plugin' })}
</div>
</div>
</div>

View File

@ -28,7 +28,7 @@ type LoadedProps = {
onFailed: (message?: string) => void
}
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
const Loaded: React.FC<LoadedProps> = ({
updatePayload,
@ -144,7 +144,7 @@ const Loaded: React.FC<LoadedProps> = ({
return (
<>
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.readyToInstall`)}</p>
<p>{t(`${i18nPrefix}.readyToInstall`, { ns: 'plugin' })}</p>
</div>
<div className="flex flex-wrap content-start items-start gap-1 self-stretch rounded-2xl bg-background-section-burn p-2">
<Card
@ -162,7 +162,7 @@ const Loaded: React.FC<LoadedProps> = ({
<div className="mt-4 flex items-center justify-end gap-2 self-stretch">
{!isInstalling && (
<Button variant="secondary" className="min-w-[72px]" onClick={onBack}>
{t('plugin.installModal.back')}
{t('installModal.back', { ns: 'plugin' })}
</Button>
)}
<Button
@ -172,7 +172,7 @@ const Loaded: React.FC<LoadedProps> = ({
disabled={isInstalling || isLoading}
>
{isInstalling && <RiLoader2Line className="h-4 w-4 animate-spin-slow" />}
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`, { ns: 'plugin' })}</span>
</Button>
</div>
</>

View File

@ -8,7 +8,7 @@ import Button from '@/app/components/base/button'
import { PortalSelect } from '@/app/components/base/select'
import { useGitHubUpload } from '../../hooks'
const i18nPrefix = 'plugin.installFromGitHub'
const i18nPrefix = 'installFromGitHub'
type SelectPackageProps = {
updatePayload: UpdateFromGitHubPayload
@ -62,7 +62,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
if (e.response?.message)
onFailed(e.response?.message)
else
onFailed(t(`${i18nPrefix}.uploadFailed`))
onFailed(t(`${i18nPrefix}.uploadFailed`, { ns: 'plugin' }))
}
finally {
setIsUploading(false)
@ -75,14 +75,14 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
htmlFor="version"
className="flex flex-col items-start justify-center self-stretch text-text-secondary"
>
<span className="system-sm-semibold">{t(`${i18nPrefix}.selectVersion`)}</span>
<span className="system-sm-semibold">{t(`${i18nPrefix}.selectVersion`, { ns: 'plugin' })}</span>
</label>
<PortalSelect
value={selectedVersion}
onSelect={onSelectVersion}
items={versions}
installedValue={updatePayload?.originalPackageInfo.version}
placeholder={t(`${i18nPrefix}.selectVersionPlaceholder`) || ''}
placeholder={t(`${i18nPrefix}.selectVersionPlaceholder`, { ns: 'plugin' }) || ''}
popupClassName="w-[512px] z-[1001]"
triggerClassName="text-components-input-text-filled"
/>
@ -90,14 +90,14 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
htmlFor="package"
className="flex flex-col items-start justify-center self-stretch text-text-secondary"
>
<span className="system-sm-semibold">{t(`${i18nPrefix}.selectPackage`)}</span>
<span className="system-sm-semibold">{t(`${i18nPrefix}.selectPackage`, { ns: 'plugin' })}</span>
</label>
<PortalSelect
value={selectedPackage}
onSelect={onSelectPackage}
items={packages}
readonly={!selectedVersion}
placeholder={t(`${i18nPrefix}.selectPackagePlaceholder`) || ''}
placeholder={t(`${i18nPrefix}.selectPackagePlaceholder`, { ns: 'plugin' }) || ''}
popupClassName="w-[512px] z-[1001]"
triggerClassName="text-components-input-text-filled"
/>
@ -110,7 +110,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
onClick={onBack}
disabled={isUploading}
>
{t('plugin.installModal.back')}
{t('installModal.back', { ns: 'plugin' })}
</Button>
)}
<Button
@ -119,7 +119,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
onClick={handleUploadPackage}
disabled={!selectedVersion || !selectedPackage || isUploading}
>
{t('plugin.installModal.next')}
{t('installModal.next', { ns: 'plugin' })}
</Button>
</div>
</>

View File

@ -19,7 +19,7 @@ const SetURL: React.FC<SetURLProps> = ({ repoUrl, onChange, onNext, onCancel })
htmlFor="repoUrl"
className="flex flex-col items-start justify-center self-stretch text-text-secondary"
>
<span className="system-sm-semibold">{t('plugin.installFromGitHub.gitHubRepo')}</span>
<span className="system-sm-semibold">{t('installFromGitHub.gitHubRepo', { ns: 'plugin' })}</span>
</label>
<input
type="url"
@ -38,7 +38,7 @@ const SetURL: React.FC<SetURLProps> = ({ repoUrl, onChange, onNext, onCancel })
className="min-w-[72px]"
onClick={onCancel}
>
{t('plugin.installModal.cancel')}
{t('installModal.cancel', { ns: 'plugin' })}
</Button>
<Button
variant="primary"
@ -46,7 +46,7 @@ const SetURL: React.FC<SetURLProps> = ({ repoUrl, onChange, onNext, onCancel })
onClick={onNext}
disabled={!repoUrl.trim()}
>
{t('plugin.installModal.next')}
{t('installModal.next', { ns: 'plugin' })}
</Button>
</div>
</>

View File

@ -13,7 +13,7 @@ import ReadyToInstallBundle from '../install-bundle/ready-to-install'
import ReadyToInstallPackage from './ready-to-install'
import Uploading from './steps/uploading'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type InstallFromLocalPackageProps = {
file: File
@ -43,15 +43,15 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
const getTitle = useCallback(() => {
if (step === InstallStep.uploadFailed)
return t(`${i18nPrefix}.uploadFailed`)
return t(`${i18nPrefix}.uploadFailed`, { ns: 'plugin' })
if (isBundle && step === InstallStep.installed)
return t(`${i18nPrefix}.installComplete`)
return t(`${i18nPrefix}.installComplete`, { ns: 'plugin' })
if (step === InstallStep.installed)
return t(`${i18nPrefix}.installedSuccessfully`)
return t(`${i18nPrefix}.installedSuccessfully`, { ns: 'plugin' })
if (step === InstallStep.installFailed)
return t(`${i18nPrefix}.installFailed`)
return t(`${i18nPrefix}.installFailed`, { ns: 'plugin' })
return t(`${i18nPrefix}.installPlugin`)
return t(`${i18nPrefix}.installPlugin`, { ns: 'plugin' })
}, [isBundle, step, t])
const { getIconUrl } = useGetIcon()

View File

@ -17,7 +17,7 @@ import checkTaskStatus from '../../base/check-task-status'
import Version from '../../base/version'
import { pluginManifestToCardPluginProps } from '../../utils'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type Props = {
uniqueIdentifier: string
@ -118,7 +118,7 @@ const Installed: FC<Props> = ({
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.readyToInstall`)}</p>
<p>{t(`${i18nPrefix}.readyToInstall`, { ns: 'plugin' })}</p>
<p>
<Trans
i18nKey={`${i18nPrefix}.fromTrustSource`}
@ -127,7 +127,7 @@ const Installed: FC<Props> = ({
</p>
{!isDifyVersionCompatible && (
<p className="system-md-regular flex items-center gap-1 text-text-warning">
{t('plugin.difyVersionNotCompatible', { minimalDifyVersion: payload.meta.minimum_dify_version })}
{t('difyVersionNotCompatible', { ns: 'plugin', minimalDifyVersion: payload.meta.minimum_dify_version })}
</p>
)}
</div>
@ -149,7 +149,7 @@ const Installed: FC<Props> = ({
<div className="flex items-center justify-end gap-2 self-stretch p-6 pt-5">
{!isInstalling && (
<Button variant="secondary" className="min-w-[72px]" onClick={handleCancel}>
{t('common.operation.cancel')}
{t('operation.cancel', { ns: 'common' })}
</Button>
)}
<Button
@ -159,7 +159,7 @@ const Installed: FC<Props> = ({
onClick={handleInstall}
>
{isInstalling && <RiLoader2Line className="h-4 w-4 animate-spin-slow" />}
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`, { ns: 'plugin' })}</span>
</Button>
</div>
</>

View File

@ -8,7 +8,7 @@ import Button from '@/app/components/base/button'
import { uploadFile } from '@/service/plugins'
import Card from '../../../card'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type Props = {
isBundle: boolean
@ -64,6 +64,7 @@ const Uploading: FC<Props> = ({
<RiLoader2Line className="h-4 w-4 animate-spin-slow text-text-accent" />
<div className="system-md-regular text-text-secondary">
{t(`${i18nPrefix}.uploadingPackage`, {
ns: 'plugin',
packageName: fileName,
})}
</div>
@ -82,14 +83,14 @@ const Uploading: FC<Props> = ({
{/* Action Buttons */}
<div className="flex items-center justify-end gap-2 self-stretch p-6 pt-5">
<Button variant="secondary" className="min-w-[72px]" onClick={onCancel}>
{t('common.operation.cancel')}
{t('operation.cancel', { ns: 'common' })}
</Button>
<Button
variant="primary"
className="min-w-[72px]"
disabled
>
{t(`${i18nPrefix}.install`)}
{t(`${i18nPrefix}.install`, { ns: 'plugin' })}
</Button>
</div>
</>

View File

@ -13,7 +13,7 @@ import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
import ReadyToInstallBundle from '../install-bundle/ready-to-install'
import Install from './steps/install'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type InstallFromMarketplaceProps = {
uniqueIdentifier: string
@ -47,12 +47,12 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
const getTitle = useCallback(() => {
if (isBundle && step === InstallStep.installed)
return t(`${i18nPrefix}.installComplete`)
return t(`${i18nPrefix}.installComplete`, { ns: 'plugin' })
if (step === InstallStep.installed)
return t(`${i18nPrefix}.installedSuccessfully`)
return t(`${i18nPrefix}.installedSuccessfully`, { ns: 'plugin' })
if (step === InstallStep.installFailed)
return t(`${i18nPrefix}.installFailed`)
return t(`${i18nPrefix}.installPlugin`)
return t(`${i18nPrefix}.installFailed`, { ns: 'plugin' })
return t(`${i18nPrefix}.installPlugin`, { ns: 'plugin' })
}, [isBundle, step, t])
const handleInstalled = useCallback((notRefresh?: boolean) => {

View File

@ -18,7 +18,7 @@ import Version from '../../base/version'
import useInstallPluginLimit from '../../hooks/use-install-plugin-limit'
import { pluginManifestInMarketToPluginProps } from '../../utils'
const i18nPrefix = 'plugin.installModal'
const i18nPrefix = 'installModal'
type Props = {
uniqueIdentifier: string
@ -134,10 +134,10 @@ const Installed: FC<Props> = ({
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.readyToInstall`)}</p>
<p>{t(`${i18nPrefix}.readyToInstall`, { ns: 'plugin' })}</p>
{!isDifyVersionCompatible && (
<p className="system-md-regular text-text-warning">
{t('plugin.difyVersionNotCompatible', { minimalDifyVersion: pluginDeclaration?.manifest.meta.minimum_dify_version })}
{t('difyVersionNotCompatible', { ns: 'plugin', minimalDifyVersion: pluginDeclaration?.manifest.meta.minimum_dify_version })}
</p>
)}
</div>
@ -160,7 +160,7 @@ const Installed: FC<Props> = ({
<div className="flex items-center justify-end gap-2 self-stretch p-6 pt-5">
{!isInstalling && (
<Button variant="secondary" className="min-w-[72px]" onClick={handleCancel}>
{t('common.operation.cancel')}
{t('operation.cancel', { ns: 'common' })}
</Button>
)}
<Button
@ -170,7 +170,7 @@ const Installed: FC<Props> = ({
onClick={handleInstall}
>
{isInstalling && <RiLoader2Line className="h-4 w-4 animate-spin-slow" />}
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`, { ns: 'plugin' })}</span>
</Button>
</div>
</>