ruff
ruff copied to clipboard
Ensure Ruff Format handles gettext comments correctly
issue
Python code using gettext comments can associate in-line comments with gettext. Like this:
# Translators: foo is programming term to represent a sample string
_("Foo")
_(
# Translators: foo is programming term to represent a sample string
"Foo"
)
pgettext(
"sampleStrings",
# Translators: foo is programming term to represent a sample string
"Foo"
)
ruff format
will reformat something like this
# Translators: foo is programming term to represent a sample string
(_("Foo"), "reallylongstringlongerthanlinelength")
# Translators: foo is programming term to represent a sample string
_("foo, reallylongstringlongerthanlinelength")
# Translators: foo is programming term to represent a sample string
pgettext("tag", "foo, reallylongstringlongerthanlinelength")
to
# Translators: foo is programming term to represent a sample string
(
_("Foo"),
"reallylongstringlongerthanlinelength"
)
# Translators: foo is programming term to represent a sample string
_(
"foo, reallylongstringlongerthanlinelength"
)
# Translators: foo is programming term to represent a sample string
pgettext(
"tag",
"foo, reallylongstringlongerthanlinelength"
)
instead of the expected
(
# Translators: foo is programming term to represent a sample string
_("Foo"),
"reallylongstringlongerthanlinelength"
)
_(
# Translators: foo is programming term to represent a sample string
"foo, reallylongstringlongerthanlinelength"
)
pgettext(
"tag",
# Translators: foo is programming term to represent a sample string
"foo, reallylongstringlongerthanlinelength"
)
Suggested fix
expand the flake8-gettext
config to set a translator comment flag e.g. "Translators:"
If this is set, move any comments while formatting, to keep the comments on the line above the target string.
keywords
gettext, translators, translations, translate, i18n, l10n, format, comments
last tested ruff version
v0.5.0