Laravel 6.9.0 validation.php 翻译的消息如果不以变量/属性开头,则不会显示。

huangapple go评论84阅读模式
英文:

Laravel 6.9.0 validation.php translated messages not showing if they do not start with a variable / property

问题

I translated by hand the error messages in the validation.php file for the /en/ locale since the site is almost finished and I figured since it needs only one language (not English) it's not worth refactoring everything to a new locale, instead, just translate the EN one.

但是,我目前遇到的问题是,一个以:attribute或任何其他:variable开头的翻译消息会正确显示,但如果以西里尔字母开头,则不会。以下是validation.php中的一个示例 -

'accepted' => 'Трябва да приемете :attribute.', // 不起作用
'confirmed' => ':attribute не съвпада със стойността за потвърждение.', // 起作用

如果消息不起作用,我只需将:attribute或任何其他可能被称为的内容放在字符串的开头,现在它就可以工作...

这真的很奇怪,我不确定这是否与这个在/en/ lang文件夹下有关或其他原因。我已经尝试寻找解决方案几个小时了,但找不到与我的情况相关的任何内容,所以我希望在这里得到一些帮助。

英文:

So I translated by hand the error messages in the validation.php file for the /en/ locale since the site is almost finished and I figured since it needs only one language (not English) it's not worth refactoring everything to a new locale, instead, just translate the EN one.

But, I am currently facing the issue where a translated message, which starts with :attribute or any other :variable will get displayed properly, but if it starts with Cyrillic it does not. Here is an example from the validation.php -

'accepted' => 'Трябва да приемете :attribute.', // DOES NOT WORK
'confirmed' => ':attribute не съвпада със стойността за потвърждение.', // WORKS

If a message isn't working, all I have to do is put the :attribute or whatever it might be called called, at the beginning of the string and it works now...

This is really weird and I am not sure if it has anything to do with the fact that this is under the /en/ lang folder or something else. I tried to find a solution for a couple of hours now but I cant find anything related to my case so I am hoping for some help here.

答案1

得分: 2

在挖掘了数天后,发现当表单提交大量文本,比如两段文字的textarea内容时,表单输入会发送到一个cookie中,以便在验证失败时闪现错误。但由于textarea包含大量文本,验证失败,但错误闪现也会无声地失败,$errors会保持为空。

https://laracasts.com/index.php/discuss/channels/general-discussion/laravel-5-not-showing-validation-errors-when-textarea-is-filled-with-lots-of-text?

一个可能的解决方案是在session.php中将会话驱动程序设置为FILE,如上面链接的问题中所提到的。

英文:

So after days of digging around, it turns out that when a form submits a huge textarea content, such as like 2 paragraphs of text, the form input is sent to a cookie in order to flash the errors when the validation fails. But since the textarea contains a lot of text, the validation fails, but the error flash also fails, silently,and $errors is left empty.

https://laracasts.com/index.php/discuss/channels/general-discussion/laravel-5-not-showing-validation-errors-when-textarea-is-filled-with-lots-of-text?

A possible solution is to use FILE for the session driver in session.php, as mentioned in the issue linked above.

huangapple
  • 本文由 发表于 2020年1月6日 23:05:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定