Categories translations in blueprint don't work

Hello!

I am making a website in 3 languages (English, Kazakh, and Russian) with Kazakh being the default. It is a website for a publishing house, where users should be able to add publication issues and select categories or tags from the panel. I made a blueprint for each publication issue with different fields. I am having issues with the category radio field where they have to choose whether it’s a current or upcoming issue for example. The thing these categories should be translated depending on the language chosen, so we have the following in the blueprint:

categories:
            label: Categories
            type: radio
            options:
              current:
                qaz: қазіргі
                eng: current
                rus: текущие
              upcoming:
                qaz: жақында
                eng: upcoming
                rus: предстоящие

And I’ve tried multiple things like renaming the language code or pasting custom translations into the languages files. None of it works, and I only get one language displayed and it’s the same language even if you switch languages.

Could you please advise?

Another issue is that this resulting category filter should be visible on the Publications page, to sort through current, past and upcoming publications. So can’t get it to work until the categories work too. Let me know if you need more information like links or screenshots.

Thank you!

The translation are shown depending on user language, not translation language, also, your language codes are not correct, should be existing codes like en, ru

Hi thank you @texnixe!
The translations are not shown for me unfortunately depending on user language, even when I switch them. Or do you mean by user language the language of the panel itself?
When I use existing codes it doesn’t work either

What I meant was that you need to set your account language to one of the options, then it works, but again it has to look like this:

          categories:
            label: Categories
            type: radio
            options:
              current:
                en: Current
                ru: текущие
              upcoming:
                en: upcoming
                ru: предстоящие

with the proper codes. This is what it then looks like if I set my account language to Russian:

Thank you @texnixe , don;t mean to bother more but it’s still not working, here’s what I have for the entire blueprint file as of now (if you scroll down you’ll see the categories field):

title: Publication

columns:
  main:
    width: 2/3
    sections:
      fields:
        type: fields
        fields:
          description:
            type: textarea
            size: medium
          price:
            label: Price
            type: text
          page amount:
            label: Page amount
            type: text
          cover type:
            label: Cover type
            type: text
          paper type:
            label: Paper type
            type: text
          publication size:
            label: Publication size
            type: text
          sku:
            label: SKU
            type: text
          featured:
            label: Featured
            type: pages
            query: site.find('community')
          categories:
            label: Categories
            type: radio
            options:
              current:
                en: current
                ru: текущие
                ka: қазіргі
              upcoming:
                en: upcoming
                ru: предстоящие
                ka: жақында

                
  sidebar:
    width: 1/3
    sections:
      files:
        type: files

And this is what I get for all three languages (when the user changes language):

What does the rest of the interface look like on that page?

the code was for the entire interface, the interface looks like this @texnixe

and for kazakh:

Hm, but the interface language is English, not Russian

Does the interface language matter? Can’t the interface be in English but the categories show up in different languages once the user selects the language of the website itself (not the panel interface)? Or is that not possible?

On top of that Kazakh language is missing from interface languages anyway

As I said, the user language is the interface language and that’s what your translated options depend on.

There is a workaround though via PHP blueprints, see PHP-based blueprints | Kirby CMS

Ohhh now everything makes sense! Thanks for the workaround :slight_smile:

The workaround works, thanks so much again!

And if I am building a controller filter, and want to access this blueprint field (so that in frontend these categories would be translated when language is changed as well), should I do something like this? I am new to php sorry!

<?php 

return function ($page) {
    
$field = $page->blueprint()->field('category');
    dump($field);
$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$publications = $unfiltered

    ->when($filterBy, function($filterBy) {
        return $this->filterBy('category', $filterBy);
    })
    ->paginate(2);

    $pagination = $publications->pagination();
    $filters = $unfiltered->pluck('category', null, true);

    return [

        'filterBy' => $filterBy,
        'unfiltered' => $unfiltered,
        'publications' => $publications,
        'pagination' => $pagination,
        'filters' => $filters

    ];

};

