diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml index 1b2ec56..1cd4443 100644 --- a/.github/workflows/publish_alpha.yml +++ b/.github/workflows/publish_alpha.yml @@ -16,6 +16,7 @@ on: - 'MANIFEST.in' - 'readme.md' - 'scripts/**' + - 'translations/**' workflow_dispatch: jobs: diff --git a/.github/workflows/sync_tx.yml b/.github/workflows/sync_tx.yml new file mode 100644 index 0000000..2fd378e --- /dev/null +++ b/.github/workflows/sync_tx.yml @@ -0,0 +1,32 @@ +name: Run script on merge to dev by gitlocalize-app + +on: + workflow_dispatch: + push: + branches: + - dev + +jobs: + run-script: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.9 + + - name: Run script if merged by gitlocalize-app[bot] + if: github.event_name == 'push' && github.event.head_commit.author.username == 'gitlocalize-app[bot]' + run: | + python scripts/sync_translations.py + + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update translations + branch: dev diff --git a/scripts/prepare_translations.py b/scripts/prepare_translations.py new file mode 100644 index 0000000..46dee45 --- /dev/null +++ b/scripts/prepare_translations.py @@ -0,0 +1,53 @@ +"""this script should run every time the contents of the locale folder change +except if PR originated from @gitlocalize-app +TODO - on commit to dev +""" + +import json +from os.path import dirname +import os + +locale = f"{dirname(dirname(__file__))}/locale" +tx = f"{dirname(dirname(__file__))}/translations" + + +for lang in os.listdir(locale): + intents = {} + dialogs = {} + vocs = {} + regexes = {} + for root, _, files in os.walk(f"{locale}/{lang}"): + b = root.split(f"/{lang}")[-1] + + for f in files: + if b: + fid = f"{b}/{f}" + else: + fid = f + with open(f"{root}/{f}") as fi: + strings = [l.replace("{{", "{").replace("}}", "}") + for l in fi.read().split("\n") if l.strip() + and not l.startswith("#")] + + if fid.endswith(".intent"): + intents[fid] = strings + elif fid.endswith(".dialog"): + dialogs[fid] = strings + elif fid.endswith(".voc"): + vocs[fid] = strings + elif fid.endswith(".rx"): + regexes[fid] = strings + + os.makedirs(f"{tx}/{lang}", exist_ok=True) + if intents: + with open(f"{tx}/{lang}/intents.json", "w") as f: + json.dump(intents, f, indent=4) + if dialogs: + with open(f"{tx}/{lang}/dialogs.json", "w") as f: + json.dump(dialogs, f, indent=4) + if vocs: + with open(f"{tx}/{lang}/vocabs.json", "w") as f: + json.dump(vocs, f, indent=4) + if regexes: + with open(f"{tx}/{lang}/regexes.json", "w") as f: + json.dump(regexes, f, indent=4) diff --git a/scripts/sync_translations.py b/scripts/sync_translations.py new file mode 100644 index 0000000..9322d94 --- /dev/null +++ b/scripts/sync_translations.py @@ -0,0 +1,54 @@ +"""this script should run in every PR originated from @gitlocalize-app +TODO - before PR merge +""" + +import json +from os.path import dirname +import os + +locale = f"{dirname(dirname(__file__))}/locale" +tx = f"{dirname(dirname(__file__))}/translations" + + +for lang in os.listdir(tx): + intents = f"{tx}/{lang}/intents.json" + dialogs = f"{tx}/{lang}/dialogs.json" + vocs = f"{tx}/{lang}/vocabs.json" + regexes = f"{tx}/{lang}/regexes.json" + + if os.path.isfile(intents): + with open(intents) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = [s for s in samples if s] # s may be None + with open(f"{locale}/{lang}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(dialogs): + with open(dialogs) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = [s for s in samples if s] # s may be None + with open(f"{locale}/{lang}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(vocs): + with open(vocs) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = [s for s in samples if s] # s may be None + with open(f"{locale}/{lang}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(regexes): + with open(regexes) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = [s for s in samples if s] # s may be None + with open(f"{locale}/{lang}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + diff --git a/translations/en-us/dialogs.json b/translations/en-us/dialogs.json new file mode 100644 index 0000000..cff0432 --- /dev/null +++ b/translations/en-us/dialogs.json @@ -0,0 +1,10 @@ +{ + "gpt_error.dialog": [ + "I was not able to get an answer from {name}", + "Sorry but something went wrong with the {name} request." + ], + "asking.dialog": [ + "Let me ask {name}", + "Asking {name}" + ] +} \ No newline at end of file diff --git a/translations/fr-fr/dialogs.json b/translations/fr-fr/dialogs.json new file mode 100644 index 0000000..633479b --- /dev/null +++ b/translations/fr-fr/dialogs.json @@ -0,0 +1,10 @@ +{ + "gpt_error.dialog": [ + "Je n'ai pas pu obtenir de r\u00e9ponse venant de {name}", + "D\u00e9sol\u00e9, mais quelque chose s'est mal pass\u00e9 avec la demande \u00e0 {name}" + ], + "asking.dialog": [ + "Laissez moi poser la question \u00e0 {name}", + "Je demande \u00e0 {name}" + ] +} \ No newline at end of file diff --git a/translations/nl-nl/dialogs.json b/translations/nl-nl/dialogs.json new file mode 100644 index 0000000..4f91358 --- /dev/null +++ b/translations/nl-nl/dialogs.json @@ -0,0 +1,10 @@ +{ + "gpt_error.dialog": [ + "Ik kon geen antwoord krijgen van {name}", + "Sorry, maar er is iets misgegaan met het verzoek aan {name}" + ], + "asking.dialog": [ + "Ik vraag het {name}", + "{name} weet het antwoord." + ] +} \ No newline at end of file