I'm developing a Zend Framework 2 application an having a problem with translations. Actually in the view scripts a can use the view helper Translate
. Since I defined "translate" as a source keyword in Poedit ([Poedit menu] -> Catalogue -> Properties... -> Source keywords
) the strings are identified by the tool and added to the tranlation list.
But there are also some strings at other places, where I cannot use the/a view helper, e.g. in form classes or in the navigation. How should this be managed?
Some ideas:
Create a file with a list of such strings. Example: We create files
navigation.i18n
,forms.i18n
etc. (or just one file), define there all strings we need in the common Poedit syntax we added to theSource keywords
list (e.g. withtranslate
:translate('my label foo'), translate('my label bar')
etc.), and finally addi18n
as a source path ([Poedit menu] -> Catalogue -> Properties... -> Source paths
). We also can use an extension, that is already defined as a 'Source paths'.A class, that provides one (static) method
translate(...)
without any functionality. Example: Instead of'label' => 'foo'
we use'label' => \MyNamespace\Util\Translator::translate('foo')
I think, the second appoach is cleaner, and I like more. I don't need to write my key sring twice and to hold in the head, what is already translated / updated. But maybe there are better ideas?
Expression
is used:$select->columns(array('title' => new Expression('IFNULL(sports.title, "' . 'unassigned')));
– Herzberg$this->translate($sport->title)
. But it will only be possible, if the key string has already been added to the.po
file. That means, I need access to the Service Locator from my table class. Well, I can pass it as constructor argument, when I'm creating its object in theModule
class, and use is directly in the Table class. But then I need every time to take care of it. – Herzberg