mirror of
https://github.com/langgenius/dify.git
synced 2026-02-25 10:45:21 +00:00
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
Co-authored-by: Riskey <36894937+RiskeyL@users.noreply.github.com>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import type { Locale } from '@/i18n-config/language'
|
|
import type { DocPathWithoutLang } from '@/types/doc-paths'
|
|
import { useTranslation } from '#i18n'
|
|
import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n-config/language'
|
|
import { apiReferencePathTranslations } from '@/types/doc-paths'
|
|
|
|
export const useLocale = () => {
|
|
const { i18n } = useTranslation()
|
|
return i18n.language as Locale
|
|
}
|
|
|
|
export const useGetLanguage = () => {
|
|
const locale = useLocale()
|
|
|
|
return getLanguage(locale)
|
|
}
|
|
export const useGetPricingPageLanguage = () => {
|
|
const locale = useLocale()
|
|
|
|
return getPricingPageLanguage(locale)
|
|
}
|
|
|
|
export const defaultDocBaseUrl = 'https://docs.dify.ai'
|
|
export type DocPathMap = Partial<Record<Locale, DocPathWithoutLang>>
|
|
|
|
export const useDocLink = (baseUrl?: string): ((path?: DocPathWithoutLang, pathMap?: DocPathMap) => string) => {
|
|
let baseDocUrl = baseUrl || defaultDocBaseUrl
|
|
baseDocUrl = (baseDocUrl.endsWith('/')) ? baseDocUrl.slice(0, -1) : baseDocUrl
|
|
const locale = useLocale()
|
|
const docLanguage = getDocLanguage(locale)
|
|
return (path?: DocPathWithoutLang, pathMap?: DocPathMap): string => {
|
|
const pathUrl = path || ''
|
|
let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl
|
|
let languagePrefix = `/${docLanguage}`
|
|
|
|
// Translate API reference paths for non-English locales
|
|
if (targetPath.startsWith('/api-reference/') && docLanguage !== 'en') {
|
|
const translatedPath = apiReferencePathTranslations[targetPath]?.[docLanguage as 'zh' | 'ja']
|
|
if (translatedPath) {
|
|
targetPath = translatedPath
|
|
languagePrefix = ''
|
|
}
|
|
}
|
|
|
|
return `${baseDocUrl}${languagePrefix}${targetPath}`
|
|
}
|
|
}
|