diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 7bf8e41c43..367b7c00b4 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -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 = [ diff --git a/components/Posting/config.yaml b/components/Posting/config.yaml new file mode 100644 index 0000000000..338b211f57 --- /dev/null +++ b/components/Posting/config.yaml @@ -0,0 +1,3 @@ +parameters: + posting: + use_short_language_display: true diff --git a/src/Entity/Language.php b/src/Entity/Language.php index 0642aa99ea..60e37f036a 100644 --- a/src/Entity/Language.php +++ b/src/Entity/Language.php @@ -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