Multi language troubles

Hi,

I’m working on a bilingual website, I built my blueprints to create en manages my pages in french and in english.

I add 'languages' => true to my config.php file as the guide says. It’s look like this :

<?php
return [
  'environment' => 'local',
  'schnti.cachebuster.active' => false,
  'debug'  => true,
  'languages' => true,

];

I’ve created a folder languages with my fr.php and en.php:

<?php

return [
  'code' => 'fr',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'fr_FR.utf-8',
  'name' => 'Français',
  'url' => '/',
];
<?php

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

    ],
];

I write my site panel this way to change the label of my fields regarding the choosen languages :


tabs:
  settings:
    label:
      fr: Paramètres
      en: settings
    icon: settings
    columns :
      - width: 1/2
        fields:
          maintenance:
            label: Maintenance
            type: toggle
            text:
              - "on"
              - "off"
          siteSettings:
            label: SEO
            type:  headline
          author:
            label:
              fr: Auteur
              en: Author
            type:  text
          description:
            label: Description
            type:  textarea
          keywords:
            label:
              fr: Mots clés
              en: Keywords
            type:  tags
          favicon:
            label: favicon
            type: files
            max: 1
            multiple: false

But I choose my language (French or english), the fields label doesn’t change.


It’s a problem because I’ve got select fields to choose category for my pages and I want to register the category in french and in english. But with this problem I only have one language possible.

I’ve tried to solve it by deleting all my content and media folders, i still got this problem.

That is a misunderstanding. The language of labels, titles etc. defined in a blueprint with the language keys depends on the user language, not on the site language selected with the page language switcher.

Ok I understand, but there is a solution to display french or english in my select field regarding the language of the page and add to my page.en.txt or my page.fr.txt ?

Because for the moment the option is the same neither for the english or french page.

I wrote my select field like this, thinking that will change my options translation regarde the languages off the panel…

category:
        label: Catégorie
        width: 1/2
        required: true
        type: select
        options:
          rassembler:
            fr: rassembler
            en: meet
          habiter: 
            fr: vivre
            en: live

As I said, this will change the display according to the user language. Labels etc. are part of the user interface, therefore what is shown depends on the user selected language.

It probably doesn’t make sense to store values in different languages, but rather translate those option values stored in content files via translation variables.

Ok thanks I will check Translation variables.
But can I say, it’s difficult for a non developper like clients. Because his/her not gonna change his user language, but he/she whill switch french to english in the panel. And by not seign the label language switching can be none ergonomic.

What you can do:

Create a route like this:

'routes' => [
    [
        'pattern' => 'get-options/(:any)',
        'action' => function($lang) {
            $array = [
                'de' => [
                  'rassembler' => 'rassembler',
                  'vivre' => 'vivre',
                ],
                'en' => [
                  'rassembler' => 'meet',
                  'vivre' => 'live',
                ],
            ];
            return $array[$lang];
            
        }
    ]
],

You can even change the keys if you really want to store different values per language.

Then in your blueprint:

    fields:
      category:
        label: Catégorie
        width: 1/2
        required: true
        type: select
        options: api
        api: "http://your.domain/get-options/{{kirby.language.code}}"

Thanks, I’ve tried, but I got this error : Screenshot from 2021-11-10 19-31-08

Does the route work if you open it in the browser?

It’s what it’s display in my panel in the browser. It’s seems the route doesn’t work.