I'm working on a Wordpress site using Timber as templating engine (twig for Wordpress). I want to translate the interface using the Wordpress gettext mechanism via PoEdit (uses xgettext).
Template snippet:
<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 />
I'm using PoEdit to extract the strings from the *.twig file.
It is working if I place {{ __('City, region, ZIP', text_domain) }} on a separate line in the template, but it is not working when placed in the input placeholder as shown in the snippet above.
I configured PoEdit as explained here: https://github.com/jarednova/timber/wiki/Text-Cookbook#generating-po-files-using-poedit
Does anybody have an idea why that is the case? Is xgettext ignoring strings inside of HTML attributes?
Another example:
In the following case the strings get extracted for translation:
<i class="fa fa-envelope"></i>
{{ __('Search subscription', text_domain) }}
{{ __('Save free search subscription', text_domain) }}
But not in the following case:
<i class="fa fa-envelope"></i>
<span data-rt-xs="{{ __('Search subscription', text_domain) }}" data-rt-lg="{{ __('Save free search subscription', text_domain) }}"></span>
xgettext
or Poedit operate on these cache files instead. (2) Poedit 2 Pro seems to have built-in Twig support. – Hebert