Conversation
…rn of changes to the .po files
MebinAbraham
left a comment
There was a problem hiding this comment.
Good first PR, just a few comments. 🙌
…o using a NamedTuple for keys and improved print output
MaciekBaron
left a comment
There was a problem hiding this comment.
LGTM, just one typo + wording suggestion
…igital/dis-wagtail into CMS-789-makemessages-linter
| return ( | ||
| f"{'msgctxt: {self.msgctxt}\n' if self.msgctxt != '' else ''}" | ||
| f"msgid: {self.msgid}" | ||
| f"{'\nmsgid_plural: {self.msgid_plural}' if self.msgid_plural != '' else ''}" | ||
| ) |
There was a problem hiding this comment.
The msgid_plural and msgctxt are not being interpolated properly, and also we can't have backslashes in fstrings.
| return ( | |
| f"{'msgctxt: {self.msgctxt}\n' if self.msgctxt != '' else ''}" | |
| f"msgid: {self.msgid}" | |
| f"{'\nmsgid_plural: {self.msgid_plural}' if self.msgid_plural != '' else ''}" | |
| ) | |
| return ( | |
| (f"msgctxt: {self.msgctxt}\n" if self.msgctxt else "") | |
| + f"msgid: {self.msgid}" | |
| + (f"\nmsgid_plural: {self.msgid_plural}" if self.msgid_plural else "") | |
| ) |
| for path in self._modified_po_files: | ||
| self.stderr.write(f" {path}\n\n") | ||
| if len(self._modified_po_files[path]) > 0: | ||
| self.stderr.write(" The following msgids have changed\n\n") |
There was a problem hiding this comment.
| self.stderr.write(" The following msgids have changed\n\n") | |
| self.stderr.write(" The following msgids have changed:\n\n") |
| if len(self._modified_po_files[path]) > 0: | ||
| self.stderr.write(" The following msgids have changed\n\n") | ||
| for item in self._modified_po_files[path]: | ||
| self.stderr.write(f" {item}\n\n") |
There was a problem hiding this comment.
Nit: The formatting off this when you have ctx, and plural seems a bit off. It would be good to make it consistent.
Currently you get:
The following msgids have changed
msgctxt: button label
msgid: Open new
msgid: Open New
msgid_plural: Open New
Would be good to have something like:
- msgctxt: button label
msgid: Open new
- msgid: Open New
msgid_plural: Open News
There was a problem hiding this comment.
Have some improved formatting here, do we want to also insert indentation for multiline strings or leave them in a similar format to the .po file?
- msgid:
If the web address is correct, or you selected a link or button, <a
href="%(contact_url)s">contact us</a>.
vs
- msgid:
If the web address is correct, or you selected a link or button, <a
href="%(contact_url)s">contact us</a>.
There was a problem hiding this comment.
I'm easy either way, up to you.
There was a problem hiding this comment.
I'm happy to leave it as is then
| """Extracts groups of msgid, msgctxt and msgid_plural from pofile contents and returns | ||
| a set of unique groups keyed with a tuple of those values in the order (msgid, msgctxt and msgid_plural). | ||
|
|
||
| msgctxt and msgid_plural will default to an empty string if not present. |
There was a problem hiding this comment.
For clarity:
msgctxt and msgid_plural will default to an empty string if not present.
Used by --check mode to detect changes that affect translation behaviour
only. This intentionally ignores header metadata, comments, source
references, ordering, wrapping, and other non-functional PO churn.| make makemessages-check | ||
| ``` | ||
|
|
||
| Will warn if .po files will change without applying changes to disk. |
There was a problem hiding this comment.
| Will warn if .po files will change without applying changes to disk. | |
| Will error if `.po` files will change that affect translation behaviour. It ignores non-functional changes such as headers, comments, source references, entry ordering, and line wrapping. |
There was a problem hiding this comment.
For clarity, warn > error since we exit 1.
| content_before = Path(self.potfile).read_text(encoding="utf-8") | ||
| self.command.write_po_file(self.potfile, "cy") | ||
| content_after = Path(self.potfile).read_text(encoding="utf-8") |
There was a problem hiding this comment.
Should be using po file?
| for path in self._modified_po_files: | ||
| self.stderr.write(f" {path}\n\n") | ||
| if len(self._modified_po_files[path]) > 0: | ||
| self.stderr.write(" The following msgids have changed\n\n") |
There was a problem hiding this comment.
Since it might not be msgid that have changed, maybe The following translation keys have changed: or The following translation items have changed:
|
@MebinAbraham |
What is the context of this PR?
Relates to CMS-789.
Add a --check flag to makemessages management command to warn if there would be any updates to .po files. Intended to be used in pre-commit and CI to ensure translations aren't missed.
How to review
Try running make make messages-check without any code changes.
Try running after changing a string in a call to gettext and sense check returns correct value.
Deployment Safety
Bleed and Sandbox deploy automatically on merge, so PRs should be safe to deploy immediately.
Please select one:
Follow-up Actions
Needs to be added to pre commit and CI.
Might want to add line numbers to original code files at some point.