X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FL10n.php;h=414d578fca8be8aa906347b7235c117b1f8b804f;hb=c4870a16d4ffbd37d6c4f379abfe2d18cacb88ff;hp=3f74a408496299d3b1be0059a7c548ccd46efec3;hpb=4e4eab7548c6c7bb7f096beb39419fef276af500;p=friendica.git diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 3f74a40849..414d578fca 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -334,7 +334,7 @@ class L10n // for some languages there is only a single array item $s = $t[0]; } - // if $t is empty, skip it, because empty strings array are indended + // if $t is empty, skip it, because empty strings array are intended // to make string file smaller when there's no translation } else { $s = $t; @@ -378,7 +378,7 @@ class L10n * * @return array */ - public static function getAvailableLanguages(): array + public function getAvailableLanguages(bool $additional = false): array { $langs = []; $strings_file_paths = glob('view/lang/*/strings.php'); @@ -392,10 +392,109 @@ class L10n $path_array = explode('/', $strings_file_path); $langs[$path_array[2]] = self::LANG_NAMES[$path_array[2]] ?? $path_array[2]; } + + if ($additional) { + // See https://github.com/friendica/friendica/issues/10511 + // Persian is manually added to language detection until a persian translation is provided for the interface, at + // which point it will be automatically available through `getAvailableLanguages()` and this should be removed. + // Additionally some more languages are added to that list that are used in the Fediverse. + $additional_langs = [ + 'af' => 'Afrikaans', + 'az-Latn' => 'azərbaycan dili', + 'bs-Latn' => 'bosanski jezik', + 'be' => 'беларуская мова', + 'bn' => 'বাংলা', + 'cy' => 'Cymraeg', + 'el-monoton' => 'Ελληνικά', + 'eu' => 'euskara', + 'fa' => 'فارسی', + 'ga' => 'Gaeilge', + 'gl' => 'Galego', + 'he' => 'עברית', + 'hi' => 'हिन्दी', + 'hr' => 'Hrvatski', + 'hy' => 'Հայերեն', + 'id' => 'bahasa Indonesia', + 'jv' => 'Basa Jawa', + 'ka' => 'ქართული', + 'ko' => '한국인', + 'lt' => 'lietuvių', + 'lv' => 'latviešu', + 'ms-Latn' => 'Bahasa Melayu', + 'sr-Cyrl' => 'српски језик', + 'sk' => 'slovenský', + 'sl' => 'Slovenščina', + 'sq' => 'Shqip', + 'sw' => 'Kiswahili', + 'ta' => 'தமிழ்', + 'th' => 'แบบไทย', + 'tl' => 'Wikang Tagalog', + 'tr' => 'Türkçe', + 'pt-PT' => 'Português', + 'uk' => 'Українська', + 'uz' => 'Ўзбек', + 'vi' => 'Tiếng Việt', + 'zh-hant' => '繁體', + ]; + $langs = array_merge($additional_langs, $langs); + ksort($langs); + } } return $langs; } + /** + * The language detection routine uses some slightly different language codes. + * This function changes the language array accordingly. + * + * @param array $languages + * @return array + */ + public function convertForLanguageDetection(array $languages): array + { + foreach ($languages as $key => $language) { + $newkey = $this->convertCodeForLanguageDetection($key); + if ($newkey != $key) { + if (!isset($languages[$newkey])) { + $languages[$newkey] = $language; + } + unset($languages[$key]); + } + } + + ksort($languages); + + return $languages; + } + + /** + * The language detection routine uses some slightly different language codes. + * This function changes the language codes accordingly. + * + * @param string $language + * @return string + */ + public function convertCodeForLanguageDetection(string $language): string + { + switch ($language) { + case 'da-dk': + return 'da'; + case 'en-us': + case 'en-gb': + return 'en'; + case 'fi-fi': + return 'fi'; + case 'nb-no': + return 'nb'; + case 'pt-br': + return 'pt-BR'; + case 'zh-cn': + return 'zh-Hans'; + default: + return $language; + } + } + /** * Translate days and months names. *