feat: merge i18n

This commit is contained in:
Joel
2024-02-23 15:18:48 +08:00
287 changed files with 5299 additions and 6617 deletions

View File

@ -10,7 +10,7 @@ import { updateUserProfile } from '@/service/common'
import { ToastContext } from '@/app/components/base/toast'
import I18n from '@/context/i18n'
import { timezones } from '@/utils/timezone'
import { languages } from '@/utils/language'
import { languages } from '@/i18n/language'
const titleClassName = `
mb-2 text-sm font-medium text-gray-900
@ -53,7 +53,7 @@ export default function LanguagePage() {
<div className={titleClassName}>{t('common.language.displayLanguage')}</div>
<SimpleSelect
defaultValue={locale || userProfile.interface_language}
items={languages}
items={languages.filter(item => item.supported)}
onSelect={item => handleSelect('language', item)}
disabled={editing}
/>

View File

@ -20,7 +20,7 @@ import { useProviderContext } from '@/context/provider-context'
import { Plan } from '@/app/components/billing/type'
import UpgradeBtn from '@/app/components/billing/upgrade-btn'
import { NUM_INFINITE } from '@/app/components/billing/config'
import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language'
import { LanguagesSupported } from '@/i18n/language'
dayjs.extend(relativeTime)
const MembersPage = () => {
@ -31,7 +31,7 @@ const MembersPage = () => {
normal: t('common.members.normal'),
}
const { locale } = useContext(I18n)
const language = getModelRuntimeSupported(locale)
const { userProfile, currentWorkspace, isCurrentWorkspaceManager } = useAppContext()
const { data, mutate } = useSWR({ url: '/workspaces/current/members' }, fetchMembers)
const [inviteModalVisible, setInviteModalVisible] = useState(false)
@ -55,7 +55,7 @@ const MembersPage = () => {
{isNotUnlimitedMemberPlan
? (
<div className='flex space-x-1'>
<div>{t('billing.plansCommon.member')}{language !== LanguagesSupportedUnderscore[1] && accounts.length > 1 && 's'}</div>
<div>{t('billing.plansCommon.member')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}</div>
<div className='text-gray-700'>{accounts.length}</div>
<div>/</div>
<div>{plan.total.teamMembers === NUM_INFINITE ? t('billing.plansCommon.unlimited') : plan.total.teamMembers}</div>
@ -64,7 +64,7 @@ const MembersPage = () => {
: (
<div className='flex space-x-1'>
<div>{accounts.length}</div>
<div>{t('billing.plansCommon.memberAfter')}{language !== LanguagesSupportedUnderscore[1] && accounts.length > 1 && 's'}</div>
<div>{t('billing.plansCommon.memberAfter')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}</div>
</div>
)}
</div>

View File

@ -15,7 +15,6 @@ import { emailRegex } from '@/config'
import { ToastContext } from '@/app/components/base/toast'
import type { InvitationResult } from '@/models/common'
import I18n from '@/context/i18n'
import { getModelRuntimeSupported } from '@/utils/language'
import 'react-multi-email/dist/style.css'
type IInviteModalProps = {
@ -32,7 +31,6 @@ const InviteModal = ({
const { notify } = useContext(ToastContext)
const { locale } = useContext(I18n)
const language = getModelRuntimeSupported(locale)
const InvitingRoles = useMemo(() => [
{
@ -51,7 +49,7 @@ const InviteModal = ({
try {
const { result, invitation_results } = await inviteMember({
url: '/workspaces/current/members/invite-email',
body: { emails, role: role.name, language },
body: { emails, role: role.name, language: locale },
})
if (result === 'success') {

View File

@ -1,8 +1,8 @@
export type FormValue = Record<string, any>
export type TypeWithI18N<T = string> = {
'en_US': T
'zh_Hans': T
'en-US': T
'zh-Hans': T
[key: string]: T
}
@ -67,16 +67,16 @@ export enum ModelStatusEnum {
export const MODEL_STATUS_TEXT: { [k: string]: TypeWithI18N } = {
'no-configure': {
en_US: 'No Configure',
zh_Hans: '未配置凭据',
'en-US': 'No Configure',
'zh-Hans': '未配置凭据',
},
'quota-exceeded': {
en_US: 'Quota Exceeded',
zh_Hans: '额度不足',
'en-US': 'Quota Exceeded',
'zh-Hans': '额度不足',
},
'no-permission': {
en_US: 'No Permission',
zh_Hans: '无使用权限',
'en-US': 'No Permission',
'zh-Hans': '无使用权限',
},
}

View File

@ -16,7 +16,6 @@ import {
ConfigurateMethodEnum,
ModelTypeEnum,
} from './declarations'
import { getModelRuntimeSupported } from '@/utils/language'
import I18n from '@/context/i18n'
import {
fetchDefaultModal,
@ -59,7 +58,7 @@ export const useSystemDefaultModelAndModelList: UseDefaultModelAndModelList = (
export const useLanguage = () => {
const { locale } = useContext(I18n)
return getModelRuntimeSupported(locale)
return locale.replace('-', '_')
}
export const useProviderCrenditialsFormSchemasValue = (

View File

@ -17,6 +17,7 @@ import Input from './Input'
import { SimpleSelect } from '@/app/components/base/select'
import Tooltip from '@/app/components/base/tooltip-plus'
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
import Radio from '@/app/components/base/radio'
type FormProps = {
value: FormValue
onChange: (val: FormValue) => void
@ -47,7 +48,7 @@ const Form: FC<FormProps> = ({
const language = useLanguage()
const [changeKey, setChangeKey] = useState('')
const handleFormChange = (key: string, val: string) => {
const handleFormChange = (key: string, val: string | boolean) => {
if (isEditMode && (key === '__model_type' || key === '__model_name'))
return
@ -214,6 +215,37 @@ const Form: FC<FormProps> = ({
</div>
)
}
if (formSchema.type === 'boolean') {
const {
variable,
label,
show_on,
} = formSchema as CredentialFormSchemaRadio
if (show_on.length && !show_on.every(showOnItem => value[showOnItem.variable] === showOnItem.value))
return null
return (
<div key={variable} className='py-3'>
<div className='flex items-center justify-between py-2 text-sm text-gray-900'>
<div className='flex items-center space-x-2'>
<span>{label[language]}</span>
{tooltipContent}
</div>
<Radio.Group
className='flex items-center'
value={value[variable] ? 1 : 0}
onChange={val => handleFormChange(variable, val === 1)}
>
<Radio value={1} className='!mr-1'>True</Radio>
<Radio value={0}>False</Radio>
</Radio.Group>
</div>
{fieldMoreInfo?.(formSchema)}
</div>
)
}
}
return (