Bash script for processing translation files through PTC (Private Translation Cloud) API with support for various project configurations.
- π Flexible file search using globbing or explicit file configuration
- π‘οΈ Strict error handling for CI environments
- π Detailed logging with color highlighting
- β‘ Optimized for CI/CD usage
- π Step-based processing (Upload β Process β Monitor β Download)
- π― Isolated action support (upload, status, download)
- π Compact progress monitoring with status indicators
- ποΈ YAML configuration file support
- π Additional translation files support (mo, php, json, etc.)
# Create config file
cat > .ptc-config.yml << 'EOF'
source_locale: en
files:
- file: src/locales/en.json
output: src/locales/{{lang}}.json
- file: languages/plugin.pot
output: languages/plugin-{{lang}}.po
additional_translation_files:
- type: mo
path: languages/plugin-{{lang}}.mo
- type: po
path: languages/plugin-{{lang}}.po
EOF
# Process translations with token from command line
./ptc-cli.sh --config-file .ptc-config.yml --api-token="$PTC_API_TOKEN"Convenient for processing multiple files when the file or path to it contains a language code. In this case, you cannot transfer additional translation files (e.g. mo, po) or configure the output_file_path for each.
# Make script executable
chmod +x ptc-cli.sh
# Find files for English language by pattern
./ptc-cli.sh --source-locale en --patterns 'sample-{{lang}}.json' --api-token=your-token
# Find files in subdirectories
./ptc-cli.sh --source-locale en --patterns '{{lang}}/**/*.json' --api-url=https://app.ptc.wpml.org/api/v1/
# Multiple patterns
./ptc-cli.sh -s en -p 'sample-{{lang}}.json,{{lang}}-*.properties' --api-token=your-tokenFile Selection:
-c, --config-file FILE- YAML configuration file (recommended)-p, --patterns PATTERNS- File patterns separated by commas
Basic Parameters:
-s, --source-locale LOCALE- Source language (required unless in config)-t, --file-tag-name TAG- File tag name/branch name (default: auto-detect from git)-d, --project-dir DIR- Project directory (default: current)
API Configuration:
--api-url URL- PTC API base URL (default: https://app.ptc.wpml.org/api/v1/)--api-token TOKEN- API authentication token--monitor-interval SECONDS- Status check interval (default: 5)--monitor-max-attempts COUNT- Maximum monitoring attempts (default: 100)
Control Options:
--action ACTION- Perform isolated action: upload, status, download-v, --verbose- Verbose output-n, --dry-run- Show what would be done without executing-h, --help- Show help--version- Show version
The YAML configuration file supports full project setup:
# Basic settings
source_locale: en
file_tag_name: main
api_url: https://app.ptc.wpml.org/api/v1/
# api_token: NEVER store API tokens in config files committed to repository!
# Use --api-token parameter or PTC_API_TOKEN environment variable instead
# Monitoring settings (optional)
monitor_interval: 5
monitor_max_attempts: 100
# Files to translate
files:
# React app localization files
- file: src/locales/en.json
output: src/locales/{{lang}}.json
additional_translation_files:
- type: mo
path: dist/locales/{{lang}}.mo
- type: php
path: includes/lang-{{lang}}.php
# Admin panel translations
- file: admin/locales/en.json
output: admin/locales/{{lang}}.json
# WordPress plugin translations
- file: languages/plugin.pot
output: languages/plugin-{{lang}}.po
additional_translation_files:
- type: mo
path: languages/plugin-{{lang}}.mo
- type: json
path: languages/plugin-{{lang}}-wp.jsonWith Configuration File:
# Basic usage with config
./ptc-cli.sh --config-file config.yml
# Dry run to see what would happen
./ptc-cli.sh -c config.yml --dry-run --verbose
# Override specific settings
./ptc-cli.sh -c config.yml --api-token=different-token --file-tag-name=feature-branch
# Isolated actions
./ptc-cli.sh -c config.yml --action upload # Only upload files
./ptc-cli.sh -c config.yml --action status --verbose # Check translation status
./ptc-cli.sh -c config.yml --action download # Download completed translationsWith params:
# Basic usage
./ptc-cli.sh -s en -p 'sample-{{lang}}.json' --api-token=your-token
# Search in specific directory
./ptc-cli.sh -s de -p '{{lang}}/**/*.json' -d /path/to/project
# Dry run with verbose output
./ptc-cli.sh -s en -p '{{lang}}/*.json' --verbose --dry-run --api-token=your-token
# Multiple patterns
./ptc-cli.sh -s en -p 'i18n/{{lang}}/app.json,locales/{{lang}}/*.properties' --api-token=your-token
# WordPress WPSite example
./ptc-cli.sh -s en -p 'languages/wpsite.pot' -t main --api-token=your-token
# Isolated actions with patterns
./ptc-cli.sh -s en -p 'sample-{{lang}}.json' --action upload --api-token=your-token
./ptc-cli.sh -s en -p 'sample-{{lang}}.json' --action status --verbose --api-token=your-token
./ptc-cli.sh -s en -p 'sample-{{lang}}.json' --action download --api-token=your-tokenThe script supports two modes of operation:
The script follows a step-based approach:
- π€ Upload Step: All files are uploaded to the PTC API
- βοΈ Processing Step: Translation processing is triggered for all files
- π Monitoring Step: Translation status is monitored with compact progress display
- π₯ Download Step: Completed translations are downloaded and unpacked
For more granular control, you can perform specific steps in isolation:
Only uploads files to PTC without starting translation processing.
./ptc-cli.sh -c config.yml --action uploadChecks the translation status of files without downloading.
./ptc-cli.sh -c config.yml --action status --verboseDownloads completed translations without checking or uploading.
./ptc-cli.sh -c config.yml --action downloadUse Cases for Isolated Actions:
- CI/CD pipelines: Upload files in one job, check status and download in another
- Manual workflows: Upload files, review translations externally, then download
- Debugging: Check specific status or retry downloads without re-uploading
During monitoring, you'll see compact status indicators (Each letter for one file):
UU 12/30- Unknown status (12 attempts out of 30 total)QQ 23/30- Queued for processingPP 25/30- Processing in progressCQ 27/30- Some completed, some queuedCC 28/30- All completed
Status Characters:
- π’
C- Completed - π΅
Q- Queued - π΅
P- Processing - π΄
F- Failed - π‘
U- Unknown
Add PTC_API_TOKEN to the repository secrets (Settings -> Secrets and variables -> Actions -> New repository secret). Ensure to turn on the "Allow GitHub Actions to create and approve pull requests" permission in the repository settings (Settings -> Actions -> General -> Workflow permissions).
name: Process Translation Files
on:
workflow_dispatch: # Manual trigger
jobs:
process-translations:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PTC CLI
run: |
curl -fsSL https://raw.githubusercontent.com/OnTheGoSystems/ptc-cli/refs/heads/main/ptc-cli.sh -o ptc-cli.sh
chmod +x ptc-cli.sh
- name: Process translations with PTC CLI
env:
PTC_API_TOKEN: ${{ secrets.PTC_API_TOKEN }}
run: |
./ptc-cli.sh \
--config-file .ptc/config.yml \
--api-token ${{ secrets.PTC_API_TOKEN }} \
--verbose
- name: Clean up temporary files
run: |
rm -f ptc-cli.sh
- name: Create Pull Request with translations
if: success()
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "π Update translations via PTC CLI"
title: "π Update translations from PTC"
body: |
## π Translation Update
This PR contains new translations processed by PTC CLI.
**Triggered by:** ${{ github.event_name }}
**Branch:** ${{ github.ref_name }}
**Commit:** ${{ github.sha }}
---
*Auto-generated by GitHub Actions*
delete-branch: trueSample .ptc/config.yml file:
source_locale: en
file_tag_name: main
files:
- file: src/locales/en.json
output: src/locales/{{lang}}.jsonprocess_translations:
stage: deploy
script:
- chmod +x ptc-cli.sh
- ./ptc-cli.sh -c config.yml --api-token="$PTC_API_TOKEN" -v
variables:
PTC_API_TOKEN: "$CI_PTC_API_TOKEN"
only:
- merge_requests
- mainWhen using YAML configuration, you can specify additional files to be generated (useful for WordPress):
files:
- file: languages/plugin.pot
output: languages/plugin-{{lang}}.po
additional_translation_files:
- type: mo
path: languages/plugin-{{lang}}.mo
- type: json
path: languages/plugin-{{lang}}.json
- type: php
path: includes/lang-{{lang}}.phpCommon Issues:
-
HTTP 401 Unauthorized
[ERROR] Failed to upload file: example.json (HTTP 401)
- Check your API token
- Verify token has correct permissions
-
HTTP 403 Forbidden
[ERROR] Failed to upload file: example.json (HTTP 403)
- Check your API token
- Check your Subscription
- Verify token has correct permissions
-
Files not found
[ERROR] No files found for pattern: {{lang}}.json- Check file paths in config
- Verify source locale matches your files
- Use
--verboseto see search details
-
Translation timeout
[WARNING] Timed out files: 1
- Increase
--monitor-max-attempts - Check translation status manually with provided curl command
- Increase
See DEVELOPMENT.md for development and testing instructions.
MIT License