This will give you the field definition from the blueprint. To get the option, you would need to access the options from the field, then get the right language key.

1 Like

Hi again, I habe tried to follow the link, and if I am understanding correctly, in the controller I am adding the following:

<?php 

return function ($page) {
    
    $kirby = kirby();
    $field = $page->blueprint()->field('category');
    $value = $page->category()->value();
    echo $field['options'][$value][$kirby->language()->code()] ?? $value;

$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$publications = $unfiltered

    ->when($filterBy, function($filterBy) {
        return $this->filterBy('category', $filterBy);
    })
    ->paginate(4);

    $pagination = $publications->pagination();
    $filters = $unfiltered->pluck('category', null, true);

    return [

        'filterBy' => $filterBy,
        'unfiltered' => $unfiltered,
        'publications' => $publications,
        'pagination' => $pagination,
        'filters' => $filters

    ];

};

and then on the page with the filter I am doing the following (unstyled here):

for the sidebar filter:

<a class="" href="<?= $page->url() ?>">
        
        <span class="">all</span></a>

<?php foreach ($filters as $filter): ?>
            <a class=""
            href="<?= $page->url() ?>?filter=<?= $filter ?>">
            <span class=""><?= $filter ?></span></a>

<?php endforeach ?>

for the publications grid:

<?php foreach ($publications as $publication): ?>
    
              
                <a href="<?= $publication->url() ?>">
                
                <?= $publication->image()->resize(300,null) ?> </a> 
               
    
<?php endforeach ?> 

I am definitely missing something because the options don’t change depending on the frontend language. Thanks for your patience so far. I just haven’t understood how to apply this specific situation from the forum or the videos/docs.

You are not supposed to echo anything in the controller, just define a variable.

Also not quite clear where you want to render this field value in the template? When rendering the filters?

I basically have a sidebar filter with categories (and they are multilang) and then on the right i display the filtering results (which are the children of this publications page).
That’s why I have 2 foreach loops, one for the sidebar filter which filters the categories, and another for the publications grid.

so now if I remove the echo in the controller, and put it in the filter foreach loop, how do i incorporate it in there? cause this would be wrong:

<a class="" href="<?= $page->url() ?>"><span class="">all</span></a>
        
<?php foreach ($filters as $filter {
        echo $field['options'][$value][$kirby->language()->code()] ?? $value;
        }
): ?>

      <a class="" href="<?= $page->url() ?>?filter=<?= $filter ?>">
      <span class=""><?= $filter ?></span></a>

<?php endforeach ?>

You need to replace $value with $filter here.

1 Like

Now the filter looks like this (i think the result of the below code is the names of filters under the clickable links) and doesn’t change per language still:

based on this in the filter foreach loop:

<?php foreach ($filters as $filter): {
            echo $field['options'][$filter][$kirby->language()->code()] ?? $filter;
        } ?>
            <a class="bg-lemon-yellow shadow-2xl text-2xl shadow-lemon-yellow rounded-full font-sans-serif text-brown w-fit "
            href="<?= $page->url() ?>?filter=<?= $filter ?>">
            <span class="flex-1 whitespace-nowrap"><?= $filter ?></span></a>

            <?php endforeach ?> 

and this in the controller:

<?php 

return function ($page) {
    
$kirby = kirby();
$field = $page->blueprint()->field('category');

$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$publications = $unfiltered

    ->when($filterBy, function($filterBy) {
        return $this->filterBy('category', $filterBy);
    })
    ->paginate(4);

    $pagination = $publications->pagination();
    $filters = $unfiltered->pluck('category', null, true);

    return [

        'filterBy' => $filterBy,
        'unfiltered' => $unfiltered,
        'publications' => $publications,
        'pagination' => $pagination,
        'filters' => $filters

    ];

}; 

i am using the i18n folder for translations btw and they work perfectly in the panel with the programmable blueprint workaround but for some reason not working here in the frontend when i try to fetch them for this filter