0
votes

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 greater 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?!

2

2 Answers

0
votes

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

0
votes

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');