forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 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,32 @@ | ||
name: Add new translation | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: ['translate'] | ||
|
||
concurrency: | ||
group: translation | ||
cancel-in-progress: false | ||
|
||
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: 0 | ||
|
||
- name: Installing Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Run script | ||
run: ./tools/translate/add_new_translation.sh |
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,28 @@ | ||
name: Update translation branch | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: ['master'] | ||
|
||
concurrency: | ||
group: translation | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
update_translation: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
name: 'Update old translation' | ||
|
||
steps: | ||
- name: 'Update Branch' | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run script | ||
run: ./tools/translate/update_translation.sh | ||
|
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,24 @@ | ||
python -m pip install --upgrade pip | ||
pip install -r ./tools/translate/requirements.txt | ||
|
||
git fetch origin | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "ss220bot" | ||
|
||
git checkout -b translate_tmp | ||
git reset --hard origin/master | ||
|
||
git checkout translate -- ./tools/translate/ss220replace.json | ||
git commit -m "Move old translation" | ||
|
||
git cherry-pick translate | ||
|
||
python ./tools/translate/converter.py | ||
git add ./tools/translate/ss220replace.json | ||
git commit -m "Generate translation file" | ||
git reset . | ||
|
||
./tools/translate/ss220_replacer_linux | ||
git commit -m "Apply translation" | ||
|
||
git push -f origin translate_tmp:translate |
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,90 @@ | ||
import git | ||
import json | ||
import re | ||
import os | ||
import hashlib | ||
BUILD_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..") | ||
|
||
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("+++")] | ||
|
||
# Собираем в структуру вида: | ||
# { | ||
# "file": "player.dm", | ||
# "origin": ["Test", "Test2"], | ||
# "replace": ["Тест", "Тест2"] | ||
# } | ||
files = [] | ||
for line in diff: | ||
if line.startswith("---"): | ||
files.append({"file": line[6:], "origin": [], "replace": []}) | ||
elif line.startswith("-"): | ||
files[-1]['origin'].append(line[1:].strip()) | ||
elif line.startswith("+"): | ||
files[-1]['replace'].append(line[1:].strip()) | ||
|
||
# Собираем в структуру для хранения в файле: | ||
# { | ||
# "files": [ | ||
# { | ||
# "path": "player.dm", | ||
# "replaces": [ | ||
# {"original": "Test", "replace": "Тест"}, | ||
# {"original": "Test2", "replace": "Тест2"} | ||
# ] | ||
# } | ||
# ] | ||
# } | ||
jsonStructure = {"files": []} | ||
for item in files: | ||
originLen = len(item["origin"]) | ||
replaceLen = len(item["replace"]) | ||
|
||
if originLen != replaceLen: | ||
print("Changes not equals") | ||
print(item) | ||
exit(1) | ||
|
||
file = {"path": item["file"], "replaces": []} | ||
|
||
for i in range(originLen): | ||
file["replaces"].append({"original": item["origin"][i], "replace": item["replace"][i]}) | ||
|
||
jsonStructure["files"].append(file) | ||
|
||
jsonFilePath = os.path.dirname(os.path.realpath(__file__)) + '/ss220replace.json' | ||
|
||
# Добавляем новые элементы к текущим в файле | ||
fullTranslation = json.load(open(jsonFilePath, encoding='utf-8')) | ||
for file in jsonStructure['files']: | ||
fullTranslation["files"].append(file) | ||
|
||
# Убираем дубли | ||
hashCache = {} | ||
filteredTranslation = {"files": []} | ||
for file in fullTranslation['files']: | ||
filteredFile = {"path": file["path"], "replaces": []} | ||
for replace in file['replaces']: | ||
hash = hashlib.sha256((file['path'] + replace["original"]).encode("utf-8")).hexdigest() | ||
if hash in hashCache: | ||
continue | ||
hashCache[hash] = hash | ||
|
||
filteredFile["replaces"].append({"original": replace["original"], "replace": replace["replace"]}) | ||
|
||
filteredTranslation["files"].append(filteredFile) | ||
|
||
with open(jsonFilePath, 'w+', encoding='utf-8') as f: | ||
json.dump(filteredTranslation, f, ensure_ascii=False, indent=2) | ||
|
||
print(f"Added translation for {len(jsonStructure['files'])} files.") |
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 @@ | ||
GitPython |
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
{ | ||
"files": [] | ||
} |
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,16 @@ | ||
python -m pip install --upgrade pip | ||
pip install -r ./tools/translate/requirements.txt | ||
|
||
git fetch origin | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "ss220bot" | ||
|
||
git checkout -b translate_tmp | ||
git reset --hard origin/master | ||
|
||
git checkout translate -- ./tools/translate/ss220replace.json | ||
|
||
./tools/translate/ss220_replacer_linux | ||
git commit -m "Apply translation" | ||
|
||
git push -f origin translate_tmp:translate |