Handle punctuation using Zend_Translate

167 views Asked by At

Currently, I'm trying to apply Zend_Translate to the project I'm working on. Regular text works perfectly fine, but I ran into a problem with the translation of forms.

The translation adapter is registered in Zend_Registry, using Zend_Translate as key. This works fine for most of the time, except for when the translation should happen before displaying the form.

Code example:

$subformBusiness->setLegend(_('Bedrijfsgegevens') . ':');
$subformBusiness->setLegend(_('Bedrijfsgegevens'));

Assuming 'Bedrijfsgegevens' is translated in the corresponding translation source files, the upper line will be outputted as 'Bedrijfsgegevens:', whereas the lower line outputs 'Business information'.

As far as I know, there are three ways of solving this. It can be solved by calling the stored Zend_Translate_Adapter before concatenating it with the colon, but that gives a lot of unnecessary code. Another option is to incorporate punctuation in the translation files, but that would mean there should be a translation for each type of punctuation. The thrid option is to simply remove the colon from the legend, but that's not what I'm looking for.

My question: is there a way to tell Zend_Translate to disregard punctuation?

2

There are 2 answers

3
guhemama On

Why don't you add the punctuation to the strings? OK, you will have to translate both 'Legend' and 'Legend:', but that works perfectly for me.

E.g.:

$subformBusiness->setLegend(_('Bedrijfsgegevens:'));
$element->setLabel('This is a great label:');
0
dinopmi On

As far as I know, Zend_Translate works only with literal strings, and it doesn't contain any punctuation functionality. What I would do would be just to remove the colon from the legend (your third option) and add it afterwards somehow (for instance, using the :after CSS property).

Hope that helps,