Skip to content

Commit f3d78b9

Browse files
authored
Merge pull request #1918 from Cihatata/upload-poeditor
Upload poeditor
2 parents ac8fc07 + c02e0cf commit f3d78b9

File tree

5 files changed

+197
-13
lines changed

5 files changed

+197
-13
lines changed
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import axios from "axios";
2+
import FormData from "form-data";
3+
import fs from "fs-extra";
4+
5+
// POEditor API information
6+
const API_TOKEN = process.env.POEDITOR_API;
7+
const PROJECT_ID = process.env.POEDITOR_PROJECT_ID;
8+
const FILE_PATH = process.env.FILE_PATH;
9+
const LANGUAGE = process.env.LANGUAGE;
10+
11+
// POEditor API endpoint
12+
const API_URL = 'https://api.poeditor.com/v2';
13+
14+
// Function to upload translations
15+
async function uploadTranslations() {
16+
try {
17+
console.log(`Uploading translations for ${LANGUAGE} language from ${FILE_PATH}... test1`);
18+
19+
// Check if file exists
20+
if (!await fs.pathExists(FILE_PATH)) {
21+
throw new Error(`File not found: ${FILE_PATH}`);
22+
}
23+
24+
// Read file content
25+
const fileContent = await fs.readFile(FILE_PATH, 'utf8');
26+
27+
// Validate JSON format
28+
try {
29+
JSON.parse(fileContent);
30+
} catch (error) {
31+
throw new Error(`Invalid JSON format in ${FILE_PATH}: ${error.message}`);
32+
}
33+
34+
// Create form data for upload
35+
const formData = new FormData();
36+
formData.append('api_token', API_TOKEN);
37+
formData.append('id', PROJECT_ID);
38+
formData.append('language', LANGUAGE);
39+
formData.append('updating', 'terms_translations');
40+
formData.append('file', fs.createReadStream(FILE_PATH));
41+
formData.append('overwrite', '1');
42+
formData.append('sync_terms', '1');
43+
44+
// Upload to POEditor
45+
const response = await axios.post(`${API_URL}/projects/upload`, formData, {
46+
headers: {
47+
'Content-Type': 'application/x-www-form-urlencoded',
48+
}
49+
});
50+
51+
if (response.data.response.status !== 'success') {
52+
throw new Error(`Failed to upload translations: ${JSON.stringify(response.data)}`);
53+
}
54+
55+
console.log(`Successfully uploaded translations for ${LANGUAGE} language.`);
56+
console.log(`Statistics: ${JSON.stringify(response.data.result)}`);
57+
} catch (error) {
58+
console.error('An error occurred while uploading translations:', error);
59+
process.exit(1);
60+
}
61+
}
62+
63+
// Run script
64+
uploadTranslations();

.github/workflows/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,31 @@ If the workflow fails:
3939
1. Check the GitHub Actions logs
4040
2. Make sure your POEditor API token and project ID are correct
4141
3. Ensure that the languages you specified exist in your POEditor project
42+
43+
# POEditor Upload Workflow
44+
45+
## Summary of Implemented Translation Workflow
46+
47+
We have successfully created a GitHub Actions workflow that automatically uploads translation files to POEditor when changes are merged to the develop branch. Here's a summary of what we've implemented:
48+
### Created Files
49+
50+
1. .github/scripts/upload-translations.js
51+
52+
- A Node.js script that handles the upload of translation files to POEditor
53+
- Uses the POEditor API to upload JSON translation files
54+
- Validates file existence and JSON format before uploading
55+
- Provides detailed logging of the upload process
56+
57+
2. .github/workflows/poeditor-upload-on-merge.yml - A GitHub Actions workflow that triggers when PRs are merged to the develop branch - Only runs when changes are made to files in the src/locales directory - Detects which translation files were changed in the PR - Extracts language codes from filenames (e.g., tr.json → "tr") - Calls the upload script for each changed file
58+
### Workflow Process
59+
1. When a PR is merged to the develop branch, the workflow checks if any files in src/locales were modified.
60+
61+
1. If translation files were changed, the workflow:
62+
63+
- Sets up the necessary Node.js environment
64+
- Installs required dependencies
65+
- Identifies which specific translation files were changed
66+
- For each changed file, extracts the language code and uploads to POEditor
67+
- Provides status notifications about the upload process
68+
69+
This automated workflow ensures that your translations are always in sync between your codebase and POEditor, eliminating the need for manual uploads and reducing the risk of translation inconsistencies.

.github/workflows/first-issue-first-pr.yml

-9
This file was deleted.

