Kirby()->language() does not output the current language

trying to adjust $page->url() links to work with multi language … should be $page->url($language->code()) i was using the kirby()->language()->code() method but i always seem to end on the default language. investigating a bit further it seemed when dumping the language that regardless of me accessing the page though

lr.test/en/…

(and all content is properly translated)

the language still remains default as seen below.

// dump(kirby()->language());
Kirby\Cms\Language Object
(
    [code] => de
    [default] => 1
    [direction] => ltr
    [locale] => de_DE
    [name] => Deutsch
    [url] => https://lr.test/de
)
// dump(kirby()->languages());
Kirby\Cms\Languages Object
(
    [0] => de
    [1] => en
)

Are you sure it is not a side effect from your other question?
(Multilanguage works fine on my page)

ATM I’m wrestling through similar muddy waters. :see_no_evil:

Is it possible you came in via a route without using site()->visit()?

kirby()->setCurrentLanguage(kirby()->defaultLanguage()->code());

is the issue here, but that gets me to my previous problem :wink:

having similar trouble with latest 3.3

default lang is de, secondary is en

the failing code is literally just:
<?php $language = $kirby->language(); ?>

in 3.2.3 it gives de or en depending on path being / or /en as set up and expected.

in latest plainkit it gives de in all cases and pages below /en are delivered as german error page. as it works fine with the older kirby, i am quite confused, did i miss a setup here?

also: why is this post marked as solved?

What does your language configuration look like? Could you please post de.php and en.php?

1 Like
<?php

return [
	'code' => 'de',
	'default' => true,
	'direction' => 'ltr',
	'name' => 'Deutsch',
	'translations' => [

	],
	'url' => '/',
	'locale'	=> [
		'de_DE',
		LC_ALL			=> 'de_DE.utf8',
		LC_COLLATE	=> 'de_DE.utf8',
		LC_MONETARY => 'de_DE.utf8',
		LC_NUMERIC	=> 'de_DE.utf8',
		LC_TIME		 	=> 'de_DE.utf8',
		LC_MESSAGES => 'de_DE.utf8',
		LC_CTYPE		=> 'de_DE.utf8'
	]
];
<?php

return [
	'code' => 'en',
	'default' => false,
	'direction' => 'ltr',
	'name' => 'English',
	'translations' => [

	],
	'url' => '/en',
	'locale'	=> [
		'en_GB',
		LC_ALL			=> 'en_GB.utf8',
		LC_COLLATE	=> 'en_GB.utf8',
		LC_MONETARY => 'en_GB.utf8',
		LC_NUMERIC	=> 'en_GB.utf8',
		LC_TIME		 	=> 'en_GB.utf8',
		LC_MESSAGES => 'en_GB.utf8',
		LC_CTYPE		=> 'en_GB.utf8'
	]
];

What if you remove the URL property from the non-default language?

ok. that fixed it for 3.3.1. thanks

but it also took control away. would it work with a subdomain setting?

@texnixe

Yes, you can assign subdomains per language. In what way does it take control away? You can also set 'url' => NULL for the non-default language, should have the same effect.

i takes away the choice of naming the non-default language url to foo, doesn’t it?

Have you tried if that works or breaks? Maybe it’s just /en breaking because that is set as the default?

i did try with /bubu , no luck :slight_smile:

Hm, then that’s probably a bug, could you create an issue on GitHub please?