[COMPONENT][Posting] Display short language signifier rather than the full name for the first preffered language

This commit is contained in:
Hugo Sales 2021-11-08 15:03:39 +00:00 committed by Diogo Peralta Cordeiro
parent 705bf815ab
commit 2cf3a0b4e6
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 19 additions and 6 deletions

View File

@ -92,10 +92,18 @@ class Posting extends Component
Event::handle('PostingAvailableContentTypes', [&$available_content_types]);
$context_actor = null; // This is where we'd plug in the group in which the actor is posting, or whom they're replying to
$preferred_language_choices = $actor->getPreferredLanguageChoices($context_actor);
$language_choices = Language::getLanguageChoices();
$preferred_language_choices = $actor->getPreferredLanguageChoices($context_actor);
ksort($language_choices);
// TODO short display
if (Common::config('posting', 'use_short_language_display')) {
$key = array_key_first($preferred_language_choices);
$locale = $preferred_language_choices[$key];
unset($preferred_language_choices[$key], $language_choices[$key]);
$short_display = Cache::getHashMapKey('languages', $locale)->getShortDisplay();
$preferred_language_choices[$short_display] = trim($locale);
$language_choices[$short_display] = trim($locale);
}
$request = $vars['request'];
$form_params = [

View File

@ -0,0 +1,3 @@
parameters:
posting:
use_short_language_display: true

View File

@ -109,15 +109,17 @@ class Language extends Entity
public static function getLanguageChoices(): array
{
return Cache::getList(
'languages', // TODO replace with F\transform
fn () => array_merge(...F\map(DB::dql('select l from language l'), fn ($e) => $e->toChoiceFormat())),
$langs = Cache::getHashMap(
'languages',
fn () => F\reindex(DB::dql('select l from language l'), fn (self $l) => $l->getLocale())
);
return array_merge(...F\map(array_values($langs), fn ($l) => $l->toChoiceFormat()));
}
public function toChoiceFormat(): array
{
return [_m($this->getLongDisplay()) => $this->getShortDisplay()];
return [_m($this->getLongDisplay()) => $this->getLocale()];
}
public static function schemaDef(): array