Language detection

Hello,

I have a multilanguage website (English, French, Spanish, Deutsch, Japeneese, Portugueese, Italian)

And i want the best solution to serve user with his native language or country language

By the way lang.detect is not working for me, this is my code

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

c::set('languages', array(
  array(
    'code'    => 'fr',
    'name'    => 'Français',
    'locale'  => 'fr_FR',
    'url'     => '/fr',
    'lang' => 'fr',
  ),
    array(
    'code'    => 'en',
    'name'    => 'English',
    'locale'  => 'en_US',
    'default' => true,
    'url'     => '/en',
    'lang' => 'en',
  ),
  	array(
    'code'    => 'es',
    'name'    => 'Español',
    'locale'  => 'es_ES',
    'url'     => '/es',
    'lang' => 'es',
  ),
    array(
    'code'    => 'it',
    'name'    => 'Italiano',
    'locale'  => 'it_IT',
    'url'     => '/it',
    'lang' => 'it',
  ),
    array(
    'code'    => 'jp',
    'name'    => '日本人',
    'locale'  => 'ja_JP',
    'url'     => '/jp',
    'lang' => 'ja',
  ),
  array(
    'code'    => 'de',
    'name'    => 'Deutsch',
    'locale'  => 'de_DE',
    'url'     => '/de',
    'lang' => 'de',
  ),
  array(
    'code'    => 'pt',
    'name'    => 'Portugês',
    'locale'  => 'pt_PT',
    'url'     => '/pt',
    'lang' => 'pt',
  )
));

Thank you

The language detection is only run on the homepage of the default language (i.e. http://yourdomain.com/) to allow users to manually switch their language on subpages.

Given that, there are two issues with your code:

  • The configuration option is called language.detect, not lang.detect
  • There is no lang key in the languages array, you can remove this as you have already included code

PS: Please use Markdown code blocks when posting code in the future. They use three backticks at the start and end on separate lines. I have corrected it above.

1 Like

Thank you for your answer

I’ve changed the option to language.detect, my browser languages by priority are : fr-FR, fr, en-US,
en

When i run homepage (/), its redirects to english version but should go to french in my case

Have you tried clearing your cookies or using a different browser for testing? Might be that the language was switched, which is remembered by Kirby for the current session.