Aarni Koskela [Wed, 15 Jan 2025 13:01:58 +0000 (15:01 +0200)]
Small test cleanup (#1172)
* Configure Ruff formatter to preserve quotes for now
* Split support functionality tests to a separate modules
* Use standard `monkeypatch` fixture for `os.environ` patching
* Use even more `monkeypatch` for patching
Dylan Kiss [Sat, 19 Oct 2024 12:17:36 +0000 (14:17 +0200)]
Fix extracted lineno with nested calls (#1126)
When a gettext call had a nested function call on a new line, the
extract function would use that nested call's line number when
extracting the terms for the gettext call.
The reason is that we set the line number on any encounter of an opening
parenthesis after a gettext keyword. This does not work if either we
have a nested call, or our first term starts on a new line.
This commit fixes that by only setting the line number when we encounter
the first argument inside a gettext call.
Existing tests were adapted to work according to `xgettext` with regards
to the line numbers.
Daniel Roschka [Wed, 4 Sep 2024 15:58:12 +0000 (17:58 +0200)]
Enclose white spaces in references (#1105)
Since version 0.22 gettext encloses file names in references which
contain white spaces or tabs within First Strong Isolate (U+2068) and
Pop Directional Isolate (U+2069). This commit adds the same behavior for
Babel.
Aarni Koskela [Wed, 7 Aug 2024 08:14:34 +0000 (11:14 +0300)]
Do not allow substituting alternates or drafts in derived locales (#1113)
* download_import_cldr.py: pass remaining arguments through to import_cldr
* Do not allow substituting alternates or drafts in derived locales
For more coverage, we've allowed using alternate or draft values
when no officially accepted values have been present.
However, non-global (i.e. e.g. `de_CH` locales) may have an alternate
spelling for what would be an alternate in the parent locale (and
that alternate hasn't been imported into the parent), and the import
would have then accepted the alternate from the child locale as a
non-alternate.
Allow use of importlib.metadata for finding entrypoints (#1102)
* Support importlib.metadata for finding entrypoints
* Add a basic interoperability test for Jinja2 extraction
* Only use importlib.metadata on Python 3.10+
Avoid crashing on importing `babel.localtime` when TZ envvar is malformed (#1100)
When `pytz` is _not_ installed, importing `babel.localtime` could fail
(repeatedly) when the `TZ` environment variable is malformed enough to be
caught by `_validate_tzfile_path`, which might throw a certain `ValueError`.
(When `pytz` is installed, it would raise an `UnknownTimeZoneError` we
already catch and ignore for the same sort of input.)
Tomas R [Thu, 11 Jul 2024 06:11:04 +0000 (08:11 +0200)]
Make pgettext search plurals when translation is not found (#1085)
pgettext can now find the following translation
when using `pgettext("ctx", "foo")`:
```
msgctxt "ctx"
msgid "foo"
msgid_plural "foos"
msgstr[0] "foo translated"
```
The upstream CPython PR is https://github.com/python/cpython/pull/107118
Tomas R [Thu, 11 Jul 2024 06:10:19 +0000 (08:10 +0200)]
Upgrade to CLDR 45 (#1077)
* Upgrade to CLDR 45
* Handle 'localeRules="nonlikelyScript"' for parent locales
Locales of the form 'lang_Script' where 'Script' is not the
likely script for 'lang' should have 'root' as their parent
locale. For example, the parent of 'az_Arab' should not be
computed as 'az' by truncating from the end, but should be
'root' instead as 'Arab' is not the likely script for 'az'.
The list of such languages was previously specified using
an explicit 'locales' attribute. It is now handled dynamically
using the new 'localeRules' attribute.
Allow alternative space characters as group separator when parsing numbers (#1007)
The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).
The issue was partially adressed earlier in https://github.com/python-babel/babel/issues/637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.
This commit goes further by changing both `parse_number` and `parse_decimal`
to allow certain other space characters when the group character is itself a space character,
but is not present in the string to parse.