Language.detect does not work

Hi all,

the setting: ‘language.detect’ => true does not work.
I tested it with my vpn and different countries always the same result: default language.

Any ideas?

Did you change your browser setting and clear the cache. It should actually work.

yes it did, also tested with: https://www.browserling.com.
The page does not switch to english automatilcy.

Which Kirby version do you use?
Could you share your config.php and each languages options?
And your website in domain root (domain.com) or subfolder (domain.com/website)?

Version: 3.2.5

return [
   'debug' => true,
   'languages' => true,
   'language.detect' => true
];


return [
    'code' => 'de',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'de_DE'
    ],
    'name' => 'Deutsch',
    'url' => '/',


];


return [
    'code' => 'en',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'en_UK'
    ],
    'name' => 'English',
    'url' => 'en',


];

Domain: root/httpdoc

do i need to add en_US and en_AU etc?

 'locale' => [
        'en_UK'
    ],

Thanks. I’ll test soon

Make sure to test with a current version, bugs might already be fixed.

I’ve tested and realized that your config is wrong setup. Make sure like following:

config.php

use languages.detect not language.detect

return [
    'debug' => true,
    'languages' => true,
    'languages.detect' => true
];

de.php

Any language url should be not / to work detection.
Use null or any path like /de.
Language detection works only at site root path as /, therefore, any language should not use root url.

return [
    'code' => 'de',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'de_DE'
    ],
    'name' => 'Deutsch',
    'url' => null
];

so it is not possible to have url like this:

de: myurl.de
en myurl.de/en

?

Not possible except custom router on / request maybe.

@texnixe Do you know of an alternative solution about that?

with js but i don’t like that. But it is to late for this project cause of seo.

I know it doesn’t look good for a domain with a .de extension. Your url should be like that:

myurl.de/de
myurl.de/en

Not JS, you can try on router with session.

For example you can use following routes:

return [
    'debug' => true,
    'languages' => true,
    'languages.detect' => true,
    'routes' => [
        [
            'pattern' => '/',
            'action'  => function () {
                $session = kirby()->session();
              
                if ($session->get('languages.detect', false) === false && option('languages.detect') === true) {
                    $session->set('languages.detect', true);
                    
                    return kirby()
                        ->response()
                        ->redirect(kirby()->detectedLanguage()->url());
                }
                
                return page();
            }
        ]
    ]
];

i’ll try, thx!