admin管理员组

文章数量:1122832

Using the wp i18n make-pot I can create a .pot file that can interpret .php files.
This is the command I use

wp i18n make-pot . languages/my-plugin.pot

This is good but because I use timber with my wordpress as its template engine, timber uses .twig files.
How can I use wp-cli create .pot command to look into .twig files?
I tried this command

wp i18n make-pot . languages/my-plugin.pot --include=*.twig

That creates the same .pot file that only interpreted .php and not .twig files as well.

Looking at github issues this is a open issue ease inheritance in order to support Twig/Timber.
Reading this thread I could not really come to a solution.

Using the wp i18n make-pot I can create a .pot file that can interpret .php files.
This is the command I use

wp i18n make-pot . languages/my-plugin.pot

This is good but because I use timber with my wordpress as its template engine, timber uses .twig files.
How can I use wp-cli create .pot command to look into .twig files?
I tried this command

wp i18n make-pot . languages/my-plugin.pot --include=*.twig

That creates the same .pot file that only interpreted .php and not .twig files as well.

Looking at github issues this is a open issue ease inheritance in order to support Twig/Timber.
Reading this thread I could not really come to a solution.

Share Improve this question edited Dec 20, 2021 at 15:20 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 19, 2021 at 10:29 Buttered_ToastButtered_Toast 2,8191 gold badge8 silver badges21 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

As you mentioned - it's an open issue so unlikely to have been resolved by any of the solutions in the thread... This seems to be the most likely working solution though

wp timber make-pot && wp i18n make-pot --merge=twig.pot

I haven't used timber before but check what file is created with wp timber make-pot and ensure that's the one merged into the i18n command

The other code examples refer to improvements in the i18n-command package itself

Edit

Looking at the ticket again this is actually just another "suggested" use case. But there's still hope...

According to this page on the timber GitHub support there are a few options available to you.

  1. Use a tool that supports parsing Twig files to detect all your translations like Poedit. This will make your .pot files and the merge command can be run to work it into the i18n function.
  2. A nasty twig vs. gettext hack is to add {#<?php#} to the top of your twig files. By doing this, gettext will interpret whatever comes next as PHP, and start looking for __.
  3. Twig gettext extractor - a special Twig parser for Poedit.
  4. There is mention of a gulp script to do this... however the links I followed don't seem to work any more - this is the original ticket for the gulp solution though and can be used as a base if you feel like having a crack at that

I had the same issue and located this package: timber/wp-i18n-twig https://packagist.org/packages/timber/wp-i18n-twig

After installing this package the wp i18n make-pot . languages/my-plugin.pot worked on .twig files as well.

本文标签: translationUsing wpcli to create a pot file that interprets twig files as well