.github/workflows/upload-poeditor.yml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Upload Translations to POEditor on PR Merge
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- develop
8+
paths:
9+
- "src/locales/**"
10+
11+
jobs:
12+
upload-translations:
13+
# Only run if the PR was merged (not just closed) or manually triggered
14+
if: github.event.pull_request.merged == true'
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0 # Fetch all history to get changed files
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: "18"
27+
28+
- name: Create package.json for scripts
29+
run: |
30+
mkdir -p .github/scripts
31+
cat > .github/scripts/package.json << EOF
32+
{
33+
"name": "poeditor-scripts",
34+
"version": "1.0.0",
35+
"private": true,
36+
"type": "module",
37+
"dependencies": {
38+
"axios": "^1.6.0",
39+
"fs-extra": "^11.1.1",
40+
"form-data": "^4.0.0"
41+
}
42+
}
43+
EOF
44+
45+
- name: Install dependencies
46+
run: |
47+
cd .github/scripts
48+
npm install
49+
50+
- name: Get changed locale files
51+
id: changed-files
52+
if: github.event_name == 'pull_request'
53+
run: |
54+
# Get list of changed files in src/locales directory
55+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- src/locales/*.json)
56+
echo "Changed files: $CHANGED_FILES"
57+
58+
# Create a JSON array of changed files with language codes
59+
echo "CHANGED_FILES<<EOF" >> $GITHUB_ENV
60+
echo "$CHANGED_FILES" >> $GITHUB_ENV
61+
echo "EOF" >> $GITHUB_ENV
62+
63+
- name: Upload changed translations to POEditor
64+
if: env.CHANGED_FILES != ''
65+
env:
66+
POEDITOR_API: ${{ secrets.POEDITOR_API }}
67+
POEDITOR_PROJECT_ID: ${{ secrets.POEDITOR_PROJECT_ID }}
68+
run: |
69+
# Process each changed file
70+
for FILE in $CHANGED_FILES; do
71+
if [[ -f "$FILE" ]]; then
72+
# Extract language code from filename (e.g., src/locales/en.json -> en)
73+
FILENAME=$(basename "$FILE")
74+
75+
# Special case: map gb.json to en language code
76+
if [ "$FILENAME" == "gb.json" ]; then
77+
LANG="en"
78+
echo "Found gb.json, mapping to language code 'en'"
79+
else
80+
LANG=$(basename "$FILE" .json)
81+
fi
82+
83+
echo "Processing $FILE for language $LANG"
84+
85+
# Upload to POEditor
86+
LANGUAGE=$LANG FILE_PATH=$FILE node .github/scripts/upload-translations.js
87+
fi
88+
done
89+
90+
- name: Notify on success
91+
if: success() && env.CHANGED_FILES != ''
92+
run: |
93+
echo "Successfully uploaded translation files to POEditor."
94+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
95+
echo "Manual trigger comment: ${{ github.event.inputs.comment }}"
96+
fi
97+
98+
- name: Notify on no changes
99+
if: env.CHANGED_FILES == ''
100+
run: |
101+
echo "No translation files were found to upload."

src/locales/tr.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"distributedStatusSubHeaderText": "Dünya çapında milyonlarca cihaz tarafından desteklenen sistem performansını küresel bölgeye, ülkeye veya şehre göre görüntüleyin",
6161
"distributedRightCatagoryTitle": "Monitör",
6262
"distributedRightCatagoryDescription": "Mainnet Beta Kümesi",
63-
6463
"settingsGeneralSettings": "Genel ayarlar",
6564
"settingsDisplayTimezone": "Görüntüleme saat dilimi",
6665
"settingsDisplayTimezoneDescription": "Herkese açık olarak görüntülediğiniz kontrol panelinin saat dilimi.",
@@ -102,6 +101,7 @@
102101
"settingsFailedToAddDemoMonitors": "Demo monitörler eklenemedi",
103102
"settingsMonitorsDeleted": "Tüm monitörler başarıyla silindi",
104103
"settingsFailedToDeleteMonitors": "Monitörler silinemedi",
105-
"starPromptTitle": "Checkmate yıldızla değerlendirin",
106-
"starPromptDescription": "En son sürümleri görün ve GitHub'daki topluluğun büyümesine yardımcı olun"
107-
}
104+
"starPromptTitle": "Checkmate yıldızla değerlendirin",
105+
"starPromptDescription": "En son sürümleri görün ve GitHub'daki topluluğun büyümesine yardımcı olun",
106+
"testLocale": "TEST1211 UPLOAD"
107+
}

0 commit comments

Comments
 (0)