Getting current language in config route

Hello,

In a route (in config) can I magically get the current frontend language of the user without POSTing it ?

Doing:

language = kirby()->language()->code(); (on the route in config)

…seems to always return the main language.

This is because I have to specify the language when returning a page, right ?

return site()->visit('contact',$language)->render(['success' => true]);

Thank you

You can the language if you use the language property:

But as far as I understood that means a different route per each language doesn’t it ? I’d like to keep it under one router.

Nope, one route only.

Oh, so :

			'pattern' => '(:any)',
			'method' => 'post',
			'language' => '*',
			'action' => function ($language) {
                             // use $language, $language->code() etc

Like that ?

It may be though, that using site()->visit() does not allow to include ->render() and so pass variables to the page?

return site()->visit('contact',$language->code())->render(['success' => true]);

Thank you

I wonder if you really need to use $site->visit() when you use the language scope…

This worked:

	[
		'pattern' => '(:any)',
		'method' => 'post',
		'action' => function ($language) {
			$page = page('contact');
			site()->visit($page, $language);
		    return $page->render(['success' => true]);					
		}
	],

…although I find all that a bit un-documented.

I had no idea one could simply pass vars like $language to a route function, where do these come from?

Cheers!