I doing a front end page to register as user. It’s a multi language site, It works fine but I noticed that when the I get the error for someone trying to create an account with an email that already has an account, the error in my default language (es_419) in incorrect.
When the current language is english it correctly uses the “error.user.duplicate” in the tranlations files on but on spanish I get “The entry exists” which seems to be a fallback, even if the translation exist on the es_419 file.
Any one else with a similar issue? Hopefully I’m explaining my self. Here is some of the code:
controller for signup.php
$kirby->impersonate('kirby');
try {
$user = $kirby->users()->create(array(
'email' => $data['email'],
'name' => $data['nombres'],
'role' => 'solicitante',
'language' => 'es_419',
'password' => $data['password'],
'content' => [
'phone' => $data['phone']
],
));
$kirby->impersonate(null);
} catch (Exception $e) {
$error = [$e->getMessage()]; // if current language is not english I get a default message
$kirby->impersonate(null);
}
That works! Can I use it like that with the invalid() helper?
$messages = [
'email' => [I18n::template('error.validation.email', null, null, $kirby->languageCode())]
]
I get this error
TypeError thrown with message “Argument 2 passed to Kirby\Toolkit\Str::template() must be of the type array, null given, called in /Users/luzeureka/Desktop/Web/factoria-bogar/web/kirby/src/Toolkit/I18n.php on line 157”
or is better to follow this cookbook recipe
I18n::template('error.validation.email', null, [], $kirby->languageCode());
The third parameter should be an array.
1 Like
I’m tryin to figure this one again and noticed something.
I18n::template($e->getKey(), null, $e->getData(), $kirby->language())
mostly works fine. BUT only on english because $kirby->language()
returns es
on spanish because that the code a putted on my config and set the locale to es_419
.
Here es site/languages/es.php
<?php
return [
'code' => 'es',
'default' => true,
'direction' => 'ltr',
'locale' => 'es_419',
'name' => 'Español',
But I noticed that Kirby on it’s core doesn’t have es
as language, It has 2 type of Spanish es_ES
and es_419
. So I renames my code as es_419
and everywhere else where I had used it as es
and all seems well for now.
I see other languages like Spanish that don’t have a default/neutral so they may have a similar issue so i’m leaving this here.
Note: You can set 'url' => '/es',
on your language config or it will use your code for the url.