Use "toISO6391" instead of "substr"

This commit is contained in:
Michael 2023-11-03 05:32:57 +00:00
parent 90e05fd835
commit a7ab14b3b3
3 changed files with 11 additions and 3 deletions

View file

@ -442,7 +442,7 @@ class L10n
$code = $this->toISO6391($code);
$native = $iso639->nativeByCode1($code);
$language = $iso639->languageByCode1($code);
if ($native != $iso639->languageByCode1($code) && $international) {
if ($native != $language && $international) {
$languages[$code] = $this->t('%s (%s)', $native, $language);
} else {
$languages[$code] = $native;

View file

@ -2162,7 +2162,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;

View file

@ -242,7 +242,7 @@ class Temporal
// First day of the week (0 = Sunday)
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week', 0);
$lang = substr(DI::l10n()->getCurrentLang(), 0, 2);
$lang = DI::l10n()->toISO6391(DI::l10n()->getCurrentLang());
// Check if the detected language is supported by the picker
if (!in_array($lang,