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

po: Don't mark JavaScript strings as c-format #1763

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

martinpitt
Copy link
Member

We don't use printf-style C format macros like "%s" in the JavaScript code, at least not for translations. But xgettext interprets the "$0% Free" in pkg/kubernetes/scripts/nodes.js as C format string, which confuses translation tools and blocks the proper translation of this string.

As there doesn't seem to be a way to change the --keyword=ngettext argument to do that, just filter out the c-format tag with sed.

Taken from cockpit-project/cockpit@449d76c0e6d9

Fixes #1712


Tested with make po/podman.pot. diff:

--- /tmp/podman.pot.orig	2024-06-21 14:39:15.548457329 +0200
+++ po/podman.pot	2024-06-21 14:39:35.140548117 +0200
@@ -73,8 +73,8 @@
 msgstr[0] ""
 msgstr[1] ""
 
+#
 #: src/Containers.jsx:379
-#, c-format
 msgid "$0% of $1 limit"
 msgstr ""

We don't use printf-style C format macros like "%s" in the JavaScript
code, at least not for translations. But xgettext interprets the "$0% Free"
in pkg/kubernetes/scripts/nodes.js as C format string, which confuses
translation tools and blocks the proper translation of this string.

As there doesn't seem to be a way to change the `--keyword=ngettext`
argument to do that, just filter out the `c-format` tag with sed.

Taken from cockpit-project/cockpit@449d76c0e6d9

Fixes cockpit-project#1712
@martinpitt
Copy link
Member Author

From @allisonkarlitskaya : Check --keyword=_:1,1t,no-c-format, see https://www.gnu.org/software/gettext/manual/html_node/c_002dformat-Flag.html

@martinpitt martinpitt removed the request for review from jelly June 21, 2024 13:07
@martinpitt martinpitt marked this pull request as draft June 21, 2024 13:38
@martinpitt
Copy link
Member Author

martinpitt commented Jun 23, 2024

@allisonkarlitskaya These don't work. Your first reference applies to comments in the code, but I'm not willing to do that. --keyword=_:1,1t:no-c-format or --keyword=_:1,1t,no-c-format don't work and are also not documented to exist. The --flag documentation is hard to understand, but something like -flag=_:1:no-c-format just causes every message id to receive a "no-c-format" commit which is stupid as well.

I suppose I already pulled my hair out over that six years ago, so I'd like to keep the current seddery. It has served us well enough.

@martinpitt martinpitt marked this pull request as ready for review June 23, 2024 21:27
@martinpitt
Copy link
Member Author

martinpitt commented Jun 24, 2024

I tried to change --language=C to --language=JavaScript, and this is bad: It ignores two strings, and has this weird javascript-format marker -- not sure what weblate and other tools will do about that.

--- /tmp/podman.pot	2024-06-24 14:40:19.848671108 +0200
+++ po/podman.pot	2024-06-24 14:40:37.571759516 +0200
@@ -74,7 +74,7 @@
 msgstr[1] ""
 
 #: src/Containers.jsx:379
-#, c-format
+#, javascript-format
 msgid "$0% of $1 limit"
 msgstr ""
 
@@ -143,12 +143,11 @@
 msgstr ""
 
 #: src/PruneUnusedContainersModal.jsx:96 src/ContainerRenameModal.jsx:97
-#: src/ImageRunModal.jsx:1175 src/ContainerCheckpointModal.jsx:50
-#: src/ForceRemoveModal.jsx:25 src/ContainerDeleteModal.jsx:34
-#: src/ContainerRestoreModal.jsx:53 src/ImageSearchModal.jsx:152
-#: src/ImageDeleteModal.jsx:98 src/ContainerCommitModal.jsx:157
-#: src/PodActions.jsx:52 src/PruneUnusedImagesModal.jsx:97
-#: src/PodCreateModal.jsx:213
+#: src/ContainerCheckpointModal.jsx:50 src/ForceRemoveModal.jsx:25
+#: src/ContainerDeleteModal.jsx:34 src/ContainerRestoreModal.jsx:53
+#: src/ImageSearchModal.jsx:152 src/ImageDeleteModal.jsx:98
+#: src/ContainerCommitModal.jsx:157 src/PodActions.jsx:52
+#: src/PruneUnusedImagesModal.jsx:97 src/PodCreateModal.jsx:213
 msgid "Cancel"
 msgstr ""
 
@@ -250,7 +249,7 @@
 msgid "Containers"
 msgstr ""
 
-#: src/ImageRunModal.jsx:1172 src/PodCreateModal.jsx:210
+#: src/PodCreateModal.jsx:210
 msgid "Create"
 msgstr ""
 
@@ -258,19 +257,10 @@
 msgid "Create a new image based on the current state of the $0 container."
 msgstr ""
 
-#: src/ImageRunModal.jsx:1169
-msgid "Create and run"
-msgstr ""
-
-#: src/Containers.jsx:773 src/ImageRunModal.jsx:1166 src/Images.jsx:400
-#: src/Images.jsx:409
+#: src/Containers.jsx:773 src/Images.jsx:400 src/Images.jsx:409
 msgid "Create container"
 msgstr ""
 
-#: src/ImageRunModal.jsx:1166
-msgid "Create container in $0"
-msgstr ""
-
 #: src/Containers.jsx:856
 msgid "Create container in pod"
 msgstr ""

There's nothing particularly special about the ImageRunModal.jsx:1166 one:

       title={this.props.pod ? cockpit.format(_("Create container in $0"), this.props.pod.Name) : _("Create container")}

Or the :1169 one:

                           {_("Create and run")}

So this isn't reliable.

Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like it, but trust you that it's the best way.

@allisonkarlitskaya allisonkarlitskaya merged commit c09bdcd into cockpit-project:main Jun 25, 2024
34 checks passed
@martinpitt martinpitt deleted the c-format branch June 25, 2024 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cockpit.format() strings are incorrectly marked as c-format
3 participants