2025-12-30 06:38:23 +00:00
|
|
|
import type { Locale } from '@/i18n-config/language'
|
|
|
|
|
import { atom, useAtomValue } from 'jotai'
|
2025-07-25 07:01:28 +00:00
|
|
|
import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n-config/language'
|
2023-05-15 00:51:32 +00:00
|
|
|
|
2025-12-30 06:38:23 +00:00
|
|
|
export const localeAtom = atom<Locale>('en-US')
|
|
|
|
|
export const useLocale = () => {
|
|
|
|
|
return useAtomValue(localeAtom)
|
2023-05-15 00:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-08 10:51:46 +00:00
|
|
|
export const useGetLanguage = () => {
|
2025-12-30 06:38:23 +00:00
|
|
|
const locale = useLocale()
|
2024-04-08 10:51:46 +00:00
|
|
|
|
|
|
|
|
return getLanguage(locale)
|
|
|
|
|
}
|
2025-04-30 06:58:49 +00:00
|
|
|
export const useGetPricingPageLanguage = () => {
|
2025-12-30 06:38:23 +00:00
|
|
|
const locale = useLocale()
|
2025-04-30 06:58:49 +00:00
|
|
|
|
|
|
|
|
return getPricingPageLanguage(locale)
|
|
|
|
|
}
|
2024-04-08 10:51:46 +00:00
|
|
|
|
2025-08-28 13:13:18 +00:00
|
|
|
export const defaultDocBaseUrl = 'https://docs.dify.ai'
|
2025-06-13 08:58:43 +00:00
|
|
|
export const useDocLink = (baseUrl?: string): ((path?: string, pathMap?: { [index: string]: string }) => string) => {
|
2025-06-16 06:13:04 +00:00
|
|
|
let baseDocUrl = baseUrl || defaultDocBaseUrl
|
|
|
|
|
baseDocUrl = (baseDocUrl.endsWith('/')) ? baseDocUrl.slice(0, -1) : baseDocUrl
|
2025-12-30 06:38:23 +00:00
|
|
|
const locale = useLocale()
|
2025-06-16 06:13:04 +00:00
|
|
|
const docLanguage = getDocLanguage(locale)
|
|
|
|
|
return (path?: string, pathMap?: { [index: string]: string }): string => {
|
|
|
|
|
const pathUrl = path || ''
|
|
|
|
|
let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl
|
|
|
|
|
targetPath = (targetPath.startsWith('/')) ? targetPath.slice(1) : targetPath
|
|
|
|
|
return `${baseDocUrl}/${docLanguage}/${targetPath}`
|
|
|
|
|
}
|
2025-06-13 08:58:43 +00:00
|
|
|
}
|