Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove generated translation binaries from repo #199

Merged
merged 4 commits into from Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only comment is that if msgfmt --check fails, for example if in the translation of the string "%d months" you forget the "%d", then this should stop and get fixed. You may need to check the exit code and act accordinly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I checked it in another branch. A change like this:

diff --git a/src/humanize/locale/ca_ES/LC_MESSAGES/humanize.po b/src/humanize/locale/ca_ES/LC_MESSAGES/humanize.po
index 5e6a4f2..abdc464 100644
--- a/src/humanize/locale/ca_ES/LC_MESSAGES/humanize.po
+++ b/src/humanize/locale/ca_ES/LC_MESSAGES/humanize.po
@@ -221,8 +221,8 @@ msgstr "un mes"
 #, python-format
 msgid "%d month"
 msgid_plural "%d months"
-msgstr[0] "%d mes"
-msgstr[1] "%d mesos"
+msgstr[0] "mes"
+msgstr[1] "mesos"

 #: src/humanize/time.py:174
 msgid "a year"

hugovk/humanize@cfa2788

Fails on the CI like this:

Run scripts/generate-translation-binaries.sh
ca_ES
src/humanize/locale/ca_ES/LC_MESSAGES/humanize.po:224: number of format specifications in 'msgid_plural' and 'msgstr[0]' does not match
msgfmt: found 2 fatal errors
Error: Process completed with exit code 1.

https://github.com/hugovk/humanize/runs/2431670085?check_suite_focus=true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Thanks!

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