mirror of https://github.com/langgenius/dify.git
fix: remove api reference doc link en prefix (#31910)
This commit is contained in:
parent
64e769f96e
commit
468990cc39
|
|
@ -196,19 +196,19 @@ describe('useDocLink', () => {
|
||||||
|
|
||||||
const { result } = renderHook(() => useDocLink())
|
const { result } = renderHook(() => useDocLink())
|
||||||
const url = result.current('/api-reference/annotations/create-annotation')
|
const url = result.current('/api-reference/annotations/create-annotation')
|
||||||
expect(url).toBe(`${defaultDocBaseUrl}/en/api-reference/annotations/create-annotation`)
|
expect(url).toBe(`${defaultDocBaseUrl}/api-reference/annotations/create-annotation`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should keep original path when no translation exists for non-English locale', () => {
|
it('should keep original path when no translation exists for non-English locale', () => {
|
||||||
vi.mocked(useTranslation).mockReturnValue({
|
vi.mocked(useTranslation).mockReturnValue({
|
||||||
i18n: { language: 'ja-JP' },
|
i18n: { language: 'zh-Hans' },
|
||||||
} as ReturnType<typeof useTranslation>)
|
} as ReturnType<typeof useTranslation>)
|
||||||
vi.mocked(getDocLanguage).mockReturnValue('ja')
|
vi.mocked(getDocLanguage).mockReturnValue('zh')
|
||||||
|
|
||||||
const { result } = renderHook(() => useDocLink())
|
const { result } = renderHook(() => useDocLink())
|
||||||
// This path has no Japanese translation
|
// This path has no Japanese translation
|
||||||
const url = result.current('/api-reference/annotations/create-annotation')
|
const url = result.current('/api-reference/annotations/create-annotation')
|
||||||
expect(url).toBe(`${defaultDocBaseUrl}/ja/api-reference/annotations/create-annotation`)
|
expect(url).toBe(`${defaultDocBaseUrl}/api-reference/标注管理/创建标注`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove language prefix when translation is applied', () => {
|
it('should remove language prefix when translation is applied', () => {
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,13 @@ export const useDocLink = (baseUrl?: string): ((path?: DocPathWithoutLang, pathM
|
||||||
let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl
|
let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl
|
||||||
let languagePrefix = `/${docLanguage}`
|
let languagePrefix = `/${docLanguage}`
|
||||||
|
|
||||||
// Translate API reference paths for non-English locales
|
if (targetPath.startsWith('/api-reference/')) {
|
||||||
if (targetPath.startsWith('/api-reference/') && docLanguage !== 'en') {
|
languagePrefix = ''
|
||||||
const translatedPath = apiReferencePathTranslations[targetPath]?.[docLanguage as 'zh' | 'ja']
|
if (docLanguage !== 'en') {
|
||||||
if (translatedPath) {
|
const translatedPath = apiReferencePathTranslations[targetPath]?.[docLanguage]
|
||||||
targetPath = translatedPath
|
if (translatedPath) {
|
||||||
languagePrefix = ''
|
targetPath = translatedPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue