Attempting to utilize xgettext
for extracting translatable strings from a VueJS file has presented some challenges. Specifically, xgettext
does not seem to recognize JavaScript code within a computed property in VueJS.
For instance, consider the following element in the <template>
:
<input :placeholder="translator.gettext('Phone')" />
Unfortunately, this snippet goes unnoticed when executing xgettext
with parameters such as:
xgettext --from-code=UTF-8 --language=JavaScript
On the other hand, if a translatable string is used within a function call, it is successfully identified. For example:
<div>{{ translator.gettext('This is picked up 1') }}</div>
<input :placeholder="translator.gettext('This is NOT picked up')" />
<div>{{ translator.gettext('This is picked up 2') }}</div>
In this case, the translatable string inside the input
placeholder remains undetected, while the other two are recognized.
The issue seems to stem from xgettext
treating content within an HTML property as a plain string, while VueJS interprets any value prefixed by a :
as valid JavaScript execution.
Is there a solution or workaround that would enable xgettext
to acknowledge this JavaScript code instead of simply treating it as a plain string?