wp-cli / i18n-command

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

`make-mo`: Add option to specify filename #372

Closed marekdedic closed 8 months ago

marekdedic commented 9 months ago

Feature Request

Describe your use case and the problem you are facing

I'm localizing a WordPress theme that unfortunately cannot be hosted on WP.org due to organisation policy. I am trying to migrate from a collection of tools to the i18n command. I need to create .mo file to be loaded with load_theme_textdomain(). My .po files are called like theme-slug-cs_CZ.po (so theme slug + locale name), however, the load_theme_textdomain() function requires the .mo file to be called just cs_CZ.mo (so just locale name). This requires me to strip the theme slug from all .mo files

Describe the solution you'd like

I'd like to see the option to use just the locale name for the make-mo command

swissspidy commented 9 months ago

I‘d be open for a PR that provides an option to override the name.

But why not just rename the PO file?

marekdedic commented 9 months ago

Yeah, a rename would solve the issue, true. I thought the convention was to include the plugin/theme name, though - I don't know why I think that, I found e.g. https://developer.wordpress.org/plugins/internationalization/localization/#translate-the-po-file now...

swissspidy commented 9 months ago

If you provide your own translation files, the file name convention is <slug>-<locale>.mo for plugins and <locale>.mo for themes. The difference is mostly because of historical reasons.

marekdedic commented 8 months ago

Thanks, didn't know that. Then I'll solve my immediate issue by renaming the po files, however, I still think a (probably more general) option to set the file names could be useful...

sdnunca commented 8 months ago

@swissspidy I've looked into adding the option of overriding the file name, however given that the command also supports converting all files from a directory and in that case the name override would not make much sense.

I'm not sure if adding an option to override the filename that only works when you pass file would make much sense, would appreciate any feedback.

swissspidy commented 8 months ago

That's a good point. I suppose it could still work though, just like msgfmt supports both a directory and a single file as input, and supports a --output-file argument.

Here, we could just enhance wp i18n make-mo <source> [<destination>] so that if source is a single file and destination is a file, then we would use that file name instead.

Example:

Does that make sense?

The alternative is to just close this as a wontfix, as this can also be achieved through other means like simply renaming files afterwards.

marekdedic commented 8 months ago

Hi, in my original report, I wanted to use it with a directory, not a single file - and I suspect most users will too. So the ideal case would be supporting some kind of name transformations, but I think that just may be too complex for a command line argument (in an API, you could pass a function...) :(

swissspidy commented 8 months ago

Agreed that this would be too complex. You can use one of the many shell commands out there to mass-rename files instead. Or better yet, fix the name of your PO files to actually match what WordPress expects :)