-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to generate pot file and upload to Crowdin
- Loading branch information
1 parent
68c24da
commit 4879213
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: crowdin upload | ||
on: push [crowdinUpload2] | ||
|
||
jobs: | ||
Crowdin upload | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.sha }} | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
architecture: x86 | ||
- name: generate pot file | ||
run: | | ||
xgettext -o nvda.pot --package-name "nvda" --package-version ${{ github.sha }} --foreign-user --add-comments=Translators:" --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --from-code utf-8 --language=python source/*.pyw source/**.py | ||
- name: Upload to Crowdin | ||
env: | ||
crowdinProjectID: ${{ secrets.crowdinProjectID }} | ||
crowdinAuthToken: ${{ secrets.crowdinAuthToken }} | ||
run: | | ||
py crowdinSync.py uploadSourceFile 2 nvda.pot nvda.pot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# based on file from https://github.com/jcsteh/osara | ||
|
||
import time | ||
import os | ||
import glob | ||
import sys | ||
import zipfile | ||
import shutil | ||
import subprocess | ||
import requests | ||
|
||
AUTH_TOKEN = os.getenv("crowdinAuthToken") | ||
if not AUTH_TOKEN: | ||
raise ValueError("crowdinAuthToken environment variable not set") | ||
PROJECT_ID = int(os.getenv("crowdinProjectID")) | ||
if not PROJECT_ID: | ||
raise ValueError("crowdinProjectID environment variable not set") | ||
|
||
|
||
def request(path, method=requests.get, headers={}, **kwargs): | ||
headers["Authorization"] = "Bearer %s" % AUTH_TOKEN | ||
r = method("https://api.crowdin.com/api/v2/%s" % path, headers=headers, | ||
**kwargs) | ||
# Convert errors to exceptions, but print the response before raising. | ||
try: | ||
r.raise_for_status() | ||
except requests.exceptions.HTTPError: | ||
print(r.json()) | ||
raise | ||
return r | ||
|
||
def projectRequest(path, **kwargs): | ||
return request("projects/%d/%s" % (PROJECT_ID, path), **kwargs) | ||
|
||
def uploadSourceFile(crowdinFileID, crowdinFileName, localFilePath): | ||
fn = os.path.basename(localFilePath) | ||
f = open(localFilePath, "rb") | ||
print(f"Uploading {localFilePath} to Crowdin temporary storage as {crowdinFileName}") | ||
r = request("storages", method=requests.post, | ||
headers={"Crowdin-API-FileName": crowdinFileName}, data=f) | ||
storageID = r.json()["data"]["id"] | ||
print(f"Updating file {crowdinFileID} on Crowdin with storage ID {storageID}") | ||
r = projectRequest("files/%d" % crowdinFileID, method=requests.put, | ||
json={"storageId": storageID}) | ||
return r | ||
|
||
if __name__ == "__main__": | ||
command = sys.argv[1] | ||
if command == "uploadSourceFile": | ||
crowdinFileID = int(sys.argv[2]) | ||
crowdinFileName = sys.argv[3] | ||
localFilePath = sys.argv[4] | ||
uploadSourceFile(crowdinFileID, crowdinFileName, localFilePath) | ||
else: | ||
raise ValueError("Unknown command") |