upload-reference.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import requests
  3. # Configuration
  4. API_KEY = os.getenv("POEDITOR_API_KEY")
  5. PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
  6. UPLOAD_API_URL = "https://api.poeditor.com/v2/projects/upload"
  7. LOCAL_FILE_PATH = "src/PixiEditor/Data/Localization/Languages/en.json"
  8. def upload_en_json():
  9. if not API_KEY or not PROJECT_ID:
  10. print("::error::Missing POEDITOR_API_KEY or POEDITOR_PROJECT_ID environment variables.")
  11. exit(1)
  12. return
  13. try:
  14. with open(LOCAL_FILE_PATH, "rb") as file:
  15. files = {
  16. "file": ("en.json", file, "application/json")
  17. }
  18. data = {
  19. "api_token": API_KEY,
  20. "id": PROJECT_ID,
  21. "updating": "terms_translations", # Updates both terms and translations.
  22. "language": "en", # Specify language as English.
  23. "overwrite": 1, # Overwrite existing terms/translations.
  24. "sync_terms": 1, # Sync terms: delete terms not in the uploaded file.
  25. "fuzzy_trigger": 1 # Mark translations in other languages as fuzzy.
  26. }
  27. response = requests.post(UPLOAD_API_URL, data=data, files=files)
  28. except FileNotFoundError:
  29. print(f"::error::Local file not found: {LOCAL_FILE_PATH}")
  30. return
  31. if response.status_code == 200:
  32. result = response.json()
  33. if result.get("response", {}).get("status") == "success":
  34. print("✅ Upload succeeded:")
  35. print(result)
  36. else:
  37. print("::error::Upload failed:")
  38. print(result)
  39. exit(1)
  40. else:
  41. print("::error::HTTP Error:", response.status_code)
  42. print(response.text)
  43. exit(1)
  44. if __name__ == "__main__":
  45. upload_en_json()