Getting active lang in config route

I have a route in config that tries to get the active language for the user, this is the relevant part of my code:

        'pattern' => '(:any)/myroute',
        'method' => 'POST',
        'action' => function () {
            return kirby()->language()->code();

…but it seems no matter what language is active for the user, this always returns the default language, in this case “en”

I know the active lang is different from the returned lang, because I use <?php dump($kirby->language()) ?> in my template code and compare with returned language.

What am I doing wrong ?

Should I pass the active lang from the template to the route ? Is there any way to get active lang directly in config ?


You can use the language scope:

As in having distinct routes per language?

I meant using the language prop in your route as in the linked example. What is your language configuration like? Are you using the language code for both default and other languages?