Some minor rephrasing to i18n doc; also removing recommendation to use %s style

This commit is contained in:
Griatch 2025-04-26 12:30:56 +02:00
parent e96878f538
commit bf06a41d36
2 changed files with 6 additions and 8 deletions

View file

@ -173,7 +173,7 @@ string = _("Text to translate")
### Formatting Considerations
When using formatted strings, ensure that you pass the "raw" string to `gettext` for translation first and then format the output. Otherwise, placeholders will be replaced before translation occurs, preventing the correct string from being found in the `.po` file.
When using formatted strings, ensure that you pass the "raw" string to `gettext` for translation first and then format the output. Otherwise, placeholders will be replaced before translation occurs, preventing the correct string from being found in the `.po` file. It's also recommended to use named placeholders (e.g., `{char}`) instead of positional ones (e.g., `{}`) for better readability and maintainability.
```python
# incorrect:
@ -189,9 +189,3 @@ This is also why f-strings don't work with `gettext`:
# will not work
string = _(f"Hello {char}!")
```
However, you can use %-formatting. Its recommended to use named placeholders because the order of placeholders may vary in different translations.
```python
_("Today is %(month)s %(day)s.") % {"month": m, "day": d}
```