]> git.mxchange.org Git - friendica.git/commitdiff
Improved handling of undetected languages
authorMichael <heluecht@pirati.ca>
Sun, 7 Jan 2024 12:45:08 +0000 (12:45 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 28 Jan 2024 15:37:08 +0000 (16:37 +0100)
src/Model/Item.php
src/Protocol/Relay.php

index a672f5b174791aa7af0d61f6446bd45eb4188812..4c7f0d24fa1e9ea0be9ee16d024d558660d27eeb 100644 (file)
@@ -2071,10 +2071,7 @@ class Item
                        return !empty($transmitted) ? json_encode($transmitted) : null;
                }
 
-               $languages = self::getLanguageArray($content, 3, $item['uri-id'], $item['author-id']);
-               if (empty($languages)) {
-                       return !empty($transmitted) ? json_encode($transmitted) : null;
-               }
+               $languages = self::getLanguageArray($content, 3, $item['uri-id'], $item['author-id'], $transmitted);
 
                if (!empty($transmitted)) {
                        $languages = array_merge($transmitted, $languages);
@@ -2091,9 +2088,10 @@ class Item
         * @param integer $count
         * @param integer $uri_id
         * @param integer $author_id
+        * @param array   $default
         * @return array
         */
-       public static function getLanguageArray(string $body, int $count, int $uri_id = 0, int $author_id = 0): array
+       public static function getLanguageArray(string $body, int $count, int $uri_id = 0, int $author_id = 0, array $default = ['un' => 1]): array
        {
                $searchtext = BBCode::toSearchText($body, $uri_id);
 
@@ -2107,7 +2105,7 @@ class Item
                }
 
                if (empty($searchtext)) {
-                       return ['un' => 1];
+                       return $default;
                }
 
                $ld = new Language(DI::l10n()->getDetectableLanguages());
@@ -2131,7 +2129,7 @@ class Item
                }
 
                if (empty($result)) {
-                       return ['un' => 1];
+                       return $default;
                }
 
                $result = self::compactLanguages($result);
index 1b9c7a0563d2debca1980bcfece90fe9fc7218a3..ae0ad949d043d059305d8915b3f1a627c0c53414 100644 (file)
@@ -188,7 +188,7 @@ class Relay
                        }
                }
 
-               if (empty($detected)) {
+               if (empty($detected) && empty($languages)) {
                        $detected = ['un'];
                }