Skip to content

Commit a9cdff1

Browse files
committed
Restore limit translate
1 parent d0a7ba1 commit a9cdff1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎lhc_web/lib/core/lhtranslate/lhtranslate.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ public static function detectChatLanguage(erLhcoreClassModelChat $chat)
127127
return null;
128128
}
129129

130+
// Too short text is not reliable for language detection.
131+
// Proceed only if there are more than 3 words or the text is longer than 20 characters.
132+
$wordCount = count(preg_split('/\s+/u', $messageText, -1, PREG_SPLIT_NO_EMPTY));
133+
134+
if ($wordCount <= 3 && mb_strlen($messageText) <= 20) {
135+
return null;
136+
}
137+
130138
$languageCode = self::detectLanguage(substr($messageText, 0, 500));
131139

132140
if (!is_string($languageCode) || $languageCode === '') {

0 commit comments

Comments
 (0)