Qual: Correct language detection in moderation workflow (#38681)
# Qual: Correct language detection in moderation workflow Fix "TypeError: franc is not a function" - Converting language detection to an async function - Adding Scottish language detection (locally, an English sentence was detected as Scottish) Co-authored-by: Alexandre SPANGARO <alexandre.spangaro@gmail.com>
This commit is contained in:
parent
08997e0ea2
commit
c72056ae34
1 changed files with 10 additions and 7 deletions
17
.github/workflows/moderation.yml
vendored
17
.github/workflows/moderation.yml
vendored
|
|
@ -41,14 +41,17 @@ jobs:
|
|||
const isProfane = profanityList.some(word => new RegExp(`\\b${word}\\b`, 'i').test(comment))
|
||||
const isOffTopic = offTopicKeywords.some(kw => comment.toLowerCase().includes(kw.toLowerCase()))
|
||||
|
||||
let isEnglish = true
|
||||
try {
|
||||
const franc = require('franc')
|
||||
const lang = franc(comment)
|
||||
isEnglish = lang && lang.startsWith('eng')
|
||||
} catch (e) {
|
||||
console.log('Language detection failed:', e)
|
||||
async function isEnglishFunc(text) {
|
||||
try {
|
||||
const { franc } = await import('franc');
|
||||
const lang = franc(text);
|
||||
return lang.startsWith('eng') || lang.startsWith('sco');
|
||||
} catch (e) {
|
||||
console.log('Language detection failed:', e)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let isEnglish = await isEnglishFunc(comment)
|
||||
|
||||
if ((isForbidden || isProfane || isOffTopic || !isEnglish) && !isOwner) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue