英文:
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会保持为空。
一个可能的解决方案是在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.
A possible solution is to use FILE for the session driver in session.php, as mentioned in the issue linked above.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论