Can you enter variables into text when using Zend_Translate in multiple mode

I am trying to use Zend_translate in a situation where I need to insert the value of a variable into the resulting string and contain the string as a plural form. Using the regular (not multiple) helper of the $ this-> translate () view in the script view, I can insert the variable into the string:

$this->translate('You have %1$s questions to answer', 3) // would result in "You have 3 questions to answer" being output 

But how do I do this using what Zend calls the modern multiple signage method? Apparently the view helper $ this-> translate () itself does not support multiple notation, instead I have to call

 $this->translate()->getTranslator()->translate( array('You have %1$s question to answer', 'You have %1$s questions to answer', $someNr ) ) 

But at this moment I only have a multiple line with a placeholder variable, I do not have a line with the entered value. In other words, I get:

You have% 1 $ s questions to answer

I want to

You have 2 questions to answer.

So the question is, does Zend_Translate support this plural way? That is, insert a variable value into a string with pluralization? Or do I need to go with line splitting before and after the plural form, translate each individually and then concatenate at the output?

+4
source share
1 answer

In the controller (or elsewhere):

 <?php $translate = new Zend_Translate (array ( 'adapter' => 'Zend_Translate_Adapter_Array', 'content' => array ( 'test' => 'You have %1$s %2$s to answer' ), 'locale' => 'en' )); 

In view:

 <?php $x = 1; echo $this->translate ('test', $x, $this->translate (array ( 'question', 'questions', $x ))); ?> 

But you probably want to see http://framework.zend.com/manual/en/zend.translate.plurals.html for a more reasonable way to do this.

+2
source

Source: https://habr.com/ru/post/1398841/


All Articles