Skip to content

Commit 07bb202

Browse files
committed
Use Babel to compile catalogues via tox.ini
1 parent a0c1bf2 commit 07bb202

11 files changed

Lines changed: 53 additions & 56 deletions

File tree

‎.github/CONTRIBUTING.md‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ tox -e py -- tests/test_number.py
1717
tox -e py -- tests/test_number.py -k intcomma
1818
```
1919

20-
Some localisation tests are skipped when compiled `.mo` translation files are missing.
21-
Generate them with `scripts/generate-translation-binaries.sh`, which requires Bash and
22-
GNU gettext's `msgfmt`. Translation-update tests also require `xgettext` and `msgmerge`.
23-
Use `tox -e py -- -rs` to see skip reasons.
24-
25-
CI generates translation binaries and runs the
26-
[configured tox environments](../tox.ini). See the [test workflow](workflows/test.yml)
27-
for supported Python versions and platforms.
20+
The tox test environments compile the `.mo` translation binaries from the `.po` catalogs
21+
before running the tests. When running `pytest` directly, some localisation tests are
22+
skipped if the `.mo` files are missing. Generate them with:
23+
24+
```sh
25+
tox -e compile-translations
26+
```
27+
28+
Translation-update tests also require GNU gettext's `xgettext` and `msgmerge`. Use
29+
`tox -e py -- -rs` to see skip reasons.
30+
31+
CI runs the [configured tox environments](../tox.ini). See the
32+
[test workflow](workflows/test.yml) for supported Python versions and platforms.
2833

2934
## Linting
3035

‎.github/workflows/actions.lock‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ workflows:
66
'.github/workflows/benchmark.yml':
77
- 'actions/checkout@v7.0.1'
88
- 'actions/setup-python@v7.1.0'
9+
- 'astral-sh/setup-uv@v10.3.2'
910
- 'codspeedhq/action@v5.6.0'
1011
'.github/workflows/docs.yml':
1112
- 'actions/checkout@v7.0.1'
@@ -28,6 +29,7 @@ workflows:
2829
'.github/workflows/release.yml':
2930
- 'actions/checkout@v7.0.1'
3031
- 'actions/download-artifact@v8.0.2'
32+
- 'astral-sh/setup-uv@v10.3.2'
3133
- 'hynek/build-and-inspect-python-package@v3.0.2'
3234
- 'pypa/gh-action-pypi-publish@v1.14.3'
3335
'.github/workflows/require-pr-label.yml':

‎.github/workflows/benchmark.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ jobs:
2222
python-version: "3.15"
2323
allow-prereleases: true
2424

25-
- name: Install gettext
26-
run: |
27-
sudo apt install gettext
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v10.3.2
2827

29-
- name: Generate translation binaries
28+
- name: Compile translations
3029
run: |
31-
scripts/generate-translation-binaries.sh
30+
uvx --with tox-uv tox -e compile-translations
3231
3332
- name: Install dependencies
3433
run: pip install -e ".[tests]"

‎.github/workflows/release.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ jobs:
2828
fetch-depth: 0
2929
persist-credentials: false
3030

31-
- name: Install gettext
32-
run: |
33-
sudo apt install gettext
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v10.3.2
3433

35-
- name: Generate translation binaries
34+
- name: Compile translations
3635
run: |
37-
scripts/generate-translation-binaries.sh
36+
uvx --with tox-uv tox -e compile-translations
3837
3938
- uses: hynek/build-and-inspect-python-package@v3.0.2
4039

‎.github/workflows/test.yml‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,9 @@ jobs:
4242
run: |
4343
echo "PYTHON_GIL=0" >> "$GITHUB_ENV"
4444
45-
- name: Install Linux dependencies
46-
if: startsWith(matrix.os, 'ubuntu')
47-
run: |
48-
sudo apt install gettext
49-
50-
- name: Install macOS dependencies
51-
if: startsWith(matrix.os, 'macos')
52-
run: |
53-
brew install gettext
54-
5545
- name: Install uv
5646
uses: astral-sh/setup-uv@v10.3.2
5747

58-
- name: Generate translation binaries
59-
run: |
60-
scripts/generate-translation-binaries.sh
61-
6248
- name: Tox tests
6349
run: |
6450
uvx --python ${{ matrix.python-version }} --with tox-uv tox -e py

‎scripts/generate-translation-binaries.sh‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎src/humanize/locale/ar/LC_MESSAGES/humanize.po‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ msgstr ""
1212
"PO-Revision-Date: 2026-04-07 22:42+0300\n"
1313
"Last-Translator: AYMENJD <let.me.code.safe@gmail.com>\n"
1414
"Language-Team: Arabic <let.me.code.safe@gmail.com>\n"
15-
"Language: Arabic (عربي)\n"
15+
"Language: ar\n"
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"

‎src/humanize/locale/sk_SK/LC_MESSAGES/humanize.po‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# This file is distributed under the same license as the PACKAGE package.
44
# Jose Riha <jose1711 gmail com>, 2016.
55
#
6-
#, fuzzy
76
msgid ""
87
msgstr ""
98
"Project-Id-Version: humanize\n"
@@ -12,7 +11,7 @@ msgstr ""
1211
"PO-Revision-Date: 2020-09-29 22:43+0300\n"
1312
"Last-Translator: Jose Riha <jose1711 gmail com>\n"
1413
"Language-Team: sk <LL@li.org>\n"
15-
"Language: Slovak\n"
14+
"Language: sk\n"
1615
"MIME-Version: 1.0\n"
1716
"Content-Type: text/plain; charset=UTF-8\n"
1817
"Content-Transfer-Encoding: 8bit\n"

‎src/humanize/locale/uk_UA/LC_MESSAGES/humanize.po‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ msgstr ""
33
"Project-Id-Version: PROJECT VERSION\n"
44
"Report-Msgid-Bugs-To: \n"
55
"POT-Creation-Date: 2026-11-12 12:11+0200\n"
6-
"PO-Revision-Date: \n"
6+
"PO-Revision-Date: 2020-03-22 15:17+0200\n"
77
"Last-Translator: TL\n"
88
"Language-Team: uk_UA\n"
99
"Language: uk\n"

‎tests/test_i18n.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_i18n() -> None:
102102
assert humanize.naturaltime(in_three_days, when=NOW) == "3 gün sonra"
103103

104104
except FileNotFoundError:
105-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
105+
pytest.skip("Generate .mo with tox -e compile-translations")
106106

107107
finally:
108108
humanize.i18n.deactivate()
@@ -127,7 +127,7 @@ def test_naturaltime_persian(seconds: int, expected: str) -> None:
127127
value = NOW + dt.timedelta(seconds=seconds)
128128
assert humanize.naturaltime(value, when=NOW) == expected
129129
except FileNotFoundError:
130-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
130+
pytest.skip("Generate .mo with tox -e compile-translations")
131131
finally:
132132
humanize.deactivate()
133133

@@ -161,7 +161,7 @@ def test_intcomma() -> None:
161161
assert humanize.intcomma("1.234.567,89") == "1.234.567,89"
162162

163163
except FileNotFoundError:
164-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
164+
pytest.skip("Generate .mo with tox -e compile-translations")
165165

166166
finally:
167167
humanize.i18n.deactivate()
@@ -180,7 +180,7 @@ def test_naturaldelta() -> None:
180180
assert humanize.naturaldelta(seconds) == "1,234 años"
181181

182182
except FileNotFoundError:
183-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
183+
pytest.skip("Generate .mo with tox -e compile-translations")
184184

185185
finally:
186186
humanize.i18n.deactivate()
@@ -270,7 +270,7 @@ def test_intword_i18n(locale: str, number: int, expected_result: str) -> None:
270270
try:
271271
humanize.i18n.activate(locale)
272272
except FileNotFoundError:
273-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
273+
pytest.skip("Generate .mo with tox -e compile-translations")
274274
else:
275275
assert humanize.intword(number) == expected_result
276276
finally:
@@ -301,7 +301,7 @@ def test_naturalsize_i18n(locale: str, value: float, expected_result: str) -> No
301301
try:
302302
humanize.i18n.activate(locale)
303303
except FileNotFoundError:
304-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
304+
pytest.skip("Generate .mo with tox -e compile-translations")
305305
else:
306306
assert humanize.naturalsize(value) == expected_result
307307
finally:
@@ -312,7 +312,7 @@ def test_naturalsize_i18n_binary() -> None:
312312
try:
313313
humanize.i18n.activate("fr_FR")
314314
except FileNotFoundError:
315-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
315+
pytest.skip("Generate .mo with tox -e compile-translations")
316316
else:
317317
assert humanize.naturalsize(3000, binary=True) == "2.9 Kio"
318318
finally:
@@ -334,7 +334,7 @@ def test_naturaldelta_one_year_i18n(
334334
try:
335335
humanize.i18n.activate(locale)
336336
except FileNotFoundError:
337-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
337+
pytest.skip("Generate .mo with tox -e compile-translations")
338338
else:
339339
assert humanize.naturaldelta(dt.timedelta(days=days)) == expected_result
340340
finally:
@@ -357,7 +357,7 @@ def test_langauge_codes(locale: str, expected_result: str) -> None:
357357
try:
358358
humanize.i18n.activate(locale)
359359
except FileNotFoundError:
360-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
360+
pytest.skip("Generate .mo with tox -e compile-translations")
361361
else:
362362
assert humanize.ordinal(5) == expected_result
363363
finally:
@@ -382,7 +382,7 @@ def test_ordinal_genders(
382382
try:
383383
humanize.i18n.activate(locale)
384384
except FileNotFoundError:
385-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
385+
pytest.skip("Generate .mo with tox -e compile-translations")
386386
else:
387387
assert humanize.ordinal(number, gender=gender) == expected_result
388388
finally:
@@ -455,7 +455,7 @@ def test_none_locale(self) -> None:
455455
test_str = humanize.naturaltime(three_seconds)
456456
assert test_str == "3 seconds ago"
457457
except FileNotFoundError:
458-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
458+
pytest.skip("Generate .mo with tox -e compile-translations")
459459

460460
finally:
461461
humanize.i18n.deactivate()
@@ -472,6 +472,6 @@ def test_intword_unit_has_no_format_placeholder(locale: str) -> None:
472472
for value in (1_000, 1_000_000, 1_000_000_000, 10**12, 10**15, 10**100):
473473
assert "%" not in humanize.intword(value)
474474
except FileNotFoundError:
475-
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
475+
pytest.skip("Generate .mo with tox -e compile-translations")
476476
finally:
477477
humanize.i18n.deactivate()

0 commit comments

Comments
 (0)