wp-cli / i18n-command

Provides internationalization tools for WordPress projects.
MIT License
96 stars 52 forks source link

wp i18n make-php - Expectations #385

Closed davidwebca closed 5 months ago

davidwebca commented 5 months ago

Feature Request

Describe your use case and the problem you are facing

When using the previously existing wp i18n make-pot and others, the assumption is that the first argument of the function is the source code, not another file. When I first saw wp i18n make-php, I excepted the first argument to take in the source code to generate directly the PHP files for the new performant translations project.

Describe the solution you'd like

For the sake of consistency wp i18n make-php should take in, as first argument, a path to the source code instead of a "po/mo" files or folder source of po/mo files.

wp i18n make-php /path-to-my-php-source-code /path-to-the-languages-folder

This is also a case for people who aren't interested in developing for older versions of WordPress and that aren't required to support po/mo files : right now the steps I would need to take would be to generate the pot file, translate with Poedit or other tools and then generate the PHP files which seems cumbersome to me.

I'd then suggest either a new additional command to convert po files to PHP or adding an argument to pass.

ex.: wp i18n convert-po --format=PHP /path-to-pomo-folder /path-to-destination-folder --> converts po files to different formats

wp i18n make-php /path-to-my-php-source-code /path-to-destination-folder --> makes PHP languages files from scanning the source code like the other commands.

swissspidy commented 5 months ago

The flow is exactly the same as when generating MO files as well:

  1. Parse the source code to get a string catalog (POT)
  2. Use a tool such as Poedit to create a new translation based on the catalog in a given language (PO)
  3. Bring the translation in to a machine readable format (MO or PHP) that cannot be directly opened by Poedit, but cam be understood by WordPress

As for the naming: the make-php command is the counterpart to the make-mo command.

Hope that makes it more clear.

davidwebca commented 5 months ago

Gotcha! I think I expected this move to remove the initial step since we can be working directly with PHP but I was wrong. Maybe in the future! Thanks 🤘