The script scrapes the API for taxonomy terms and post types, pulls down the term titles, descriptions, and post titles. Those are then injected into a php file with i18n wrappers, so that this can be loaded into the regular translation syncing process.
It can be used in a child theme project's actions like this:
Example workflow file
```
name: Translate Strings
on:
workflow_dispatch:
schedule:
- cron: '0 6,18 * * *'
jobs:
translation-strings:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: i18n
uses: WordPress/wporg-repo-tools/.github/actions/i18n@try/i18n-action
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --no_taxonomies
- name: Commit and push
# Using a specific hash here instead of a tagged version, for risk mitigation, since this action modifies our repo.
uses: actions-js/push@a52398fac807b0c1e5f1492c969b477c8560a0ba # 1.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: test-i18n
message: 'Update translation strings'
```
See https://github.com/WordPress/wporg-theme-directory/issues/74, https://github.com/WordPress/wporg-main-2022/issues/436 — the content coming from the WordPress database is not translated on rosetta sites. We had a similar problem on Patterns and Learn, so they both use this sync-script process to get the strings into GlotPress (https://github.com/WordPress/pattern-directory/pull/275). Since this has now also come up on the main site and themes, I've created a shared action that should accept args to pull the correct project's strings into the repo.
The script scrapes the API for taxonomy terms and post types, pulls down the term titles, descriptions, and post titles. Those are then injected into a php file with i18n wrappers, so that this can be loaded into the regular translation syncing process.
It can be used in a child theme project's actions like this:
Example workflow file
``` name: Translate Strings on: workflow_dispatch: schedule: - cron: '0 6,18 * * *' jobs: translation-strings: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: i18n uses: WordPress/wporg-repo-tools/.github/actions/i18n@try/i18n-action with: token: ${{ secrets.GITHUB_TOKEN }} args: --no_taxonomies - name: Commit and push # Using a specific hash here instead of a tagged version, for risk mitigation, since this action modifies our repo. uses: actions-js/push@a52398fac807b0c1e5f1492c969b477c8560a0ba # 1.3 with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: test-i18n message: 'Update translation strings' ```I've got a testing branch on my wporg-main-2022 fork here: https://github.com/WordPress/wporg-main-2022/compare/trunk...ryelle:wporg-main-2022:test-i18n
The last commit there includes the
translate-strings.php
file with all the page titles from WordPress.org.This can also be tested locally, if you want to try out different args
composer install
to get the Requests depphp .github/actions/i18n/bin/i18n.php --taxonomies=wporg-pattern-category,wporg-pattern-flag-reason --post_types=page --url=https://wordpress.org/patterns/wp-json/wp/v2/
extra/translation-strings.php
file.Still to do:
wporg-patterns
Not part of this PR, but will need to add filters to actually use the translated values.