Merge pull request #15451 from marcusxss/link_global_directory_language

Make link from contacts to global directory pass on user language
This commit is contained in:
Michael Vogel 2026-02-12 10:41:08 +01:00 committed by GitHub
commit fb741fbb07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View file

@ -48,6 +48,12 @@ class Widget
*/
public static function findPeople(): string
{
// Langs in friendica are all lowercase and dash separated (e.g. da-dk) - in the directory
// they're underscore separated, with the latter part being uppercase (e.g. da_DK)
$directory_user_lang_string = "";
if (DI::userSession()->get('language')) {
$directory_user_lang_string = "&lang=" . DI::l10n()->langToLocaleCode(DI::userSession()->get('language'));
}
$global_dir = Search::getGlobalDirectory();
if (DI::config()->get('system', 'invitation_only')) {
@ -70,7 +76,7 @@ class Widget
$nv['random'] = DI::l10n()->t('Random Profile');
$nv['inv'] = DI::l10n()->t('Invite Friends');
$nv['directory'] = DI::l10n()->t('Global Directory');
$nv['global_dir'] = OpenWebAuth::getZrlUrl($global_dir, true);
$nv['global_dir'] = OpenWebAuth::getZrlUrl($global_dir, true) . $directory_user_lang_string;
$nv['local_directory'] = DI::l10n()->t('Local Directory');
$aside = [];
@ -611,9 +617,9 @@ class Widget
$widget_timelineorder = json_decode(DI::pConfig()->get($uid, 'system', 'widget_timeline_order'));
if (!empty($widget_timelineorder)) {
$tmp = [];
foreach($widget_timelineorder as $order) {
foreach($channels as $channel) {
if($channel['ref'] == $order) {
foreach ($widget_timelineorder as $order) {
foreach ($channels as $channel) {
if ($channel['ref'] == $order) {
$tmp[] = $channel;
}
}

View file

@ -469,6 +469,17 @@ class L10n
return $languages;
}
/**
* Converts e.g. en-gb to en_GB and da-dk to da_DK, which is the format some other systems expect
*
* @param string $lang
* @return string
* */
public function langToLocaleCode($lang)
{
return preg_replace_callback("/([a-z]+)-([a-z]+)/", fn ($m) => $m[1] . "_" . strtoupper($m[2]), $lang);
}
/**
* Convert the language code to ISO639-1
* It also converts old codes to their new counterparts.