"Count" parameter added

This commit is contained in:
Michael Vogel 2022-09-19 12:46:28 +02:00
parent f08b08e0d8
commit 3650feb256
2 changed files with 4 additions and 4 deletions

View file

@ -1870,7 +1870,7 @@ class Item
return '';
}
$languages = self::getLanguageArray(trim($item['title'] . "\n" . $item['body']));
$languages = self::getLanguageArray(trim($item['title'] . "\n" . $item['body']), 3);
if (empty($languages)) {
return '';
}
@ -1878,7 +1878,7 @@ class Item
return json_encode($languages);
}
public static function getLanguageArray(string $body): array
public static function getLanguageArray(string $body, int $count): array
{
// Convert attachments to links
$naked_body = BBCode::removeAttachment($body);
@ -1908,7 +1908,7 @@ class Item
$availableLanguages['fa'] = 'fa';
$ld = new Language(array_keys($availableLanguages));
return $ld->detect($naked_body)->limit(0, 3)->close() ?: [];
return $ld->detect($naked_body)->limit(0, $count)->close() ?: [];
}
/**

View file

@ -129,7 +129,7 @@ class Relay
}
$languages = [];
foreach (Item::getLanguageArray($body) as $language => $reliability) {
foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
if ($reliability > 0) {
$languages[] = $language;
}