Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make-mo: Add option to specify filename #372

Closed
1 task done
marekdedic opened this issue Nov 8, 2023 · 8 comments · Fixed by #373
Closed
1 task done

make-mo: Add option to specify filename #372

marekdedic opened this issue Nov 8, 2023 · 8 comments · Fixed by #373

Comments

@marekdedic
Copy link

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
Copy link
Member

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

But why not just rename the PO file?

@marekdedic
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link

sdnunca commented 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
Copy link
Member

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.

@marekdedic
Copy link
Author

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 swissspidy linked a pull request Nov 21, 2023 that will close this issue
@swissspidy
Copy link
Member

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 :)

@swissspidy swissspidy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants