forked from GNUsocial/gnu-social
[COMPONENT][Posting] Display short language signifier rather than the full name for the first preffered language
This commit is contained in:
parent
705bf815ab
commit
2cf3a0b4e6
@ -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 = [
|
||||
|
3
components/Posting/config.yaml
Normal file
3
components/Posting/config.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
parameters:
|
||||
posting:
|
||||
use_short_language_display: true
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user