开发者

i18n in Symfony Forms

开发者 https://www.devze.com 2023-04-04 03:54 出处:网络
Is there any way I can use the format_number_choice function inside of a actions file. In fact I need to use it for a Form error message.

Is there any way I can use the format_number_choice function inside of a actions file. In fact I need to use it for a Form error message.

'max_size' => 'File is too large (maximum is %max_size% bytes).',

In English it's simply "bytes", but in other languages the syntax changes after a certain value (for example if the number is g开发者_如何转开发reater than 20 it's: "20 of bytes").

I can use parenthesis, of course, but if the framework offers support for doing this specific thing, why not to use it?!


The way it's currently implemented in the 1.4 branch, you can define only one translation per message using il18n XML files.

What you could do is create a custom validator which inherits the current validator (sfValidatorFile in your example) and does the size checking in the doClean method before calling its parent's method.

I suggest you take a look at the source to see how it works : sfValidatorFile


The correct way to handle number ranges for translation is explained here in the Definitive Guide. I won't reproduce it here as the documentation itself is clear and concise. Note however that the string is not extracted automatically by the i18n-extract task, so you need to add it manually - again, the documentation explains this.

So yes, you can use the format_number_choice() function inside an action - you just need to load the helper inside the action like this:

sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号