Browse Source

Temporarily disabled download changes and added upload

CPK 5 months ago
parent
commit
4f4078e1ef

+ 5 - 3
.github/workflows/localization.yml

@@ -30,7 +30,7 @@ jobs:
         uses: actions/[email protected]
         uses: actions/[email protected]
       - name: Compare local reference
       - name: Compare local reference
         id: upload-comparison
         id: upload-comparison
-        run: python .github/workflows/localization/upload-comparison.py
+        run: python .github/workflows/localization/reference-comparison.py
         env:
         env:
           POEDITOR_API_KEY: ${{ secrets.POEDITORKEY }}
           POEDITOR_API_KEY: ${{ secrets.POEDITORKEY }}
           POEDITOR_PROJECT_ID: ${{ secrets.POEDITORPROJECT }}
           POEDITOR_PROJECT_ID: ${{ secrets.POEDITORPROJECT }}
@@ -42,13 +42,15 @@ jobs:
     environment: poeditor
     environment: poeditor
     if: needs.compare-upload.outputs.hasChanges
     if: needs.compare-upload.outputs.hasChanges
     steps:
     steps:
+      - name: Checkout
+        uses: actions/[email protected]
       - name: Upload Changes
       - name: Upload Changes
-        run: echo "Changes would be uploaded here!"
+        run: python .github/workflows/localization/upload-reference.py
 
 
   download:
   download:
     name: "Download changes"
     name: "Download changes"
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
-    if: ${{ inputs.mode != 'Upload only' }}
+    if: ${{ inputs.mode != 'Upload only' }} && false
     steps:
     steps:
       - name: Checkout
       - name: Checkout
         uses: actions/[email protected]
         uses: actions/[email protected]

+ 0 - 0
.github/workflows/localization/upload-comparison.py → .github/workflows/localization/reference-comparison.py


+ 47 - 0
.github/workflows/localization/upload-reference.py

@@ -0,0 +1,47 @@
+import os
+import requests
+
+# Configuration
+API_KEY = os.getenv("POEDITOR_API_KEY")
+PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
+UPLOAD_API_URL = "https://api.poeditor.com/v2/projects/upload"
+LOCAL_FILE_PATH = "src/PixiEditor/Data/Localization/Languages/en.json"
+
+def upload_en_json():
+    if not API_KEY or not PROJECT_ID:
+        print("::error::Missing POEDITOR_API_KEY or POEDITOR_PROJECT_ID environment variables.")
+        return
+
+    try:
+        with open(LOCAL_FILE_PATH, "rb") as file:
+            files = {
+                "file": ("en.json", file, "application/json")
+            }
+            data = {
+                "api_token": API_KEY,
+                "id": PROJECT_ID,
+                "updating": "terms_translations",  # Updates both terms and translations.
+                "language": "en",                  # Specify language as English.
+                "overwrite": 1,                    # Overwrite existing terms/translations.
+                "sync_terms": 1,                   # Sync terms: delete terms not in the uploaded file.
+                "fuzzy_trigger": 1                 # Mark translations in other languages as fuzzy.
+            }
+            response = requests.post(UPLOAD_API_URL, data=data, files=files)
+    except FileNotFoundError:
+        print(f"::error::Local file not found: {LOCAL_FILE_PATH}")
+        return
+
+    if response.status_code == 200:
+        result = response.json()
+        if result.get("response", {}).get("status") == "success":
+            print("✅ Upload succeeded:")
+            print(result)
+        else:
+            print("::error::Upload failed:")
+            print(result)
+    else:
+        print("::error::HTTP Error:", response.status_code)
+        print(response.text)
+
+if __name__ == "__main__":
+    upload_en_json()