Marco Ricci commited on 2025-01-13 23:28:32
Zeige 2 geänderte Dateien mit 35 Einfügungen und 2 Löschungen.
Use examples in doctests where it makes didactical sense.
| ... | ... |
@@ -122,7 +122,8 @@ class DebugTranslations(gettext.NullTranslations): |
| 122 | 122 |
plural = v.plural |
| 123 | 123 |
context = v.l10n_context |
| 124 | 124 |
cache.setdefault((context, singular), (member, trimmed)) |
| 125 |
- if plural: |
|
| 125 |
+ # Currently no translatable messages use plural forms |
|
| 126 |
+ if plural: # pragma: no cover |
|
| 126 | 127 |
cache.setdefault((context, plural), (member, trimmed)) |
| 127 | 128 |
|
| 128 | 129 |
@classmethod |
| ... | ... |
@@ -260,7 +261,8 @@ class TranslatableString(NamedTuple): |
| 260 | 261 |
c, sep2, d = self.plural.partition(filename_str) |
| 261 | 262 |
if sep1: |
| 262 | 263 |
ret = ret._replace(singular=(a + b)) |
| 263 |
- if sep2: |
|
| 264 |
+ # Currently no translatable messages use plural forms |
|
| 265 |
+ if sep2: # pragma: no cover |
|
| 264 | 266 |
ret = ret._replace(plural=(c + d)) |
| 265 | 267 |
return ret |
| 266 | 268 |
|
| ... | ... |
@@ -312,6 +314,36 @@ class TranslatableString(NamedTuple): |
| 312 | 314 |
The flags failed to validate. See the exact error |
| 313 | 315 |
message for details. |
| 314 | 316 |
|
| 317 |
+ Examples: |
|
| 318 |
+ >>> TranslatableString('', 'all OK').validate_flags()
|
|
| 319 |
+ ... # doctest: +NORMALIZE_WHITESPACE |
|
| 320 |
+ TranslatableString(l10n_context='', singular='all OK', plural='', |
|
| 321 |
+ flags=frozenset(), translator_comments='') |
|
| 322 |
+ >>> TranslatableString('', '20% OK').validate_flags(
|
|
| 323 |
+ ... 'no-python-format' |
|
| 324 |
+ ... ) |
|
| 325 |
+ ... # doctest: +NORMALIZE_WHITESPACE |
|
| 326 |
+ TranslatableString(l10n_context='', singular='20% OK', plural='', |
|
| 327 |
+ flags=frozenset({'no-python-format'}),
|
|
| 328 |
+ translator_comments='') |
|
| 329 |
+ >>> TranslatableString('', '%d items').validate_flags()
|
|
| 330 |
+ ... # doctest: +ELLIPSIS |
|
| 331 |
+ Traceback (most recent call last): |
|
| 332 |
+ ... |
|
| 333 |
+ ValueError: Missing flag for how to deal with percent character ... |
|
| 334 |
+ >>> TranslatableString('', '{braces}').validate_flags()
|
|
| 335 |
+ ... # doctest: +ELLIPSIS |
|
| 336 |
+ Traceback (most recent call last): |
|
| 337 |
+ ... |
|
| 338 |
+ ValueError: Missing flag for how to deal with brace character ... |
|
| 339 |
+ >>> TranslatableString('', 'no braces').validate_flags(
|
|
| 340 |
+ ... 'python-brace-format' |
|
| 341 |
+ ... ) |
|
| 342 |
+ ... # doctest: +ELLIPSIS |
|
| 343 |
+ Traceback (most recent call last): |
|
| 344 |
+ ... |
|
| 345 |
+ ValueError: Missing format string parameters ... |
|
| 346 |
+ |
|
| 315 | 347 |
""" |
| 316 | 348 |
all_flags = frozenset( |
| 317 | 349 |
f.strip() for f in self.flags.union(extra_flags) |
| 318 | 350 |