Get user current language in a panel field?

Inside a field I use this:

$options = $this->page()->kirby()->options();
echo $options['panel.language'];

My user have the language sv but still it shows en. I’m probably using the wrong function?

How can I get sv when my language of the user is sv?

I found the answer myself again.

$language_code = substr( site()->user()->language(), 0, 2 );
echo $language_code;


Yeah, you are right. In fact, all fields in the user account file are accessible via the $user->data() method and directly thanks to the magic getter.

In a panel field that does not seem to work. But to get all the fields it’s possible to do this:

print_r( site()->user()->data() );

I would prefer doing this if it would be possible:

$language_code = site()->user()->language()->code();
echo $language_code;

…but that code function does not exist.


Well, I think

$site->user()->language() ;

does not work anyway.



And that outputs the language code, anyway.

That won’t work, because the $language object refers to the site language. This is different from the Panel language as you can change these individually.