What is the recommended method / best practice for Poedit to translate strings without a source keyword?

I am developing a Zend Framework 2 application that has a translation problem. In fact, in view scripts a, you can use the Translate helper. Since I defined β€œtranslate” as the source word in Poedit ( [Poedit menu] -> Catalogue -> Properties... -> Source keywords ), the strings are identified by the tool and added to the list of transactions.

But there are some lines in other places where I cannot use the / a view helper, for example. in class classes or in navigation. How should it be managed?

Some ideas:

  • Create a file with a list of such lines. Example. We create files navigation.i18n , forms.i18n , etc. (Or just one file), we will define there all the lines that we need, in the general Poedit syntax, which we added to the Source keywords list (for example, with Translate : translate('my label foo'), translate('my label bar') , etc.) and finally add i18n as the source path ( [Poedit menu] -> Catalogue -> Properties... -> Source paths ). We can also use an extension that is already defined as "source paths."

  • A class that provides one (static) translate(...) method without any functionality. Example. Instead of 'label' => 'foo' we use 'label' => \MyNamespace\Util\Translator::translate('foo')

I think the second lesson is cleaner, and I like it better. I do not need to write my key line twice and keep in mind what has already been translated / updated. But maybe there are better ideas?

+1
source share
3 answers

Just add the _ keyword to Poedit ( [Poedit menu] -> Catalogue -> Properties... -> Source keywords ). Then, instead of the label, use the _ function with that label. For example, change

  'options' => array( 'label' => 'Username', ), 

to

  'options' => array( 'label' => _('Username'), ), 

and in updating the Poedit directory from sources. What is it - now you have your own label in Poedit.

+1
source

I still do not understand where your problem is: S From all I can say, you are trying to translate the output of a model / object. This is a typical View problem!

If the main problem is β€œHow to get all these Model-Outputs in PoEdit?”, Then all I can tell you is either manually or implement DB-Translation ...

Implementing a ServiceManager is basically everything that matches this syntax getServiceConfig()

 return array( 'factories' => array( 'my-service' => function ($sm) { $class = new ServiceClass(); $class->setServiceManager($sm); return $class; } )); 

In the above example, $class could be pretty much everything. Model / Entity, TableGateway or whatever you want.

0
source

If you create your form differently, for example:

 $name = new \Zend\Form\Element('name'); $name->setLabel('Your name'); $name->setAttributes(array( 'type' => 'text' )); $this->add($name); 

( http://framework.zend.com/manual/2.0/en/modules/zend.form.quick-start.html )

Then you can register "setLabel" as a keyword in poedit and it will pick up the text label for the translation.

0
source

All Articles