X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=18b56215ce39ca9a680e64fc062f693c84dca392;hb=58e5f0d9c5ba75f92cc4c77b5b27069789f11318;hp=811eab50b41e17532ab9aaa48019a84f3d38ed2f;hpb=094b219581d4b9e3f8770bf551387f90f9f29a04;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 811eab50b4..18b56215ce 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -117,7 +117,7 @@ class Item const DELIVER_FIELDLIST = [ 'uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'parent-guid', 'conversation', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target', - 'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app', + 'private', 'title', 'body', 'raw-body', 'language', 'location', 'coord', 'app', 'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'author-id', 'author-addr', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid', @@ -1484,6 +1484,10 @@ class Item */ private static function setOwnerforResharedItem(array $item) { + if ($item['uid'] == 0) { + return; + } + $parent = Post::selectFirst( ['id', 'causer-id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-reason'], ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']] @@ -2034,15 +2038,12 @@ class Item return []; } - $availableLanguages = DI::l10n()->getAvailableLanguages(true); - $availableLanguages = DI::l10n()->convertForLanguageDetection($availableLanguages); - - $ld = new Language(array_keys($availableLanguages)); + $ld = new Language(DI::l10n()->getDetectableLanguages()); $result = []; foreach (self::splitByBlocks($searchtext) as $block) { - $languages = $ld->detect($block)->limit(0, $count)->close() ?: []; + $languages = $ld->detect($block)->close() ?: []; $data = [ 'text' => $block, @@ -2057,10 +2058,32 @@ class Item } } + $result = self::compactLanguages($result); + arsort($result); - $result = array_slice($result, 0, $count); + return array_slice($result, 0, $count); + } - return $result; + /** + * Concert the language code in the detection result to ISO 639-1. + * On duplicates the system uses the higher quality value. + * + * @param array $result + * @return array + */ + private static function compactLanguages(array $result): array + { + $languages = []; + foreach ($result as $language => $quality) { + if ($quality == 0) { + continue; + } + $code = DI::l10n()->toISO6391($language); + if (empty($languages[$code]) || ($languages[$code] < $quality)) { + $languages[$code] = $quality; + } + } + return $languages; } /** @@ -2143,7 +2166,15 @@ class Item $used_languages = ''; foreach (json_decode($item['language'], true) as $language => $reliability) { - $used_languages .= $iso639->nativeByCode1(substr($language, 0, 2)) . ' (' . $iso639->languageByCode1(substr($language, 0, 2)) . ' - ' . $language . "): " . number_format($reliability, 5) . '\n'; + $code = DI::l10n()->toISO6391($language); + + $native = $iso639->nativeByCode1($code); + $language = $iso639->languageByCode1($code); + if ($native != $language) { + $used_languages .= DI::l10n()->t('%s (%s - %s): %s', $native, $language, $code, number_format($reliability, 5)) . '\n'; + } else { + $used_languages .= DI::l10n()->t('%s (%s): %s', $native, $code, number_format($reliability, 5)) . '\n'; + } } $used_languages = DI::l10n()->t('Detected languages in this post:\n%s', $used_languages); return $used_languages;