fix: correct French translation language detection

This commit is contained in:
DIYgod
2026-04-07 16:52:55 +08:00
parent 75f0bf888f
commit 4b07fefdcd
2 changed files with 28 additions and 1 deletions
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest"
import { checkLanguage } from "./language"
describe("checkLanguage", () => {
it("does not treat English text as French", () => {
expect(
checkLanguage({
content: "This is a short English summary about AI and mobile apps.",
language: "fr-FR",
}),
).toBe(false)
})
it("recognizes French text when French is the target language", () => {
expect(
checkLanguage({
content: "Ceci est un resume en francais sur les applications mobiles et l'IA.",
language: "fr-FR",
}),
).toBe(true)
})
})
+5 -1
View File
@@ -5,6 +5,10 @@ import { franc } from "franc-min"
import { parseHtml } from "./html"
import { duplicateIfLengthLessThan } from "./utils"
const detectableLanguageCodes = Object.values(ACTION_LANGUAGE_MAP).flatMap(({ code }) =>
code ? [code] : [],
)
export const checkLanguage = ({
content,
language,
@@ -22,7 +26,7 @@ export const checkLanguage = ({
}
const sourceLanguage = franc(duplicateIfLengthLessThan(pureContent, 20), {
only: [code],
only: detectableLanguageCodes,
})
return sourceLanguage === code