How to sort languages in language selector?

What is a way to sort languages in language selector? For example to have the same order, as in panel, or add my order, something like:

<?php return [ 'code' => 'en', 'order' => '1',

I don’t think you can?

In the panel, AFAIK they’re ordered alphabetically.

If you want to order them yourself; I think you could solve this with a configuration array containing the language codes in the order you want. If you want to make this sortable to editors, you’ld have to use a panel field for that (e.g. structure).

No need to make it sortable in panel. It can be manually giving languages some properties, like 1, 2, 3, and then sorting by them, just need a solution how to give those properties.

I’d also suggest to use a sorting array, like described here:

I understand I should use ->sortBy(‘something’), but the question is how to give each language this “something” property?

As already suggested above, by assigning a sorting number to each language in an array, like in the example in the sorting recipe.

$order = ['en' => 3, 'es' => 1, 'it' => 2, 'de' => 0];
$languages = $kirby->languages()->sortBy( function( $language ) use( $order ) {
  return $order[ $language->code() ];
} );

The order can be stored in the config, for example.

I think I once posted an idea to allow additional fields in the language files, but that has probably gone lost…

Thanks a lot, yes, checked it, but was doing a bit wrong, now it works! :slight_smile: