diff --git a/.github/workflows/transifex.yml b/.github/workflows/transifex.yml index 68d68d28a..e601c4c3d 100644 --- a/.github/workflows/transifex.yml +++ b/.github/workflows/transifex.yml @@ -1,8 +1,9 @@ -name: Sync translations on repository and transifex.com +name: Synchronise translations on: schedule: - - cron: "0 0 * * SUN" + # 22:38 GMT, every Sunday. Chosen to be a random time. + - cron: "38 22 * * SUN" workflow_dispatch: permissions: @@ -15,22 +16,25 @@ jobs: steps: - uses: actions/checkout@v3 - with: - ref: 5.x - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 # https://github.com/transifex/transifex-client/pull/330 + python-version: 3 + - name: Install transifex client + run: | + mkdir -p /tmp/tx_cli && cd $_ + curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash + shell: bash - name: Install dependencies - run: pip install -U babel jinja2 transifex-client - - name: Install Sphinx - run: pip install . + run: pip install --upgrade babel jinja2 - name: Extract translations from source code run: python utils/babel_runner.py extract - name: Push translations to transifex.com - run: cd sphinx/locale && tx push -s --no-interactive --parallel + run: | + cd sphinx/locale + /tmp/tx_cli/tx push --source --use-git-timestamps --workers 10 env: - TX_TOKEN: "${{ secrets.TX_TOKEN }}" + TX_TOKEN: ${{ secrets.TX_TOKEN }} pull: permissions: @@ -41,28 +45,31 @@ jobs: steps: - uses: actions/checkout@v3 - with: - ref: 5.x - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 # https://github.com/transifex/transifex-client/pull/330 + python-version: 3 + - name: Install transifex client + run: | + mkdir -p /tmp/tx_cli && cd $_ + curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash + shell: bash - name: Install dependencies - run: pip install -U babel jinja2 transifex-client - - name: Install Sphinx - run: pip install . + run: pip install --upgrade babel jinja2 - name: Extract translations from source code run: python utils/babel_runner.py extract - - name: Pull translations to transifex.com - run: cd sphinx/locale && tx pull -a -f --no-interactive --parallel + - name: Pull translations from transifex.com + run: | + cd sphinx/locale + /tmp/tx_cli/tx pull --translations --all --force --use-git-timestamps --workers 10 env: - TX_TOKEN: "${{ secrets.TX_TOKEN }}" + TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Compile message catalogs run: python utils/babel_runner.py compile - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: - commit-message: "Update message catalogs" + commit-message: "[internationalisation] Update translations" branch: bot/pull-translations - title: Update message catalogs - labels: i18n + title: [bot]: Update message catalogues + labels: "internals:internationalisation" diff --git a/sphinx/locale/.tx/config b/sphinx/locale/.tx/config index 598089e9f..11f13fb83 100644 --- a/sphinx/locale/.tx/config +++ b/sphinx/locale/.tx/config @@ -1,7 +1,7 @@ [main] host = https://www.transifex.com -[sphinx-1.sphinx-pot] +[o:sphinx-doc:p:sphinx-1:r:sphinx-pot] file_filter = /LC_MESSAGES/sphinx.po source_file = sphinx.pot source_lang = en diff --git a/utils/babel_runner.py b/utils/babel_runner.py index c9d583b1e..5e62efe86 100644 --- a/utils/babel_runner.py +++ b/utils/babel_runner.py @@ -31,8 +31,6 @@ from babel.messages.pofile import read_po, write_po from babel.util import pathmatch from jinja2.ext import babel_extract as extract_jinja2 -import sphinx - ROOT = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..")) TEX_DELIMITERS = { 'variable_start_string': '<%=', @@ -75,8 +73,16 @@ KEYWORDS = {**DEFAULT_KEYWORDS, '_': None, '__': None} def run_extract(): """Message extraction function.""" log = _get_logger() + + with open('sphinx/__init__.py', encoding='utf-8') as f: + for line in f.read().splitlines(): + if line.startswith('__version__ = '): + # remove prefix; strip whitespace; remove quotation marks + sphinx_version = line[14:].strip()[1:-1] + break + input_path = 'sphinx' - catalogue = Catalog(project='Sphinx', version=sphinx.__version__, charset='utf-8') + catalogue = Catalog(project='Sphinx', version=sphinx_version, charset='utf-8') base = os.path.abspath(input_path) for root, dirnames, filenames in os.walk(base):