Feat/i18n restructure (#2529)

This commit is contained in:
crazywoola 2024-02-23 14:31:06 +08:00 • committed by GitHub
commit 9574730050
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
140 changed files with 448 additions and 659 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 = (