From c72056ae34eb4a608cb559d6c95407ae2e3b30e6 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 11 Jun 2026 09:34:27 +0200 Subject: [PATCH] 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 --- .github/workflows/moderation.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/moderation.yml b/.github/workflows/moderation.yml index 3823831a13e..69f2c31d2f1 100644 --- a/.github/workflows/moderation.yml +++ b/.github/workflows/moderation.yml @@ -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 {