【发布时间】:2015-11-25 07:11:25
【问题描述】:
我正在开发一个使用 Timber 作为模板引擎(Wordpress 的树枝)的 Wordpress 网站。我想通过PoEdit使用Wordpress gettext机制翻译界面(使用xgettext)。
模板sn-p:
<form action="/{{ current_language }}/api/search/{{ viewModel.currentSuperCategory.key }}"
method="post"
class="search-results__search"
id="search-form">
<input placeholder="{{ __('City, region, ZIP', text_domain) }}…"
class="input search-results__search__input"
name="search-query"
type="text"
data-search-autocomplete />
我正在使用 PoEdit 从 *.twig 文件中提取字符串。
如果我将 {{ __('City, region, ZIP', text_domain) }} 放在模板中的单独一行,它是工作,但它 在输入占位符中时不工作,如上面的 sn-p 所示。
我按照此处的说明配置了 PoEdit:https://github.com/jarednova/timber/wiki/Text-Cookbook#generating-po-files-using-poedit
有人知道为什么会这样吗? xgettext 是否忽略了 HTML 属性中的字符串?
另一个例子:
在以下情况下,将提取字符串进行翻译:
<i class="fa fa-envelope"></i>
{{ __('Search subscription', text_domain) }}
{{ __('Save free search subscription', text_domain) }}
但不属于以下情况:
<i class="fa fa-envelope"></i>
<span data-rt-xs="{{ __('Search subscription', text_domain) }}" data-rt-lg="{{ __('Save free search subscription', text_domain) }}"></span>
【问题讨论】:
-
两个最佳解决方案是: (1) 让 Twig 创建所有模板文件的缓存版本。这些是实际的 PHP 文件。然后让
xgettext或 Poedit 代替对这些缓存文件进行操作。 (2) Poedit 2 Pro 似乎内置了 Twig 支持。
标签: wordpress twig poedit xgettext timber