You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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...
@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.
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:
wp i18n make-mo foo.po -> unchanged behavior, writes foo.mo to same directory as foo.po
wp i18n make-mo foo.po bar.mo -> writes file to bar.mo
wp i18n make-mo foo/bar -> unchanged behavior, generates MO files for all PO files in the directory
wp i18n make-mo foo/bar baz.mo -> won't work!
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.
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...) :(
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 :)
Activity
swissspidy commentedon Nov 8, 2023
I‘d be open for a PR that provides an option to override the name.
But why not just rename the PO file?
marekdedic commentedon Nov 8, 2023
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 commentedon Nov 8, 2023
If you provide your own translation files, the file name convention is
<slug>-<locale>.mofor plugins and<locale>.mofor themes. The difference is mostly because of historical reasons.marekdedic commentedon Nov 8, 2023
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 commentedon Nov 16, 2023
@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 commentedon Nov 16, 2023
That's a good point. I suppose it could still work though, just like
msgfmtsupports both a directory and a single file as input, and supports a--output-fileargument.Here, we could just enhance
wp i18n make-mo <source> [<destination>]so that ifsourceis a single file anddestinationis a file, then we would use that file name instead.Example:
wp i18n make-mo foo.po-> unchanged behavior, writesfoo.moto same directory asfoo.powp i18n make-mo foo.po bar.mo-> writes file tobar.mowp i18n make-mo foo/bar-> unchanged behavior, generates MO files for all PO files in the directorywp i18n make-mo foo/bar baz.mo-> won't work!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 commentedon Nov 21, 2023
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 commentedon Nov 21, 2023
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 :)
sun commentedon Apr 11, 2025
The documentation on https://developer.wordpress.org/cli/commands/i18n/make-mo/ and in the help is inaccurate and misleading. It states:
But the suggested command yields an error:
The correct command argument is to just specify the file including path:
I created a quick follow-up PR for this in #438