feat: Sync strings from poeditor with github workfliw
This commit is contained in:
1 parent
7c369e8405
commit
29e03a6294
3 files changed
+225
No files matched your search
@@ -0,0 +1,41 @@
|
||||
# POEditor Translation Synchronization
|
||||
|
||||
This GitHub Actions workflow automatically downloads translation files from POEditor and integrates them into the project.
|
||||
|
||||
## How It Works
|
||||
|
||||
The workflow can be triggered in two ways:
|
||||
|
||||
1. **Manual Trigger**: You can manually run the "POEditor Translation Synchronization" workflow from the "Actions" tab in the GitHub interface.
|
||||
2. **Automatic Trigger**: The workflow runs automatically every day at midnight (UTC).
|
||||
|
||||
## Required Settings
|
||||
|
||||
For this workflow to function, you need to define the following secrets in your GitHub repository:
|
||||
|
||||
1. `POEDITOR_API_TOKEN`: Your POEditor API token
|
||||
2. `POEDITOR_PROJECT_ID`: Your POEditor project ID
|
||||
|
||||
You can add these secrets in the "Settings > Secrets and variables > Actions" section of your GitHub repository.
|
||||
|
||||
## Manual Execution
|
||||
|
||||
When running the workflow manually, you can specify which languages to download. Languages should be entered as comma-separated values (e.g., `tr,gb,es`).
|
||||
|
||||
If you don't specify any languages, the default languages `tr` and `gb` will be downloaded.
|
||||
|
||||
## Output
|
||||
|
||||
When the workflow completes successfully:
|
||||
|
||||
1. Translation files for the specified languages are downloaded from POEditor
|
||||
2. These files are copied to the `src/locales/` directory
|
||||
3. Changes are automatically committed and pushed to the main branch
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the workflow fails:
|
||||
|
||||
1. Check the GitHub Actions logs
|
||||
2. Make sure your POEditor API token and project ID are correct
|
||||
3. Ensure that the languages you specified exist in your POEditor project
|
||||
@@ -0,0 +1,92 @@
|
||||
name: POEditor Translation Synchronization
|
||||
|
||||
on:
|
||||
# For manual triggering
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
languages:
|
||||
description: "Languages to synchronize (comma separated, e.g.: tr,en,es)"
|
||||
required: false
|
||||
default: "tr,en"
|
||||
format:
|
||||
description: "Export format (key_value_json or json)"
|
||||
required: false
|
||||
default: "key_value_json"
|
||||
|
||||
# For automatic execution at a specific time (every day at midnight)
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
jobs:
|
||||
sync-translations:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "18"
|
||||
|
||||
- name: Create package.json for scripts
|
||||
run: |
|
||||
mkdir -p .github/scripts
|
||||
cat > .github/scripts/package.json << EOF
|
||||
{
|
||||
"name": "poeditor-scripts",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"axios": "^1.6.0",
|
||||
"fs-extra": "^11.1.1"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd .github/scripts
|
||||
npm install
|
||||
|
||||
- name: Download translations from POEditor
|
||||
env:
|
||||
POEDITOR_API_TOKEN: ${{ secrets.POEDITOR_API_TOKEN }}
|
||||
POEDITOR_PROJECT_ID: ${{ secrets.POEDITOR_PROJECT_ID }}
|
||||
LANGUAGES: ${{ github.event.inputs.languages || 'tr,gb' }}
|
||||
EXPORT_FORMAT: ${{ github.event.inputs.format || 'key_value_json' }}
|
||||
run: |
|
||||
mkdir -p temp
|
||||
node .github/scripts/download-translations.js
|
||||
|
||||
- name: Verify translation files
|
||||
run: |
|
||||
echo "Verifying translation files..."
|
||||
for file in temp/*.json; do
|
||||
echo "Checking $file"
|
||||
if [ ! -s "$file" ]; then
|
||||
echo "Error: $file is empty or does not exist"
|
||||
exit 1
|
||||
fi
|
||||
# Validate JSON format
|
||||
cat "$file" | jq . > /dev/null || { echo "Error: $file is not valid JSON"; exit 1; }
|
||||
done
|
||||
echo "All translation files are valid"
|
||||
|
||||
- name: Copy translations to project
|
||||
run: |
|
||||
mkdir -p src/locales
|
||||
cp -r temp/* src/locales/
|
||||
echo "Translation files copied to src/locales/"
|
||||
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --local user.name "github-actions[bot]"
|
||||
git add src/locales/*.json
|
||||
git diff --staged --quiet || git commit -m "Translations updated from POEditor"
|
||||
git push
|
||||
Reference in new issue
Block a user