Closed marekdedic closed 8 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?
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...
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 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.
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 :)
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 withload_theme_textdomain()
. My.po
files are called liketheme-slug-cs_CZ.po
(so theme slug + locale name), however, theload_theme_textdomain()
function requires the.mo
file to be called justcs_CZ.mo
(so just locale name). This requires me to strip the theme slug from all.mo
filesDescribe the solution you'd like
I'd like to see the option to use just the locale name for the
make-mo
command