Problem with language.detect

Hello all,

has anyone successfully setup the automatic language detection?

I’ve set

c::set('language.detect', true);

and the language configuration is pretty standard:

c::set('languages', array(
    array(
    'code'    => 'de',
    'name'    => 'DE',
    'locale'  => 'de_DE',
    'url'     => '/de',
  ),
  array(
    'code'    => 'en',
    'name'    => 'EN',
    'default' => true,
    'locale'  => 'en_US',
    'url'     => '/en',
  ),
));

With this configuration only the first page view redirects correctly from url.com to url.com/de. As soon as Kirby has set its cookie all following page views redirects to url.com/en.

What can cause this behavior? Is this a known bug or am I doing something wrong?

Still trying to find a solution. No one on this?

This is working fine for me. I have set langiage detect after languages array.

c::set('languages', array(
  array(
    'code'    => 'no',
    'name'    => 'Norwegian',
    'default' => true,
    'locale'  => 'no_no',
    'url'     => '/'
  ),
  array(
    'code'    => 'pl',
    'name'    => 'Polski',
    'locale'  => 'pl',
    'url'     => '/pl'
  ),
));

c::set('language.detect', true);

Everything working fine for me.

@Sciscitator you have to much commatas in your script on ‘url’.

Cheers,
Jan

I’m afraid it is not the case. It is in documentation with the last comma and it was working for me just OK.

Hi,
okay you are right. I tested it with different commatas and everything worked fine.
Also the position, if before or after the arrays of language.detect, is equal.
Have you set your content files also with the right naming?

default.de.txt and default.en.txt

@JanStieler:
Exactly, the syntax is fine even with commata. Also the content files are setup correctly. And the translation itself works perfectly. It’s just the odd behaviour of the language detection.

@mbochynski
Maybe I’m just getting it wrong, but I cannot see how your configuration would work properly. Aren’t you taking away the possibility for users to choose the language by themselves this way?

You have defined “/” as entry point to Norwegian and “/pl” for Polski. Even if the detection only takes place at the base url, users from Poland couldn’t choose the Norwegian version because the site would always redirect them to the version in Polski. Is this the behavior you want to achieve?

For me language detection would only make sense with the following assumptions:

  • Detection only comes in action on the base url of the site
  • As shown in my example all language versions of the site are accessable by the language code in the url.

This way it should be possible to use language detection AND let the users change the language by using a language switcher. I think this is a common and adequate way to integrate language detection (microsoft.com is doing it this way for example).

Any thoughts on this? Can anyone tell me how the language detection in Kirby actually really works?

Do you use the latest version? There was a minor bug in the detector in 2.0.6 which should be fixed now.

1 Like

This is exactly how I expect language detection to work. But I think something isn’t quite working right. Detection fails on successive visits.

I’ve reported the issue here: [Panel] Add auto-save not only on blur, but every X seconds · Issue #268 · getkirby/kirby · GitHub

Thanks for the answer. I’m using 2.1.0 from 19.5. Will update to latest commit and will try again.

Hey, I know that this is a old issue but I tried to get the language kit from kirby (clean install) to reflect what my issue is.

I have tested again and again with and I do not get this to work. So I have cleaned the cache and also I have only used Firefox for my tests. The issue is consistent.

###So my issue:

The languages detect worked fine until I added the third language Portuguese. With english and Norwegian it worked. Then I added the last language, then the automatic switching stops not working. Also when I then try to go back it does´t work anymore.

Any ideas of what causes this?

Here is my test repo: https://github.com/jonabaptistella/lang.curto.dk

I really need this to work perfectly. This is with Language-kit from Kirby 2.3.2.