// 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);
+ // Additionally Portuguese, Ukrainian, traditional Chinese and Welsh are added to that list.
+ $langs = array_merge(['cy' => 'Cymraeg', 'uk' => 'Українська', 'pt-PT' => 'Português', 'zh-hant' => '繁體', 'fa' => 'فارسی'], $langs);
ksort($langs);
}
}
/**
* The language detection routine uses some slightly different language codes.
- * This function changes the language language codes accordingly.
+ * This function changes the language array accordingly.
*
* @param array $languages
* @return array
$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;
}
+ /**
+ * 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.
*
/**
* Fetch the language code from the given user. If the code is invalid, return the system language
*
- * @param integer $uid User-Id
- * @param boolean $short If true, return the short form g.g. "en", otherwise the long form e.g. "en-gb"
+ * @param integer $uid User-Id
* @return string
*/
- public static function getLanguageCode(int $uid, bool $short): string
+ public static function getLanguageCode(int $uid): string
{
$owner = self::getOwnerDataById($uid);
- $languages = DI::l10n()->getAvailableLanguages($short);
+ $languages = DI::l10n()->getAvailableLanguages(true);
if (in_array($owner['language'], array_keys($languages))) {
$language = $owner['language'];
} else {
'accesskey' => 'h'
];
- $language = User::getLanguageCode($this->session->getLocalUserId(), false);
- $languages = $this->l10n->getAvailableLanguages();
+ $language = User::getLanguageCode($this->session->getLocalUserId());
+ $languages = $this->l10n->getAvailableLanguages(true);
$tabs[] = [
'label' => $languages[$language],
} elseif (self::$content == self::AUDIO) {
$condition = ["`media-type` & ?", 4];
} elseif (self::$content == self::LANGUAGE) {
- $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", User::getLanguageCode($this->session->getLocalUserId(), true)];
+ $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($this->session->getLocalUserId()))];
}
if (self::$content != self::LANGUAGE) {
private function addLanguageCondition(array $condition): array
{
$conditions = [];
- $languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId(), false)]);
+ $languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]);
+ $languages = $this->l10n->convertForLanguageDetection($languages);
foreach ($languages as $language) {
$conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?";
- $condition[] = substr($language, 0, 2);
+ $condition[] = $language;
}
if (!empty($conditions)) {
$condition[0] .= " AND (`language` IS NULL OR " . implode(' OR ', $conditions) . ")";
BBCode::PREVIEW_LARGE => $this->t('Large Image'),
];
- $channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid, false)]);
+ $channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
$languages = $this->l10n->getAvailableLanguages(true);
$first_day_of_week = $this->pConfig->get($uid, 'calendar', 'first_day_of_week', 0);