删除 symfony 翻译文本上的 %
Remove % on symfony translated text
我正在用这种方式翻译 symfony 上的一些文本
expired.password.body: 'Dear %name% %surname%,<br><br>Your password has expired.'
这是翻译代码
$email_params = [
'name' => $user_to_change_password->getName(),
'surname' => $user_to_change_password->getSurname()
];
$body = $this->translator->trans('expired.password.body', $email_params, 'emails');
然后文本被翻译并且参数正确但 % 仍在翻译文本中
Dear %foo_name% %bar_surname%
我用 str_replace
很容易解决,但我认为我应该在翻译上做错什么
在 Symfony 的翻译器文档中,他们指出定义翻译参数的参数的键实际上应该包含百分比:
use Symfony\Component\Translation\TranslatableMessage;
// the first argument is required and it's the original message
$message = new TranslatableMessage('Symfony is great!');
// the optional second argument defines the translation parameters and
// the optional third argument is the translation domain
$status = new TranslatableMessage('order.status', ['%status%' => > > $order->getStatus()], 'store');
来源:https://symfony.com/doc/current/translation.html#translatable-objects
因此,您的代码应为:
$email_params = [
'%name%' => $user_to_change_password->getName(),
'%surname%' => $user_to_change_password->getSurname()
];
$body = $this->translator->trans(
'expired.password.body',
$email_params,
'emails'
);
我正在用这种方式翻译 symfony 上的一些文本
expired.password.body: 'Dear %name% %surname%,<br><br>Your password has expired.'
这是翻译代码
$email_params = [
'name' => $user_to_change_password->getName(),
'surname' => $user_to_change_password->getSurname()
];
$body = $this->translator->trans('expired.password.body', $email_params, 'emails');
然后文本被翻译并且参数正确但 % 仍在翻译文本中
Dear %foo_name% %bar_surname%
我用 str_replace
很容易解决,但我认为我应该在翻译上做错什么
在 Symfony 的翻译器文档中,他们指出定义翻译参数的参数的键实际上应该包含百分比:
use Symfony\Component\Translation\TranslatableMessage; // the first argument is required and it's the original message $message = new TranslatableMessage('Symfony is great!'); // the optional second argument defines the translation parameters and // the optional third argument is the translation domain $status = new TranslatableMessage('order.status', ['%status%' => > > $order->getStatus()], 'store');
来源:https://symfony.com/doc/current/translation.html#translatable-objects
因此,您的代码应为:
$email_params = [
'%name%' => $user_to_change_password->getName(),
'%surname%' => $user_to_change_password->getSurname()
];
$body = $this->translator->trans(
'expired.password.body',
$email_params,
'emails'
);