How to parse Timber (twig) templates with poedit and detect quoted strings to translate

强颜欢笑 提交于 2019-12-07 08:12:31

问题


I want to parse twig templates for Timber with poedit and I need to translate quoted contents. The problem is that I can't find a parser that does not skip quoted content.

Example:

<htmltag attribute="{{ __('value','textdomain') }}" />

Does someone know of a parser for poedit that detects quoted content, like html attribute content?


回答1:


The workaround I found is to set a variable and use it as my attribute value.

{% set attr_value = __('value', 'textdomain') %}
<a href='{{ attr_value }}'>link</a>

This way, the PHP and Python parsers work, as suggested in the Timber documentation.

Using Twig-Gettext-Extractor, I get a Twig-Error-Syntax because of unrecognized __() function.




回答2:


Twig files are not automatically recognized when you use Poedit. To work around this, Timber’s documentation offers three options:

  • Either start each .twig file with {#<?php#}
  • Or use The Twig Gettext Extractor, a «poedit-friendly tool which extracts translations from twig templates».
  • Or use a Python parser. Refer to the documentation on how to set this up in Poedit.

I went with option 3 and it worked nicely.




回答3:


Had the same problem with OSX Sierra, and none of the three solutions worked for me:

  • Using {#<?php#} on top of my .twig files caused poedit not to tecognize my strings
  • Using Twig-Gettext-Extractor throw many errors
  • Using python compile throw many errors too

I solved using the first option ( {#<?php#} on top of my .twig files ) but I also edited PoEdit PHP extractor in order it can search also in .twig files. I hope this can help,

cheers!



来源:https://stackoverflow.com/questions/38665666/how-to-parse-timber-twig-templates-with-poedit-and-detect-quoted-strings-to-tr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!