Skip to contentSkip to conversation

add-patch: use Q_() for split hunk translation

PATCH Superseded aeron-gh 1 participant 2 messages Nov 10 – Nov 20

lore
Share & tools
lore

aeron-gh

author
#0 lore raw

PATCH 1/1 add-patch: use Q_() for split hunk translation

The "Split into %d hunks." message uses _(), which provides the same translation for every number. The Polish translation shows "2 skrawków", but the correct form is "2 skrawki". Numbers 2 and 5 need different plural forms.

Use Q_() with singular and plural forms, passing splittable_into as the count. This lets translators provide the correct plural forms while keeping the English output unchanged.

---
This patch is part of my GSoC 2027 microproject. Mahmoud announced this issue in March, but no patch followed:
https://lore.kernel.org/git/CAC5WPUdYxm-7Pjq4oAddLKXjSa7B0YdK8ashyeR9vhCQt+wvPA@mail.gmail.com/

 add-patch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
add-patch.c +3 -1
index f27edcbe8d..4e75e2ceda 100644
@@ -1942,7 +1942,9 @@ static size_t patch_update_file(struct add_p_state *s,
 			} else if (!split_hunk(s, file_diff,
 					     hunk - file_diff->hunk)) {
 				color_fprintf_ln(stdout, s->cfg.header_color,
-						 _("Split into %d hunks."),
+						 Q_("Split into %d hunk.",
+						    "Split into %d hunks.",
+						    splittable_into),
 						 (int)splittable_into);
 				rendered_hunk_index = -1;
 			}
Signature · 1 line
2.56.0
#1 lore raw

PATCH v2 1/1 add-patch: use Q_() for split hunk translation

The "Split into %d hunks." message uses _(), so a translation can have only one form for every count. Some languages need more than that. In Polish, 2 and 5 take different plural forms: the current translation "Podzielono na %d skrawków" uses the form for 5, so a split into 2 hunks reads "2 skrawków" instead of "2 skrawki".

Use Q_() and pass splittable_into as the count, so that gettext can pick the form that fits the number.

Translators of a language with just a singular and a plural form, such as German, now have to translate this message twice. In exchange, translators of languages that need different forms for "2 hunks" and "5 hunks" can get them right.

---

Notes:
Changes since v1:

- Replaced the last sentence ("keeping the English output unchanged") with the trade-off for translators, as Junio suggested for a similar patch [1].
- Author and sign-off now use my real name instead of "aeron-gh".
- Rebased on current master. No code change.

The count is always 2 or more here, because "s" is only offered when hunk->splittable_into > 1, so English never shows the singular string. Q_() still needs it, and translators fill in their own forms for the counts that do occur.

[1] https://lore.kernel.org/git/[email protected]/

 add-patch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
add-patch.c +3 -1
index f27edcbe8d..4e75e2ceda 100644
@@ -1942,7 +1942,9 @@ static size_t patch_update_file(struct add_p_state *s,
 			} else if (!split_hunk(s, file_diff,
 					     hunk - file_diff->hunk)) {
 				color_fprintf_ln(stdout, s->cfg.header_color,
-						 _("Split into %d hunks."),
+						 Q_("Split into %d hunk.",
+						    "Split into %d hunks.",
+						    splittable_into),
 						 (int)splittable_into);
 				rendered_hunk_index = -1;
 			}
Signature · 1 line
2.56.0