refactor: duplicate logic

This commit is contained in:
Stephen Zhou
2025-03-29 11:16:02 +08:00
parent 3c69d6c13f
commit d9c7c629bd
@@ -8,6 +8,10 @@ import type { FlatEntryModel } from "~/store/entry"
import { apiClient } from "./api-fetch"
function duplicateIfLengthLessThan(text: string, length: number) {
return text.length < length ? text.repeat(Math.ceil(length / text.length)) : text
}
export const checkLanguage = ({
content,
language,
@@ -24,17 +28,10 @@ export const checkLanguage = ({
return false
}
let sourceLanguage = franc(pureContent, {
const sourceLanguage = franc(duplicateIfLengthLessThan(pureContent, 20), {
only: [code],
})
if (sourceLanguage === "und") {
// undetermined, let's try again by duplicating the content
sourceLanguage = franc(pureContent + pureContent, {
only: [code],
})
}
return sourceLanguage === code
}