translations

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

translations

Bas Kamer
Hi

Today I had a deep look at the Translator and investigating the text domain object that the various translator plugins generate and the way the Translator uses them I found out that you cannot mix the translate() and translatePlural() helpers for identical message.

A typical object might look like this (from the tests):

a message may be either a string or an array with indexes for the plurals.

//  ["storage":"ArrayObject":private]=>
//  array(3) {
//    ["Message 2"]=>
//    string(11) "Nachricht 2"
//    ["Message 9"]=>
//    string(11) "Nachricht 9"
//    ["Message 11"]=>
//    array(2) {
//        [0]=>
//      string(16) "Nachricht 11 - 0"
//      [1]=>
//      string(16) "Nachricht 11 - 1"
//    }
//  }
//}


You would not be able to call echo $this->translate('Message 11'); because that returns an array and not a string. Apparently 'Message 11' is expected to be defined as an plural…

I think this is not correct.

I should be able to use translate('Book') or translatePlural('Book', 'Books', 1)  

It would be simple (and BC) to add a check to see if the key contains and return the first (or key 1 or a special key ("" perhaps)).  However this behavior might be on purpose because of performance reasons. (Many calls, every bit helps)


please advise.


Reply | Threaded
Open this post in threaded view
|

Re: translations

Ben Scholzen 'DASPRiD'
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: translations

Bas Kamer
you are right in my example I have no placeholder for the number.

what I am getting at they you might have…

I one part of my application I might have translatePlural('Book', 'Books', $placeholder), in an other this translate('Book'); Why should that return an Exception?


On 14 jun. 2013, at 09:47, Ben Scholzen 'DASPRiD' <[hidden email]> wrote:

> The correct behaviour would actually be to throw an exception. In the
> example you used, the "Book" or "Books" key makes no sense for
> translatePlural() method, as there is no placeholder for the number in it.
>
> On 14.06.2013 00:31, Bas Kamer wrote:
>> Hi
>>
>> Today I had a deep look at the Translator and investigating the text domain object that the various translator plugins generate and the way the Translator uses them I found out that you cannot mix the translate() and translatePlural() helpers for identical message.
>>
>> A typical object might look like this (from the tests):
>>
>> a message may be either a string or an array with indexes for the plurals.
>>
>> //  ["storage":"ArrayObject":private]=>
>> //  array(3) {
>> //    ["Message 2"]=>
>> //    string(11) "Nachricht 2"
>> //    ["Message 9"]=>
>> //    string(11) "Nachricht 9"
>> //    ["Message 11"]=>
>> //    array(2) {
>> //        [0]=>
>> //      string(16) "Nachricht 11 - 0"
>> //      [1]=>
>> //      string(16) "Nachricht 11 - 1"
>> //    }
>> //  }
>> //}
>>
>>
>> You would not be able to call echo $this->translate('Message 11'); because that returns an array and not a string. Apparently 'Message 11' is expected to be defined as an plural…
>>
>> I think this is not correct.
>>
>> I should be able to use translate('Book') or translatePlural('Book', 'Books', 1)  
>>
>> It would be simple (and BC) to add a check to see if the key contains and return the first (or key 1 or a special key ("" perhaps)).  However this behavior might be on purpose because of performance reasons. (Many calls, every bit helps)
>>
>>
>> please advise.
>>
>>
>
>
> --
> Ben Scholzen 'DASPRiD'
> Community Review Team Member | [hidden email]
> Zend Framework               | http://www.dasprids.de