diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 51ad0f4c..83bf298d 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -32,7 +32,6 @@ on: - environment-dev.yml - environment.yml - pyproject.toml - - setup.py - src/xscen/__init__.py - templates - tests/*.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c73b6a25..1be002f4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,8 +9,6 @@ on: - CHANGELOG.rst - README.rst - pyproject.toml - - setup.cfg - - setup.py - xscen/__init__.py pull_request: @@ -91,11 +89,7 @@ jobs: esmf=${{ env.esmf-version }} mamba python=${{ matrix.python-version }} - babel tox - - name: Compile catalogs - run: | - make translate - name: Test with tox run: | python -m tox -e ${{ matrix.tox-build }} @@ -104,9 +98,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_FLAG_NAME: run-Python${{ matrix.python-version }} - # - name: Compile language catalogs -# run: | -# make translate # - name: Install esmpy # run: | # pip install git+https://github.com/esmf-org/esmf.git@v${{ matrix.esmf-version }}#subdirectory=src/addon/esmpy diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 8427f5e4..69a70300 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -35,10 +35,9 @@ jobs: python-version: "3.x" - name: Install packaging libraries run: | - python -m pip install babel build setuptools wheel + python -m pip install build setuptools wheel - name: Build a binary wheel and a source tarball run: | - make translate python -m build --sdist --wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0 diff --git a/.github/workflows/tag-testpypi.yml b/.github/workflows/tag-testpypi.yml index 867f7496..006dd230 100644 --- a/.github/workflows/tag-testpypi.yml +++ b/.github/workflows/tag-testpypi.yml @@ -59,10 +59,9 @@ jobs: python-version: "3.x" - name: Install packaging libraries run: | - python -m pip install babel build setuptools wheel + python -m pip install build setuptools wheel - name: Build a binary wheel and a source tarball run: | - make translate python -m build --sdist --wheel - name: Publish distribution 📦 to Test PyPI uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 3da6f88a..d3f25db1 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -8,8 +8,6 @@ on: - CHANGELOG.rst - README.rst - pyproject.toml - - setup.cfg - - setup.py - xscen/__init__.py schedule: - cron: "0 0 * * *" # Daily “At 00:00” UTC diff --git a/.gitignore b/.gitignore index f5bcdf03..36c14155 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ docs/notebooks/samples/example* docs/notebooks/samples/gs-weights/ !docs/notebooks/samples/tutorial/*/*/*/*/*/*/*/*.nc +# Translation stuff +*.pot + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -61,10 +64,6 @@ coverage.xml .hypothesis/ .pytest_cache/ -# Translations -*.mo -*.pot - # Django stuff: *.log local_settings.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fd38857..a8de3b16 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,9 +11,7 @@ repos: rev: v4.6.0 hooks: - id: trailing-whitespace - exclude: setup.cfg - id: end-of-file-fixer - exclude: setup.cfg - id: debug-statements - id: mixed-line-ending - id: check-json diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ef43a327..703513c8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,7 @@ Internal changes * Added pins to `xarray`, `xclim`, `h5py`, and `netcdf4`. (:pull:`414`). * Add ``.zip`` and ``.zarr.zip`` as possible file extensions for Zarr datasets. (:pull:`426`). * Explicitly assign coords of multiindex in `xs.unstack_fill_nan`. (:pull:`427`). +* French translations are compiled offline. A new check ensures no PR are merged with missing messages. (:issue:`342`, :pull:`443`). v0.9.1 (2024-06-04) ------------------- diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b8ead9d5..6c0280dc 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -203,7 +203,7 @@ Once the code is implemented and translatable strings are marked as such, we nee $ make findfrench -Then go edit ``xscen/xscen/data/fr/LC_MESSAGES/xscen.po`` with the correct French translations. Finally, running:: +Then go edit ``xscen/xscen/data/fr/LC_MESSAGES/xscen.po`` with the correct French translations. Finally, run:: $ make translate diff --git a/MANIFEST.in b/MANIFEST.in index 75611f22..070cdb41 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,15 +5,13 @@ include LICENSE include Makefile include README.rst include pyproject.toml -include setup.cfg -include setup.py include .zenodo.json recursive-include src/xscen *.py *.yml recursive-include src/xscen/CVs *.json recursive-include src/xscen/data/fr *.yml *.csv recursive-include src/xscen/data *.nc -recursive-include src/xscen/data/fr/LC_MESSAGES *.mo *.po +recursive-include src/xscen/data *.mo *.po recursive-include tests *.py recursive-include docs conf.py Makefile make.bat *.png *.rst *.yml recursive-include docs/locales *.mo *.po diff --git a/Makefile b/Makefile index b4db756a..7beb153c 100644 --- a/Makefile +++ b/Makefile @@ -110,8 +110,15 @@ dev: clean ## install the package in editable mode with all development dependen pre-commit install findfrench: ## Extract phrases and update the French translation catalog (this doesn't translate) - python setup.py extract_messages - python setup.py update_catalog -l fr + pybabel extract -o src/xscen/data/messages.pot --omit-header --input-dirs=src/xscen/ + pybabel update -l fr -D xscen -i src/xscen/data/messages.pot -d src/xscen/data/ --omit-header translate: ## Compile the translation catalogs. - python setup.py compile_catalog + pybabel compile -f -D xscen -d src/xscen/data/ + +checkfrench: ## Error if the catalog could be update or if the compilation is older than the catalog. + rm -f .check_messages.pot + pybabel extract -o .check_messages.pot --omit-header --input-dirs=src/xscen/ + pybabel update -l fr -D xscen -i .check_messages.pot -d src/xscen/data/ --omit-header --check + rm -f .check_messages.pot + if [ src/xscen/data/fr/LC_MESSAGES/xscen.mo -ot src/xscen/data/fr/LC_MESSAGES/xscen.po ]; then echo "Compilation is older than translations. Please compile with 'make translate'."; exit 1; fi diff --git a/environment-dev.yml b/environment-dev.yml index 149a058f..1e3332af 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -3,7 +3,7 @@ channels: - conda-forge dependencies: - python >=3.9,<3.13 - # Don't forget to sync changes between environment.yml, environment-dev.yml, and setup.py! + # Don't forget to sync changes between environment.yml, environment-dev.yml, and pyproject.toml! # Also consider updating the list in xs.utils.show_versions if you add a new package. # Main packages - cartopy >=0.23.0 diff --git a/environment.yml b/environment.yml index 8d2d86e0..5b98d8f4 100644 --- a/environment.yml +++ b/environment.yml @@ -3,7 +3,7 @@ channels: - conda-forge dependencies: - python >=3.9,<3.13 - # Don't forget to sync changes between environment.yml, environment-dev.yml, and setup.py! + # Don't forget to sync changes between environment.yml, environment-dev.yml, and pyproject.toml! # Also consider updating the list in xs.utils.show_versions if you add a new package. # Main packages - cartopy >=0.23.0 @@ -33,8 +33,7 @@ dependencies: - xclim >=0.50, <0.51 - xesmf >=0.7 - zarr - # To install from source and get translations - - babel + # To install from source - setuptools >=65.0.0 - setuptools-scm >=8.0.0 # Opt diff --git a/pyproject.toml b/pyproject.toml index 446547ab..7e7c3623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,6 @@ requires = [ "setuptools >=65.0.0", "setuptools-scm >=8.0", - "babel", "wheel" ] build-backend = "setuptools.build_meta" @@ -35,7 +34,6 @@ classifiers = [ ] dynamic = ["version"] dependencies = [ - "babel", "cartopy >=0.23.0", "cftime", "cf_xarray >=0.7.6", @@ -71,6 +69,7 @@ dependencies = [ dev = [ # Dev tools and testing "pip >=23.3.0", + "babel", "black[jupyter] ==24.4.2", "blackdoc ==0.3.9", "bump-my-version >=0.18.3", @@ -286,8 +285,6 @@ include = ["xscen"] # "docs/notebooks/samples/*.yml", # "environment.yml", # "environment-dev.yml", -# "setup.cfg", -# "setup.py", # "src/xscen/**/*.py", # "src/xscen/**/*.yml", # "src/xscen/CVs/*.json", diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 34d9e7ba..00000000 --- a/setup.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[extract_messages] -output_file = xscen.pot -keywords = _ gettext ngettext - -[init_catalog] -domain = xscen -input_file = xscen.pot -output_dir = src/xscen/data - -[update_catalog] -domain = xscen -input_file = xscen.pot -output_dir = src/xscen/data - -[compile_catalog] -domain = xscen -directory = src/xscen/data diff --git a/setup.py b/setup.py deleted file mode 100644 index 127a38be..00000000 --- a/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Custom installation process for xscen translations.""" - -from babel.messages.frontend import compile_catalog -from setuptools import setup -from setuptools.build_meta import * # noqa: F403, F401 -from setuptools.command.install import install - - -class InstallWithCompile(install): - """Injection of the catalog compilation in the installation process.""" - - def run(self): - """Install the package, but compile the i18n catalogs first.""" - compiler = compile_catalog(self.distribution) - option_dict = self.distribution.get_option_dict("compile_catalog") - compiler.domain = [option_dict["domain"][1]] - compiler.directory = option_dict["directory"][1] - compiler.run() - super().run() - - -setup( - cmdclass={"install": InstallWithCompile}, - message_extractors={"xscen": [("**.py", "python", None)]}, -) diff --git a/src/xscen/data/fr/LC_MESSAGES/xscen.mo b/src/xscen/data/fr/LC_MESSAGES/xscen.mo new file mode 100644 index 00000000..0c1c2619 Binary files /dev/null and b/src/xscen/data/fr/LC_MESSAGES/xscen.mo differ diff --git a/src/xscen/data/fr/LC_MESSAGES/xscen.po b/src/xscen/data/fr/LC_MESSAGES/xscen.po index e7d76e0a..027dae3f 100644 --- a/src/xscen/data/fr/LC_MESSAGES/xscen.po +++ b/src/xscen/data/fr/LC_MESSAGES/xscen.po @@ -1,51 +1,32 @@ -# French translations for xscen. -# Copyright (C) 2023 ORGANIZATION -# This file is distributed under the same license as the xscen project. -# Équipe Xscen , 2023. -# -msgid "" -msgstr "" -"Project-Id-Version: xscen 0.6.18b0\n" -"Report-Msgid-Bugs-To: Rondeau-Genesse.Gabriel@ouranos.ca\n" -"POT-Creation-Date: 2023-09-29 11:45-0400\n" -"PO-Revision-Date: 2023-08-15 16:48-0400\n" -"Last-Translator: Pascal Bourgault \n" -"Language: fr\n" -"Language-Team: fr \n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.12.1\n" - -#: xscen/aggregate.py:185 -msgid "{window}-year mean of {attr}." +#: src/xscen/aggregate.py:435 +#, fuzzy +msgid "{window}-year climatological {operation} of {attr}." msgstr "Moyenne {window} ans de {attr}." -#: xscen/aggregate.py:319 +#: src/xscen/aggregate.py:649 msgid "{attr1}: {kind} delta compared to {refhoriz}." msgstr "{attr1}: Delta {kind} comparé à {refhoriz}." -#: xscen/diagnostics.py:501 +#: src/xscen/diagnostics.py:522 msgid "Ranking of measure performance" msgstr "Classement de performance de la mesure" -#: xscen/diagnostics.py:560 +#: src/xscen/diagnostics.py:581 msgid "Fraction of improved grid cells" msgstr "Fraction de points de grille améliorés" -#: xscen/io.py:650 +#: src/xscen/io.py:761 src/xscen/io.py:769 msgid "Variable" msgstr "Variable" -#: xscen/io.py:650 +#: src/xscen/io.py:762 msgid "Description" msgstr "Description" -#: xscen/io.py:650 +#: src/xscen/io.py:765 msgid "Units" msgstr "Unités" -#: xscen/io.py:654 +#: src/xscen/io.py:770 msgid "Content" msgstr "Contenu" diff --git a/tox.ini b/tox.ini index 33eea6c9..fd3425f9 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ envlist = py{39,310,311,312} docs-esmpy requires = - babel pip >= 23.3.0 setuptools >= 65.0 opts = @@ -13,12 +12,13 @@ opts = --verbose [testenv:lint] -description = Check for Code Compliance +description = Check for Code Compliance and missing french translations skip_install = True download = true conda_channels = conda_env = deps = + babel black[jupyter] ==24.4.2 blackdoc ==0.3.9 isort ==5.13.2 @@ -30,6 +30,7 @@ commands_pre = pip list commands = make lint + make checkfrench allowlist_externals = make