Skip to content

Commit 0feff56

Browse files
authored
Merge pull request #180 from openzim/enhance_locale_error
Enhance error when locale fails to setup
2 parents efc2942 + 5d3ee5a commit 0feff56

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
- Metadata length validation is buggy for unicode strings #158
2121
- Pillow 10.4.0 reveals improper type hints for image probing functions #177
22+
- Enhance error when locale fails to setup #157
2223

2324
## [3.4.0] - 2024-06-21
2425

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ zimscraperlib>=1.1,<1.2
3030
* Pillow
3131
* FFmpeg
3232
* gifsicle (>=1.92)
33+
* locale (with at least `fr_FR.UTF-8` and `pt_BR.utf8` locales installed for tests to pass)
3334

3435
## macOS
3536

@@ -51,7 +52,7 @@ sudo apt install libmagic1 wget ffmpeg \
5152
apk add ffmpeg gifsicle libmagic wget libjpeg
5253
```
5354

54-
**Nota:** i18n features do not work on Alpine, see https://github.com/openzim/python-scraperlib/issues/134 ; there is one corresponding test which is failing.
55+
**Nota:** Alpine does not have `locale` support, so i18n features do not work on Alpine, see https://github.com/openzim/python-scraperlib/issues/134 ; there is one corresponding test which is failing.
5556

5657
# Contribution
5758

src/zimscraperlib/i18n.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ def setlocale(root_dir: pathlib.Path, locale_name: str):
5656
"""set the desired locale for gettext.
5757
5858
call this early"""
59-
return Locale.setup(root_dir / "locale", locale_name)
59+
try:
60+
return Locale.setup(root_dir / "locale", locale_name)
61+
except locale.Error as exc:
62+
raise locale.Error(
63+
f"Failed to setup '{locale_name}' locale. If this locale is not installed "
64+
"on this system, please install it first."
65+
) from exc
6066

6167

6268
def get_iso_lang_data(lang: str) -> tuple[dict, dict | None]:

0 commit comments

Comments
 (0)