From e62301091de8c6da45ab4a9d09080ba88229d2d0 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Wed, 15 Jan 2025 22:20:25 +0100 Subject: [PATCH] [5.2.x] Fixed #36102 -- Moved i18n comments directly above the translatable string. xgettext only extracts comment blocks if there is no program code between the comment and the string that gets extracted. For details, see: https://www.gnu.org/software/gettext/manual/html_node/xgettext-Invocation.html#Operation-mode Black formatting has been turned off in some places to ensure the comments are not moved, which previously resulted in them being removed from the po files when scripts/manage_translations.py was run. Backport of 6fcd0440aaa7601aa258d1c956eecfaedf72fbf4 from main. --- .../contrib/humanize/templatetags/humanize.py | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 174e367a69..2e3f133033 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -223,29 +223,36 @@ class NaturalTimeFormatter: # and time unit. "past-second": ngettext_lazy("a second ago", "%(count)s seconds ago", "count"), "now": gettext_lazy("now"), - # Translators: please keep a non-breaking space (U+00A0) between count - # and time unit. + # fmt: off + # fmt turned off to avoid black splitting the ngettext_lazy calls to multiple + # lines, as this results in gettext missing the 'Translators:' comments. "future-second": ngettext_lazy( + # Translators: please keep a non-breaking space (U+00A0) between count + # and time unit. "a second from now", "%(count)s seconds from now", "count" ), - # Translators: please keep a non-breaking space (U+00A0) between count - # and time unit. "future-minute": ngettext_lazy( - "a minute from now", "%(count)s minutes from now", "count" + # Translators: please keep a non-breaking space (U+00A0) between count + # and time unit. + "a minute from now", "%(count)s minutes from now", "count", ), - # Translators: please keep a non-breaking space (U+00A0) between count - # and time unit. "future-hour": ngettext_lazy( - "an hour from now", "%(count)s hours from now", "count" + # Translators: please keep a non-breaking space (U+00A0) between count + # and time unit. + "an hour from now", "%(count)s hours from now", "count", ), + # fmt: on # Translators: delta will contain a string like '2 months' or '1 month, 2 weeks' "future-day": gettext_lazy("%(delta)s from now"), } past_substrings = { - # Translators: 'naturaltime-past' strings will be included in '%(delta)s ago' + # fmt: off "year": npgettext_lazy( - "naturaltime-past", "%(num)d year", "%(num)d years", "num" + # Translators: 'naturaltime-past' strings will be included in + # '%(delta)s ago' + "naturaltime-past", "%(num)d year", "%(num)d years", "num", ), + # fmt:on "month": npgettext_lazy( "naturaltime-past", "%(num)d month", "%(num)d months", "num" ), @@ -261,11 +268,13 @@ class NaturalTimeFormatter: ), } future_substrings = { - # Translators: 'naturaltime-future' strings will be included in - # '%(delta)s from now'. + # fmt: off "year": npgettext_lazy( - "naturaltime-future", "%(num)d year", "%(num)d years", "num" + # Translators: 'naturaltime-future' strings will be included in + # '%(delta)s from now'. + "naturaltime-future", "%(num)d year", "%(num)d years", "num", ), + # fmt: on "month": npgettext_lazy( "naturaltime-future", "%(num)d month", "%(num)d months", "num" ),