Translation Issue in kirby 3.9.8

Hi everyone,

I am working on the plugin and am having trouble with translation. This is my plugin’s ‘index.php’ file.

<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('kirby-cookie-plugin', [
    'blueprints' => [
        'cookiebannertab' => __DIR__ . '/blueprints/tabs/cookiebannertab.yml'
	],
    'snippets' => [
        'cookiebanner' =>  __DIR__ . '/snippets/cookiebanner.php'
    ],
    'translations' => [
        'de' => require __DIR__ . '/translations/de.php',
        'en' => require __DIR__ . '/translations/en.php',
    ],
]);

This is a generic cookie banner plugin that I can use in any Kirby project.

So the problem is that one of my projects only uses the German language. When I log in to the panel and check the cookie banner, the translation is always in English. When I log out of the panel, everything works fine. With this method ‘$kirby->language()->code()’, I checked the language with and without login, and it always returns ‘de’.

Maybe logged user language is English? Alternatively you can also try panel.language option:

There is only one language in the panel, and as I mentioned in my previous comment, I always get ‘de’ with or without logging in. But I’ll try with panel.language option.

@ahmetbora @texnixe Can you please help me regarding this. I’m new in kirby and can’t find any solution.
I also tried with panel.language option but it’s not working.

Just to make sure we are talking about the same thing. Is this a multi-language site with only one language enabled, or a standard site without languages? Are we talking about output in the frontend or in the Panel?

Currently, there is only one language on the site, but it will be multi-language in the future, which is why my plugin is generic enough to be used on other sites as well.

I am referring to the output in the frontend after logging into the panel.

Ok, I tested this again and did the following:

  1. Downloaded a fresh 3.9.8 Starterkit
  2. Enabled languages in config
  3. Created German as language via the Panel
  4. Create a basic plugin with
    • a cookiebanner snippets which only contains the following string <?php echo t('myerror');
    • two translation files en.php and de.php with the translations for myerror
  5. Added the cookiebanner snippet in the header snippet
  6. While logged in, opened the home page at `http://starterkit-3.9.9.test/de: “Cookiebanner” shows string in German
  7. Logged out, opened the home page t `http://starterkit-3.9.9.test/de: : “Cookiebanner” still shows string in German

So if this corresponds to what you are doing, then I cannot reproduce it.

The language definition in site/languages/de as created by the Panel:

<?php

return [
    'code' => 'de',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'de_DE'
    ],
    'name' => 'Deutsch',
    'translations' => [

    ],
    'url' => NULL
];

I also have the same language definition under site/languages/de. Except this ‘url’ => ‘/’

Could you please look at my plugin index.php file? Perhaps there is a mistake in this file.

<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('kirby-cookie-plugin', [
    'blueprints' => [
        'cookiebannertab' => __DIR__ . '/blueprints/tabs/cookiebannertab.yml'
	],
    'snippets' => [
        'cookiebanner' =>  __DIR__ . '/snippets/cookiebanner.php'
    ],
    'translations' => [
        'de' => require __DIR__ . '/translations/de.php',
        'en' => require __DIR__ . '/translations/en.php',
    ],
]);

The index is fine

Is this plugin publicly accessible anywhere?

No, we are using it in our internal Kirby projects.

Could be this setting. Try setting this to null instead.

I tried with null as well but it always same.

And what do you have in your config?

This is in site/config/config.php file.

<?php

return [
	'panel' =>[
		'install' => true,
	],
	'languages' => true,
	'debug'  => true,
	'date.handler' => 'intl',
	'cache' => [
		'pages' => [
		  'active' => true
		]
	  ]
];

Hm, I’m at my wits’ end for the moment. Feel free to send me a download link with the code via PM, so I can check it out locally.