*
* @return array
*/
- public static function getAvailableLanguages(): array
+ public function getAvailableLanguages(bool $additional = false): array
{
$langs = [];
$strings_file_paths = glob('view/lang/*/strings.php');
$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 Portuguese, Ukrainian and Welsh are added to that list.
+ $langs = array_merge(['cy' => 'Cymraeg', 'uk' => 'Українська', 'pt-PT' => 'Português', 'fa' => 'فارسی'], $langs);
+ ksort($langs);
+ }
}
return $langs;
}
+ /**
+ * The language detection routine uses some slightly different language codes.
+ * This function changes the language language codes accordingly.
+ *
+ * @param array $languages
+ * @return array
+ */
+ public function convertForLanguageDetection(array $languages): array
+ {
+ $languages['fi'] = $languages['fi-fi'];
+ unset($languages['fi-fi']);
+ $languages['da'] = $languages['da-dk'];
+ unset($languages['da-dk']);
+ $languages['nb'] = $languages['nb-no'];
+ unset($languages['nb-no']);
+ $languages['pt-BR'] = $languages['pt-br'];
+ unset($languages['pt-br']);
+ $languages['zh-Hans'] = $languages['zh-cn'];
+ $languages['zh-Hant'] = $languages['zh-cn'];
+ unset($languages['zh-cn']);
+
+ ksort($languages);
+
+ return $languages;
+ }
+
/**
* Translate days and months names.
*
$naked_body = self::getDominantLanguage($naked_body);
- $availableLanguages = DI::l10n()->getAvailableLanguages();
- // 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.
- $availableLanguages['fa'] = 'fa';
+ $availableLanguages = DI::l10n()->getAvailableLanguages(true);
+ $availableLanguages = DI::l10n()->convertForLanguageDetection($availableLanguages);
$ld = new Language(array_keys($availableLanguages));
return $ld->detect($naked_body)->limit(0, $count)->close() ?: [];
public static function getLanguageCode(int $uid, bool $short): string
{
$owner = self::getOwnerDataById($uid);
- $languages = DI::l10n()->getAvailableLanguages();
+ $languages = DI::l10n()->getAvailableLanguages($short);
if (in_array($owner['language'], array_keys($languages))) {
$language = $owner['language'];
} else {
$language = DI::config()->get('system', 'language');
}
- if ($short) {
- return substr($language, 0, 2);
- }
return $language;
}
];
$channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid, false)]);
- $languages = $this->l10n->getAvailableLanguages();
+ $languages = $this->l10n->getAvailableLanguages(true);
$first_day_of_week = $this->pConfig->get($uid, 'calendar', 'first_day_of_week', 0);
$weekdays = [