diff --git a/.github/workflows/auto_translate.yml b/.github/workflows/auto_translate.yml new file mode 100644 index 000000000000..91657c547603 --- /dev/null +++ b/.github/workflows/auto_translate.yml @@ -0,0 +1,58 @@ +name: Add new translation + +on: + workflow_dispatch: + push: + branches: ['translate'] + +jobs: + add_translation: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + name: 'Add new translation' + + steps: + - name: 'Update Branch' + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Installing Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Installing deps + run: | + python -m pip install --upgrade pip + pip install -r ./tools/translator/requirements.txt + + - name: Create temporary branch + run: | + git branch -f translate_tmp + git checkout translate_tmp + git reset --hard origin/master + + - name: Apply existing translation + run: | + git checkout origin/translate -- ./tools/translator/ss220replace.json + ./tools/translator/ss220_replacer_linux --prefix=ss220 --root=./../../ --location=./ + + - name: Apply PR translation + run: | + git cherry-pick -n origin/translate + + - name: 'Generate Translation' + run: | + git add ./tools/translator/ss220replace.json + python ./tools/translator/converter.py + git add ./tools/translator/ss220replace.json + + - name: 'Push Translation' + run: | + git config --local user.email "action@github.com" + git config --local user.name "SS220Manager" + git commit -m "Generate translation file" + git push -u -f origin/translate diff --git a/.github/workflows/translate_branch_update.yml b/.github/workflows/translate_branch_update.yml new file mode 100644 index 000000000000..6ceaa45ac0d5 --- /dev/null +++ b/.github/workflows/translate_branch_update.yml @@ -0,0 +1,35 @@ +name: Update translate branch + +on: + workflow_dispatch: + push: + branches: ['master'] + +jobs: + add_translation: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: 'Update Branch' + uses: actions/checkout@v4 + + - name: Create temporary branch + run: | + git branch -f translate_tmp + git checkout translate_tmp + git reset --hard origin/master + + - name: Apply existing translation + run: | + git checkout origin/translate -- ./tools/translator/ss220replace.json + ./tools/translator/ss220_replacer_linux --prefix=ss220 --root=./../../ --location=./ + + - name: 'Push Translation' + run: | + git config --local user.email "action@github.com" + git config --local user.name "SS220Manager" + git commit -m "Generate translation file" + git push -u -f origin translate diff --git a/tools/translator/converter.py b/tools/translator/converter.py new file mode 100644 index 000000000000..a7e2cb8cd93b --- /dev/null +++ b/tools/translator/converter.py @@ -0,0 +1,40 @@ +import git +import json +BUILD_PATH = "./../../" + + +repo = git.Repo(BUILD_PATH) +tree = repo.head.commit.tree +if not tree: + print("No changes") + exit() +diff = repo.git.diff(tree) +if not diff: + print("No changes") + exit() +diff = [line for line in diff.split("\n") if line[0] in "+-" and not line.startswith("+++")] + +translation = {"files": []} + +lastfile = '' +lastaction = '' +for line in diff: + if line.startswith("---"): + lastfile = line[6:] + lastaction = '---' + translation["files"].append({"path": lastfile, "replaces": []}) + elif line.startswith("-"): + if lastaction == "---" or lastaction == "+": + translation["files"][-1]["replaces"].append({"original": line[1:], "replace": ""}) + elif lastaction == "-": + translation["files"][-1]["replaces"][-1]["original"]+=f"\n{line[1:]}" + lastaction = "-" + elif line.startswith("+"): + if lastaction == "-": + translation["files"][-1]["replaces"][-1]["replace"] = line[1:] + elif lastaction == "+": + translation["files"][-1]["replaces"][-1]["replace"] += f"\n{line[1:]}" + lastaction = "+" + +with open('ss220replace.json', 'w+', encoding='utf-8') as f: + json.dump(translation, f, ensure_ascii=False, indent=2) diff --git a/tools/translator/requirements.txt b/tools/translator/requirements.txt new file mode 100644 index 000000000000..64b1adaeeb48 --- /dev/null +++ b/tools/translator/requirements.txt @@ -0,0 +1 @@ +GitPython diff --git a/tools/translator/ss220_replacer_linux b/tools/translator/ss220_replacer_linux new file mode 100644 index 000000000000..78b71f2fc92c Binary files /dev/null and b/tools/translator/ss220_replacer_linux differ diff --git a/tools/translator/ss220_replacer_windows.exe b/tools/translator/ss220_replacer_windows.exe new file mode 100644 index 000000000000..5a0d1bfc7791 Binary files /dev/null and b/tools/translator/ss220_replacer_windows.exe differ diff --git a/tools/translator/ss220replace.json b/tools/translator/ss220replace.json new file mode 100644 index 000000000000..6941fa698db2 --- /dev/null +++ b/tools/translator/ss220replace.json @@ -0,0 +1,3 @@ +{ + "files": [] +} \ No newline at end of file