Skip to content

Commit

Permalink
Merge pull request #199 from hugovk/generate-translation-binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Apr 25, 2021
2 parents 98fafaf + a759892 commit fb2daf3
Show file tree
Hide file tree
Showing 27 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -42,12 +42,26 @@ jobs:
restore-keys: |
${{ matrix.os }}-${{ matrix.python-version }}-v1-
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt install gettext
- name: Install macOS dependencies
if: startsWith(matrix.os, 'macos')
run: |
brew install gettext
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install -U tox
- name: Generate translation binaries
run: |
scripts/generate-translation-binaries.sh
- name: Tox tests
run: |
tox -e py
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.egg-info*
*.mo
*.pot
*.py[co]
*.sw[po]
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
recursive-include src/humanize/locale *.mo
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -199,7 +199,6 @@ How to add new phrases to existing locale files:
```console
$ xgettext --from-code=UTF-8 -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -l python src/humanize/*.py # extract new phrases
$ msgmerge -U src/humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files
$ msgfmt --check -o src/humanize/locale/ru_RU/LC_MESSAGES/humanize{.mo,.po} # compile to binary .mo
```

How to add a new locale:
Expand Down
6 changes: 6 additions & 0 deletions RELEASING.md
Expand Up @@ -14,6 +14,12 @@ git clone https://github.com/jmoiron/humanize
cd humanize
```

* [ ] Generate translation binaries:

```bash
scripts/generate-translation-binaries.sh
```

* [ ] (Optional) Create a distribution and release on **TestPyPI**:

```bash
Expand Down
8 changes: 8 additions & 0 deletions scripts/generate-translation-binaries.sh
@@ -0,0 +1,8 @@
set -e

for d in src/humanize/locale/*/; do
locale="$(basename $d)"
echo "$locale"
# compile to binary .mo
msgfmt --check -o src/humanize/locale/$locale/LC_MESSAGES/humanize{.mo,.po}
done
Binary file removed src/humanize/locale/ca_ES/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/de_DE/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/es_ES/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/fa_IR/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/fi_FI/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/fr_FR/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/id_ID/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/it_IT/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/ja_JP/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/ko_KR/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/pl_PL/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/pt_BR/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/pt_PT/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/ru_RU/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/sk_SK/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/tr_TR/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/uk_UA/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/vi_VI/LC_MESSAGES/humanize.mo
Binary file not shown.
Binary file removed src/humanize/locale/zh_CN/LC_MESSAGES/humanize.mo
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_i18n.py
Expand Up @@ -20,6 +20,9 @@ def test_i18n():
assert humanize.ordinal(5) == "5ый"
assert humanize.precisedelta(one_min_three_seconds) == "1 минута и 7 секунд"

except FileNotFoundError:
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")

finally:
humanize.i18n.deactivate()
assert humanize.naturaltime(three_seconds) == "3 seconds ago"
Expand All @@ -36,6 +39,9 @@ def test_intcomma():
humanize.i18n.activate("fr_FR")
assert humanize.intcomma(number) == "10 000 000"

except FileNotFoundError:
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")

finally:
humanize.i18n.deactivate()
assert humanize.intcomma(number) == "10,000,000"
Expand Down

0 comments on commit fb2daf3

Please sign in to comment.