mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 21:57:23 +08:00
fix(i18n): add functions to retrieve document and pricing page languages (#19142)
This commit is contained in:
parent
d5ee465bf9
commit
3dff21e0be
@ -15,6 +15,7 @@ import { useProviderContext } from '@/context/provider-context'
|
|||||||
import GridMask from '@/app/components/base/grid-mask'
|
import GridMask from '@/app/components/base/grid-mask'
|
||||||
import { useAppContext } from '@/context/app-context'
|
import { useAppContext } from '@/context/app-context'
|
||||||
import classNames from '@/utils/classnames'
|
import classNames from '@/utils/classnames'
|
||||||
|
import { useGetPricingPageLanguage } from '@/context/i18n'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
@ -33,6 +34,11 @@ const Pricing: FC<Props> = ({
|
|||||||
|
|
||||||
useKeyPress(['esc'], onCancel)
|
useKeyPress(['esc'], onCancel)
|
||||||
|
|
||||||
|
const pricingPageLanguage = useGetPricingPageLanguage()
|
||||||
|
const pricingPageURL = pricingPageLanguage
|
||||||
|
? `https://dify.ai/${pricingPageLanguage}/pricing#plans-and-features`
|
||||||
|
: 'https://dify.ai/pricing#plans-and-features'
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<div
|
<div
|
||||||
className='fixed inset-0 bottom-0 left-0 right-0 top-0 z-[1000] bg-background-overlay-backdrop p-4 backdrop-blur-[6px]'
|
className='fixed inset-0 bottom-0 left-0 right-0 top-0 z-[1000] bg-background-overlay-backdrop p-4 backdrop-blur-[6px]'
|
||||||
@ -127,7 +133,7 @@ const Pricing: FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className='flex items-center justify-center py-4'>
|
<div className='flex items-center justify-center py-4'>
|
||||||
<div className='flex items-center justify-center gap-x-0.5 rounded-lg px-3 py-2 text-components-button-secondary-accent-text hover:cursor-pointer hover:bg-state-accent-hover'>
|
<div className='flex items-center justify-center gap-x-0.5 rounded-lg px-3 py-2 text-components-button-secondary-accent-text hover:cursor-pointer hover:bg-state-accent-hover'>
|
||||||
<Link href='https://dify.ai/pricing#plans-and-features' className='system-sm-medium'>{t('billing.plansCommon.comparePlanAndFeatures')}</Link>
|
<Link href={pricingPageURL} className='system-sm-medium'>{t('billing.plansCommon.comparePlanAndFeatures')}</Link>
|
||||||
<RiArrowRightUpLine className='size-4' />
|
<RiArrowRightUpLine className='size-4' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Fragment, useState } from 'react'
|
import { Fragment, useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { useContext, useContextSelector } from 'use-context-selector'
|
import { useContextSelector } from 'use-context-selector'
|
||||||
import {
|
import {
|
||||||
RiAccountCircleLine,
|
RiAccountCircleLine,
|
||||||
RiArrowRightUpLine,
|
RiArrowRightUpLine,
|
||||||
@ -23,13 +23,12 @@ import GithubStar from '../github-star'
|
|||||||
import Support from './support'
|
import Support from './support'
|
||||||
import Compliance from './compliance'
|
import Compliance from './compliance'
|
||||||
import PremiumBadge from '@/app/components/base/premium-badge'
|
import PremiumBadge from '@/app/components/base/premium-badge'
|
||||||
import I18n from '@/context/i18n'
|
import { useGetDocLanguage } from '@/context/i18n'
|
||||||
import Avatar from '@/app/components/base/avatar'
|
import Avatar from '@/app/components/base/avatar'
|
||||||
import { logout } from '@/service/common'
|
import { logout } from '@/service/common'
|
||||||
import AppContext, { useAppContext } from '@/context/app-context'
|
import AppContext, { useAppContext } from '@/context/app-context'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
import { useModalContext } from '@/context/modal-context'
|
import { useModalContext } from '@/context/modal-context'
|
||||||
import { LanguagesSupported } from '@/i18n/language'
|
|
||||||
import { LicenseStatus } from '@/types/feature'
|
import { LicenseStatus } from '@/types/feature'
|
||||||
import { IS_CLOUD_EDITION } from '@/config'
|
import { IS_CLOUD_EDITION } from '@/config'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
@ -43,11 +42,11 @@ export default function AppSelector() {
|
|||||||
const [aboutVisible, setAboutVisible] = useState(false)
|
const [aboutVisible, setAboutVisible] = useState(false)
|
||||||
const systemFeatures = useContextSelector(AppContext, v => v.systemFeatures)
|
const systemFeatures = useContextSelector(AppContext, v => v.systemFeatures)
|
||||||
|
|
||||||
const { locale } = useContext(I18n)
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { userProfile, langeniusVersionInfo, isCurrentWorkspaceOwner } = useAppContext()
|
const { userProfile, langeniusVersionInfo, isCurrentWorkspaceOwner } = useAppContext()
|
||||||
const { isEducationAccount } = useProviderContext()
|
const { isEducationAccount } = useProviderContext()
|
||||||
const { setShowAccountSettingModal } = useModalContext()
|
const { setShowAccountSettingModal } = useModalContext()
|
||||||
|
const docLanguage = useGetDocLanguage()
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await logout({
|
await logout({
|
||||||
@ -132,9 +131,7 @@ export default function AppSelector() {
|
|||||||
className={cn(itemClassName, 'group justify-between',
|
className={cn(itemClassName, 'group justify-between',
|
||||||
'data-[active]:bg-state-base-hover',
|
'data-[active]:bg-state-base-hover',
|
||||||
)}
|
)}
|
||||||
href={
|
href={`https://docs.dify.ai/${docLanguage}/introduction`}
|
||||||
locale !== LanguagesSupported[1] ? 'https://docs.dify.ai/' : `https://docs.dify.ai/v/${locale.toLowerCase()}/`
|
|
||||||
}
|
|
||||||
target='_blank' rel='noopener noreferrer'>
|
target='_blank' rel='noopener noreferrer'>
|
||||||
<RiBookOpenLine className='size-4 shrink-0 text-text-tertiary' />
|
<RiBookOpenLine className='size-4 shrink-0 text-text-tertiary' />
|
||||||
<div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.helpCenter')}</div>
|
<div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.helpCenter')}</div>
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
useContext,
|
useContext,
|
||||||
} from 'use-context-selector'
|
} from 'use-context-selector'
|
||||||
import type { Locale } from '@/i18n'
|
import type { Locale } from '@/i18n'
|
||||||
import { getLanguage } from '@/i18n/language'
|
import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n/language'
|
||||||
import { noop } from 'lodash-es'
|
import { noop } from 'lodash-es'
|
||||||
|
|
||||||
type II18NContext = {
|
type II18NContext = {
|
||||||
@ -24,5 +24,15 @@ export const useGetLanguage = () => {
|
|||||||
|
|
||||||
return getLanguage(locale)
|
return getLanguage(locale)
|
||||||
}
|
}
|
||||||
|
export const useGetDocLanguage = () => {
|
||||||
|
const { locale } = useI18N()
|
||||||
|
|
||||||
|
return getDocLanguage(locale)
|
||||||
|
}
|
||||||
|
export const useGetPricingPageLanguage = () => {
|
||||||
|
const { locale } = useI18N()
|
||||||
|
|
||||||
|
return getPricingPageLanguage(locale)
|
||||||
|
}
|
||||||
|
|
||||||
export default I18NContext
|
export default I18NContext
|
||||||
|
@ -39,6 +39,24 @@ export const getLanguage = (locale: string) => {
|
|||||||
return LanguagesSupported[0].replace('-', '_')
|
return LanguagesSupported[0].replace('-', '_')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DOC_LANGUAGE: Record<string, string> = {
|
||||||
|
'zh-Hans': 'zh-hans',
|
||||||
|
'ja-JP': 'ja-jp',
|
||||||
|
'en-US': 'en',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getDocLanguage = (locale: string) => {
|
||||||
|
return DOC_LANGUAGE[locale] || 'en'
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRICING_PAGE_LANGUAGE: Record<string, string> = {
|
||||||
|
'ja-JP': 'jp',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getPricingPageLanguage = (locale: string) => {
|
||||||
|
return PRICING_PAGE_LANGUAGE[locale] || ''
|
||||||
|
}
|
||||||
|
|
||||||
export const NOTICE_I18N = {
|
export const NOTICE_I18N = {
|
||||||
title: {
|
title: {
|
||||||
en_US: 'Important Notice',
|
en_US: 'Important Notice',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user