Plugin is multi language kirby not

What’s the simplest solution?
The installed plugin is multi language but Kirby 3 not.
All translation() / t() doesn’t display anything.

Hm, the plugin should actually provide a default value, I don’t think there’s anything you can do other than contacting the developer or set a language.

Can i set the default language in the index.php file of the plugin?

Could you post a link to the plugin, I need to see what’s happening there.

I wrote a fork from the membership plugin (Kirby2).

The index.php

<?php
Kirby::plugin('saan/membership', [
  'templates' => [
	'account'	=> __DIR__ . '/templates/account.php',
	'login'		=> __DIR__ . '/templates/login.php',
	'register'	=> __DIR__ . '/templates/register.php',
	'reset'		=> __DIR__ . '/templates/reset.php',
	'active'	=> __DIR__ . '/templates/active.php'
  ],
  'blueprints' => [
	'account'	=> __DIR__ . '/blueprints/account.yml',
	'login'		=> __DIR__ . '/blueprints/login.yml',
	'register'	=> __DIR__ . '/blueprints/register.yml',
	'reset'		=> __DIR__ . '/blueprints/reset.yml',
	'active' 	=> __DIR__ . '/blueprints/active.yml'
  ],
  'controllers' => [
	'account'	=> require __DIR__ . '/controllers/account.php',
	'login' 	=> require __DIR__ . '/controllers/login.php',
	'register'	=> require __DIR__ . '/controllers/register.php',
	'reset' 	=> require __DIR__ . '/controllers/reset.php'
  ],
  'snippets' => [
	'activeaccount' => __DIR__ . '/snippets/activeaccount.php',
	'resetpassword' => __DIR__ . '/snippets/resetpassword.php'
  ],
  'routes' => [
    [	
      'pattern' => 'logout',
      'action'  => function() {
			if($user = $kirby->user()) {
				$user->logout();
			}
			go();
		}
    ],
    [
		// If user follows the activation link from email
		'pattern' => 'token/([a-f0-9]{32})',
		'action'  => function($token) {	
			$site = site();
			// Find user by token
			if ($user = $site->users()->findBy('token', $token)) {
				// clear the token and set active to '1'
				$user->update([
					'token'		=> '',
					'active'	=> '1'
				]);
				// Account is activated go to account/active
				return go('/account/active');
			} else {
				return go();
			}
		}
	],
	[	
		// If user follows the reset link from email
		'pattern' => 'token/([a-f0-9]{36})',
		'action'  => function($token) {
			$site = site();
			if($u = $site->user()) $u->logout();
			// Find user by token
			if ($user = $site->users()->findBy('token',$token)) {
	
				$user->update([
					'token'    => '',
					'password' => $token,
					'active'   => '1'
				]);
	
				if ($user->login($token)) {
					return go('/account');
				} else {
					return go();
				}
				
			} else {
				return go();
			}
		}
	]
	],//end routes
	'translations' => [
        'de' => [
            // All pages
			'membership.firstname' => 'Vorname',
			'membership.lastname'  => 'Name',
			'membership.email'     => 'E-Mail',
			'membership.password'  => 'Passwort',
			'membership.newpassword'  	=> 'Neues Passwort',
			'membership.confpassword'	=> 'Neues Passwort bestätigen',

The t() helper accepts a fallback value, maybe you can work with that.

u could tidy up your script, that’s what i was doing on my plugin as well

    'hooks' => [
        require __DIR__ .'/registry/hooks/hook.a.php',
    ],
    'routes' => [      
        require __DIR__ .'/registry/route/a.php',        
        require __DIR__ .'/registry/route/b.php',        
        require __DIR__ .'/registry/route/c.php',
    ],
    'translations' => [
        'de' => require(__DIR__.'/languages/de.php'),
        'en' => require(__DIR__.'/languages/en.php'),
    ],
// de.php
<?php return [
  'key' => 'value',
]; ?>

In my case obviously i set ‘languages’ => true in config file, not sure if that’s required…

and i am accessing them (without fallback)

<?= t('key') ?>
<?php echo t('key') ?>

Your update method needs permissions, don’t forget about them. Not sure about single language site, u could just activate the language support and only set up one language for that.

1 Like

If i set languages to TRUE, the url has this ugly “/de/” or “/en/” in it!

On a single language website!

return array (
  'code' => 'de',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => '/'
);

check out the url parameter, u can set

  • domains
  • strings (such as en, de)
  • or just a slash…

so when setting a slash, your default language will also become your-url.com/page

the only difference would be having text.de.txt

1 Like

Ah that’s it.
Many thanks @carstengrimm ! :+1:

1 Like