Skip to content

Commit 9218222

Browse files
authored
feat: Add internationalization (i18n) support for translations (#3501)
1 parent 1790771 commit 9218222

File tree

10 files changed

+5672
-3
lines changed

10 files changed

+5672
-3
lines changed

.github/workflows/update-release-pr.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
# 1. Replaces x-release-please-version placeholders with actual version
99
# 2. Updates the Upgrade Notice section in readme.txt if there are breaking changes
10+
# 3. Regenerates the POT file for translations (if languages/ directory exists)
1011
#
1112
# The workflow identifies release-please PRs by:
1213
# - Branch name starting with "release-please--"
@@ -27,8 +28,8 @@ permissions:
2728
pull-requests: write
2829

2930
jobs:
30-
update-upgrade-notice:
31-
name: Update Upgrade Notice
31+
update-release-pr:
32+
name: Update Release PR
3233
# Only run on release-please PRs
3334
if: startsWith(github.head_ref, 'release-please--')
3435
runs-on: ubuntu-latest
@@ -45,6 +46,13 @@ jobs:
4546
with:
4647
node-version: "22"
4748

49+
- name: Install WP-CLI
50+
run: |
51+
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
52+
chmod +x wp-cli.phar
53+
sudo mv wp-cli.phar /usr/local/bin/wp
54+
wp --info
55+
4856
- name: Extract version and component from PR
4957
id: version_info
5058
run: |
@@ -127,6 +135,30 @@ jobs:
127135
--version=${{ steps.version_info.outputs.version }} \
128136
--plugin-dir=${{ steps.version_info.outputs.plugin_dir }}
129137
138+
- name: Check for languages directory
139+
id: i18n
140+
run: |
141+
PLUGIN_DIR="${{ steps.version_info.outputs.plugin_dir }}"
142+
if [ -d "${PLUGIN_DIR}/languages" ]; then
143+
echo "enabled=true" >> $GITHUB_OUTPUT
144+
echo "Languages directory found - will regenerate POT file"
145+
else
146+
echo "enabled=false" >> $GITHUB_OUTPUT
147+
echo "No languages directory - skipping POT generation"
148+
fi
149+
150+
- name: Regenerate POT file
151+
if: steps.i18n.outputs.enabled == 'true' && steps.version_info.outputs.version != ''
152+
working-directory: ${{ steps.version_info.outputs.plugin_dir }}
153+
run: |
154+
COMPONENT="${{ steps.version_info.outputs.component }}"
155+
wp i18n make-pot . languages/${COMPONENT}.pot \
156+
--slug=${COMPONENT} \
157+
--domain=${COMPONENT} \
158+
--include=src,access-functions.php,*.php \
159+
--exclude=node_modules,vendor,tests,build,packages
160+
echo "POT file regenerated: languages/${COMPONENT}.pot"
161+
130162
- name: Check for changes
131163
id: changes
132164
run: |
@@ -156,5 +188,5 @@ jobs:
156188
git config --local user.email "github-actions[bot]@users.noreply.github.com"
157189
git config --local user.name "github-actions[bot]"
158190
git add "$PLUGIN_DIR"
159-
git commit -m "chore: replace x-release-please-version placeholders and update upgrade notice for ${COMPONENT}"
191+
git commit -m "chore: replace x-release-please-version placeholders, update upgrade notice, and regenerate translations for ${COMPONENT}"
160192
git push

docs/DEVELOPMENT.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ npm run build
124124
npm run -w @wpgraphql/wp-graphql build
125125
```
126126

127+
## Internationalization (i18n)
128+
129+
WPGraphQL supports internationalization. Translation files are in `plugins/wp-graphql/languages/`.
130+
131+
```bash
132+
# Regenerate the POT file (extracts translatable strings from PHP)
133+
npm run -w @wpgraphql/wp-graphql i18n:pot
134+
135+
# Generate JSON translation files for JavaScript (from PO files)
136+
npm run -w @wpgraphql/wp-graphql i18n:json
137+
```
138+
139+
The POT file is automatically regenerated during releases via the `update-release-pr` workflow.
140+
127141
## Custom Environment Configuration
128142

129143
Create a `.wp-env.override.json` file in the root to customize the environment:

plugins/wp-graphql/languages/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)