Skip to content

Commit d95b83b

Browse files
committed
Enhance error when locale fails to setup
1 parent efc2942 commit d95b83b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
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

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)