Setting multiple languages

Hi everyone,

I’ve made a website in french (it will be the default language) and I want know to make the english version. I followed the guide but it doesn’t work. Maybe I missed something.

What I do step by step :

  1. I create the “config” folder.

  2. I create the “config.php” file.

  3. In “config.php”, I copy-paste the code given in the guide to enable to switch between languages.

    <?php

    return [
    ‘languages’ => true,
    ];

At this point nothing has changed, the website is still running. Now I have to set the default language.

So 4) I create the “languages” folder.
5) I create the “fr.php” file, since my default language will be french.
6) I configure the “fr.php” to french :

<?php

return [
  'code' => 'fr',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'fr_FR',
  'name' => 'Francais',
];

At this point, everything seems ok in the panel, I can see the french language in the settings. My main URL redirect to “mainurl/fr”, wich is a default page that only show a title (home). Next steps of the guide may fix it.

  1. I add " ‘url’ => ‘/’, " to the fr.php. In this file, the code seems to have automatically changed, probably when I clicked on the edit button of the language in the site settings panel. Now it looks like

    <?php

    return [
    ‘code’ => ‘fr’,
    ‘default’ => true,
    ‘direction’ => ‘ltr’,
    ‘locale’ => [
    ‘LC_ALL’ => ‘fr_FR’
    ],
    ‘name’ => ‘Francais’,
    ‘translations’ => [

     ],
     'url' => '/',
    

    ];

Next steps doesn’t concerns me so I skip it.

At this point the main url is not redirecting to “mailurl/fr” but the page shown is still showing a default page only containing the title (home). All pages have disappeared in the panel.

Do I’ve missed something ?

Thx for your help

Edit :
Something very strange is that some pages are showing the right template but without any content (wich I fix by copy-pasting the content of my “page.txt” into the automatically created “page.fr.txt” wich was empty) whereas some are showing the default template. This looks arbitrary : some main pages uses the right template, some aren’t, some of the sub pages uses the right template, some of the subpages of the same page aren’t.

The problem here is that if you define the language manually, you need to rename your text files manually to include the language code, e.g. project.fr.txt. In a site with languages enabled, you may not have any content files without the language string anymore.

That’s actually the reason why setting the languages via the Panel Settings page is the better approach, it creates the language files in the /site/languages folder for you and renames your content files automatically.

Thx @texnixe !

I renamed my files but it still doesn’t work for some pages.

The sub page “Demeure” works but the sub page “Familiale” doesn’t. The home page doesn’t work either.

You have to delete those files without the language extension… In a multi-lang context, make sure to have only files with the language code, but for files and pages.

It works but not for the home page

“maison” doesn’t work neither.

You have salon-poele.jpg.fr.txtand salon-poele.fr.txt, the latter is superfluous.

Thx a lot, I just deleted all txt files since Kirby create them automatically.

Great thanks @texnixe

Have another problem. Sorry for all my questions.

My default language is set to french but english is displaying by default. I tried to turn off the language detection : doesn’t work.
By the way, I can’t switch the language of the page displayed by adding “/fr” or “/en” at the end of the URL.

Here is my code :

config.php :

<?php

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

fr.php :

<?php

return [
    'code' => 'fr',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'fr_FR'
    ],
    'name' => 'Francais',
    'translations' => [

    ],
    'url' => '/',
]; 

en.php :

<?php

return [
    'code' => 'en',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'en_US'
    ],
    'name' => 'English',
    'translations' => [

    ],
    'url' => '/'
];

You have set both languages to the same URL, which doesn’t make sense.

Also, language detection only works if both languages use the language slug in their URLs.

Thank you very much, I’ll try tomorrow.

I think everything works perfectly now.

Thanks again for your help @texnixe !

1 Like