From 0d9e7e2f0a59af9efd00ca39284dc743cdbca8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Sun, 9 May 2021 12:28:10 +0200 Subject: [PATCH] chore(i18n): migrate from POEditor to Weblate (#170) --- .github/workflows/release.yml | 23 ++-------------- .gitignore | 3 +- .scripts/build/getlangs.py | 52 ----------------------------------- CONTRIBUTING.md | 8 +++--- Makefile | 7 ++--- README.md | 9 +++++- 6 files changed, 17 insertions(+), 85 deletions(-) delete mode 100644 .scripts/build/getlangs.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52fb17a..0055195 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,12 +24,6 @@ jobs: changelog="${changelog//$'\n'/'%0A'}" changelog="${changelog//$'\r'/'%0D'}" echo "::set-output name=changelog::$changelog" - - name: Build locales - env: - POEDITOR_API_ACCESS: ${{ secrets.POEDITOR_API_ACCESS }} - run: | - make POEDITOR_API_ACCESS="${POEDITOR_API_ACCESS}" i18n - tar cf locales.tar.gz kosmorrolib/locales - name: Create release id: create_release uses: actions/create-release@v1 @@ -42,19 +36,8 @@ jobs: prerelease: false body: | ${{ steps.prepare_release.outputs.changelog }} - - name: Upload locales - id: upload-locales - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./locales.tar.gz - asset_name: locales.tar.gz - asset_content_type: application/x-tar - - pip: + pipy: name: Release to PyPI runs-on: ubuntu-latest steps: @@ -76,9 +59,7 @@ jobs: env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - POEDITOR_API_ACCESS: ${{ secrets.POEDITOR_API_ACCESS }} POEDITOR_PROJECT_ID: 306433 run: | - make POEDITOR_API_ACCESS="${POEDITOR_API_ACCESS}" POEDITOR_PROJECT_ID="306433" build + make i18n build twine upload dist/* - diff --git a/.gitignore b/.gitignore index 18127a2..b10abcb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,5 @@ coverage.xml /manpage/* !/manpage/*.md -# Translation files are taken care on https://poeditor.com/join/project/GXuhLpdaoh +# Compiled internationalization files *.mo -*.po diff --git a/.scripts/build/getlangs.py b/.scripts/build/getlangs.py deleted file mode 100644 index db6c11e..0000000 --- a/.scripts/build/getlangs.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 - -# This script's purpose is to retrieve the translations from POEditor (https://poeditor.com). -# It is mainly used in the release process. -# (c) Jérôme Deuchnord - MIT License - -import os -import requests - -POEDITOR_URL = 'https://api.poeditor.com/v2' -API_TOKEN = os.environ['POEDITOR_API_ACCESS'] -PROJECT_ID = os.environ['POEDITOR_PROJECT_ID'] - -languages = requests.post('%s/languages/list' % POEDITOR_URL, - data={'api_token': API_TOKEN, - 'id': PROJECT_ID}) - -json = languages.json() - -if languages.status_code != 200: - raise AssertionError(json['response']['message']) - -for language in json['result']['languages']: - if language['percentage'] < 100: - # Ignore unfinished translations - continue - - print('Importing finished translation for %s... ' % language['name'], end='') - - translations = requests.post('%s/projects/export' % POEDITOR_URL, - data={'api_token': API_TOKEN, - 'id': PROJECT_ID, - 'language': language['code'], - 'type': 'po'}) - - if translations.status_code != 200: - print('Failed!') - raise AssertionError(translations.json()['response']['message']) - - translations = requests.get(translations.json()['result']['url']) - - if translations.status_code != 200: - print('Failed!') - raise AssertionError('URL given by the API returned a %d status code' % translations.status_code) - - os.makedirs('kosmorrolib/locales/%s/LC_MESSAGES' % language['code'], exist_ok=True) - - with open('kosmorrolib/locales/%s/LC_MESSAGES/messages.po' % language['code'], 'w') as file: - file.write(translations.text) - - print('OK') - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4806fe9..dcbe743 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ First, please check someone didn't suggest your next revolution in the _Issues_ ## Translating -If you speak another language than English, another nice way to enhance Kosmorro is to translate its messages. The recommended way to begin translating Kosmorro is to [join the POEditor team](https://poeditor.com/join/project/GXuhLpdaoh). +If you speak another language than English, another nice way to enhance Kosmorro is to translate its messages. The recommended way to begin translating Kosmorro is to [join the Weblate project](https://hosted.weblate.org/engage/kosmorro/). ## Writing code @@ -44,7 +44,7 @@ The messages file contains all the messages Kosmorro can display, in order to ma When you add a new string that will be displayed to the end user, please pass it to the `_()` function made available in the `kosmorrolib.i18n` package, for instance: ```python -# Dont: +# Don't: print('Note: All the hours are given in UTC.') # Do: @@ -57,10 +57,10 @@ This will allow Python's internationalization tool to translate the string in an Once you have done your work, please remember to tell [Babel](http://babel.pocoo.org) to extract the new strings: ```console -$ pipenv run python setup.py extract_messages --output-file=kosmorrolib/locales/messages.pot +$ make messages ``` -> If the `setup.py` script tells you that the `extract_messages` command does not exist, then run `kosmorro sync` to ensure all the dev dependencies are installed and try again. +> If the `setup.py` script tells you that the `extract_messages` command does not exist, then run `pipenv sync` to ensure all the dev dependencies are installed and try again. Note that if you forget to update the messages file, the CI will fail. diff --git a/Makefile b/Makefile index 4e1892f..b69c07d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ test: unset KOSMORRO_TIMEZONE; \ LANG=C pipenv run python3 -m coverage run -m unittest test -build: i18n manpages +build: manpages python3 setup.py sdist bdist_wheel messages: @@ -19,10 +19,7 @@ manpages: ronn --roff manpage/kosmorro.7.md i18n: - if [ "$$POEDITOR_API_ACCESS" != "" ]; then \ - python3 .scripts/build/getlangs.py; \ - python3 setup.py compile_catalog; \ - fi + python3 setup.py compile_catalog; \ env: @if [[ "$$RELEASE_NUMBER" == "" ]]; \ diff --git a/README.md b/README.md index a34e7d3..7d39129 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ![Kosmorro](kosmorrolib/assets/png/kosmorro-logo.png) -[![Coverage Status](https://coveralls.io/repos/github/Kosmorro/kosmorro/badge.svg?branch=master)](https://coveralls.io/github/Kosmorro/kosmorro?branch=master) [![Version on PyPI](https://img.shields.io/pypi/v/kosmorro)](https://pypi.org/project/kosmorro) [![Discord](https://img.shields.io/discord/650237632533757965?logo=discord&label=%23kosmorro)](https://discord.gg/TVX4MSKGaa) ![Docker Pulls](https://img.shields.io/docker/pulls/kosmorro/kosmorro) +[![Coverage Status](https://coveralls.io/repos/github/Kosmorro/kosmorro/badge.svg?branch=master)](https://coveralls.io/github/Kosmorro/kosmorro?branch=master) [![Version on PyPI](https://img.shields.io/pypi/v/kosmorro)](https://pypi.org/project/kosmorro) [![Discord](https://img.shields.io/discord/650237632533757965?logo=discord&label=%23kosmorro)](https://discord.gg/TVX4MSKGaa) ![Docker Pulls](https://img.shields.io/docker/pulls/kosmorro/kosmorro) [![Help translating Kosmorro!](https://hosted.weblate.org/widgets/kosmorro/-/cli/svg-badge.svg)](https://hosted.weblate.org/engage/kosmorro/) A program that calculates your astronomical ephemerides! @@ -98,3 +98,10 @@ Before you use this feature, make sure you have installed a LaTeX distribution: - with Brew: `brew install basictex` These dependencies are not installed by default, because they take a lot of place and are not necessary if you are not interested in generating PDF files. + +## Help translating Kosmorro! + +Kosmorro is translated on [Weblate](https://hosted.weblate.org/engage/kosmorro/), a popular free platform for crowd-sourced internationalization. +If you speak a language that is not supported yet, feel free to contribute! + +![Translation state per language](https://hosted.weblate.org/widgets/kosmorro/-/cli/multi-auto.svg)