Parsing WordPress translations in Twig/Timber templates has always been quirky and not very convenient. Especially since WordPress started grabbing translations from multiple sources (theme stylesheet, {block,theme}.json, block editor JS, PHP files) and now also outputing in multiple formats (po, [php](https://make.wordpress.org/core/2024/02/27/i18n-improvements-6-5-performant-translations/)).
WP-CLI being the recommended way to create/update POT files, `timber/wp-i18n-twig` provides (almost native) Twig translation extraction by overriding the default `wp i18n make-pot`.
When working with Twig, you may require popular Twig libraries that register custom tags (such as `{% dump %}`, `{% cache %}`, etc.). `timber/wp-i18n-twig` will automatically load the token parsers for the following tags:
- Tags from [symfony/twig-brigde](https://github.com/symfony/twig-bridge):
-`{% dump %}`
-`{% form_theme %}`
-`{% stopwatch %}`
-`{% trans_default_domain %}`
-`{% trans %}`
- Tags from [twigphp/cache-extra](https://github.com/twigphp/cache-extra):
-`{% cache %}`
- Tags from [symfony/ux](https://github.com/symfony/ux)
-`{% component %}`
-`{% props %}`
> [!IMPORTANT]
> For the token parsers to be loaded, you must use the local version of `timber/wp-i18n-twig` (`vendor/bin/wp`).
To make this package work in any Twig environment, templates are not compiled to PHP but only parsed. This main benefit is that it's (almost) configuration agnostic (custom filters, functions, template location).
- Custom tags other than the supported ones above will result in parsing errors.
- Using [non default block/comment/variable tags](https://github.com/twigphp/Twig/blob/4c179c8a64fece77e17ef299d1a2a3f908993107/src/Lexer.php#L58-L64) isn't supported and probably won't ever be.