Poedit在没有源关键字的情况下翻译字符串的推荐方式/最佳实践是什么? [英] What is the recomended way / best practice to Poedit translate strings without a source keyword?

查看:107
本文介绍了Poedit在没有源关键字的情况下翻译字符串的推荐方式/最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Zend Framework 2应用程序,但翻译存在问题.实际上,在视图脚本中,可以使用视图帮助器

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.

但是在其他地方也有一些字符串,在这些地方我无法使用/view helper,例如在表单类或导航中.应该如何管理?

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?

一些想法:

  1. 使用此类字符串列表创建文件.示例:我们创建文件navigation.i18nforms.i18n等(或仅一个文件),在其中定义我们需要添加到Source keywords列表中的通用Poedit语法中需要的所有字符串(例如,使用translate:translate('my label foo'), translate('my label bar')等),最后添加i18n作为源路径([Poedit menu] -> Catalogue -> Properties... -> Source paths).我们还可以使用已经定义为源路径"的扩展名.

  1. 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 the Source keywords list (e.g. with translate: translate('my label foo'), translate('my label bar') etc.), and finally add i18n as a source path ([Poedit menu] -> Catalogue -> Properties... -> Source paths). We also can use an extension, that is already defined as a 'Source paths'.

一个类,提供一个(静态)方法translate(...)而没有任何功能.示例:我们使用'label' => \MyNamespace\Util\Translator::translate('foo')

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?

推荐答案

只需将关键字_添加到Poedit([Poedit menu] -> Catalogue -> Properties... -> Source keywords).然后,使用带有标签的函数_代替标签. 例如更改

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

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

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

,并在Poedit中更新源代码目录".就是这样-现在您在Poedit中拥有标签了.

and in Poedit update Catalog From Sources. That's it -- now you have your label in Poedit.

这篇关于Poedit在没有源关键字的情况下翻译字符串的推荐方式/最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