How to sort language select list on current language context I have a form with a language field with the language select list widget.
The options of this field contains an array with a pattern like 

['langcode' =&gt; t('language')]


Now I want to sort these options in the right order.

The default sorting is on the value but not on the translated one.

e.g. ['de' => t('german')] which I translated into "Deutsch" will now sort under "g" instead of "d".

So I did try to do it in a form alter hook and a preprocess hook but this is not the right place to do it, because the values are still untranslated here.

So my question is how can I sort these options if the values are translated?
i think it can be done in a hook_form_alter()

if the options are in $form['languages'], you can do something like :

$language_options = $form['languages'];


then manipulate the array $language_options, until it has the order you need
then override it in form :

$form['languages'] = $language_options;