Most of the plugin translation strings suddenly disappeared. It seemed to work when I added an extra language, but now I’m not so sure. How can I fix this or determine the cause?
Some extra info: when deleting the language folder, the strings return to normal.
My lang code looks like this.
nl-be.php
<?php
return [
'code' => 'nl-be',
'default' => true,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'nl_BE',
],
'name' => 'Nederlands',
'translations' => [
'arty.job-title' => 'Jobtitel',
],
];
fr-be.php
<?php
return [
'code' => 'fr-be',
'default' => false,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'fr_BE',
],
'name' => 'Français',
'translations' => [
'arty.job-title' => 'Titre du job',
],
];
What version are you on?
From the top of my head, I’d think that the translations array from your languages file should be merged with e.g. translations provided by a plugin. But based on what you report that doesn’t work for you, so would be great to know some more details to try to replicate it.
4.6.1, I started from plainkit.
Could you provide exact steps to reproduce when exactly this happended? After enabling languages? After adding a second language?
Which plugins exactly did you add? I see retour and dreamform, but there seem to be others, like the one that addes the green border on top and the weird language switcher?
The language switcher is a plugin by JUNO, and the first screenshot is Kirby SEO.
Maybe related: Field label language fallback doesn't work · Issue #120 · tobimori/kirby-seo · GitHub
So the issue is more that if a plugin is using translations but doesn’t offer one for the current language that it doesn’t fall back to the English translation provided by the plugin but shows the i18n keys? Did I understand this correctly.
I assume so
However, this is a weird case, since kirby-seo should support FR and NL languages.
I’ll try to reconstruct the issue this week or the following. Currently busy with another deadline.
Hi Sonja,
I had some time to investigate the issue and found that disabling the plugin below restores the missing strings.
This is based on the following example:
That’s interesting. Wonder if it has to do with when things are loaded.
Should I open an issue on github?
using the kirby() global helper in plugin configs will break the loading order as the instance is not done loading all plugins yet.
Okay, that explains why it’s going wrong. Is there another way to check the user role here? Or do you see a completely different approach to accomplish this?
use it inside the function()
as this cookbook shows.
and not like the one you posted
related to
another way would be to swap blueprints in the index.php
. This example show a full new dir per role.
site/blueprints/...
site/blueprints-editor/...
<?php
use Kirby\Cms\App;
$base = dirname(__DIR__); // <-- public folder setup
$base = __DIR__; // <-- default folder setup
require $base.'/kirby/bootstrap.php';
require $base.'/vendor/autoload.php';
$kirby = new App([]);
$user = $kirby->user();
$blueprintsForRole = $user ? $base.'/site/blueprints-'.$user->role() : null;
if ($user && Dir::exists($blueprintsForRole)) {
$options['roots']['blueprints'] = $blueprintsForRole;
$kirby = new App($options);
}
echo $kirby->render();