From 8d8e65f5c9668278e9ffd53e5588023cfde186f5 Mon Sep 17 00:00:00 2001 From: Daniel Yates Date: Fri, 5 Jul 2024 12:56:53 +0100 Subject: [PATCH] Improve import and export of translation strings Following on from the lessons previously learned in #946 and #948, we'll set the delete-missing-phrases flag _only_ on enUS uploads going forward as that appears to work fine. All other translation uploads will not set the flag. This means that going forward the minimum required process to delete a translation string should just be to remove it from the 'enUS.lua' file; a subsequent import of translation strings would then remove it from all other files automatically. It is, however, totally permissible to remove the string from all files if that would make things clearer. Additionally I've made some of the terminology around the place a bit more consistent for this whole process, eg. preferring to use "translations" instead of "locales" for target names and workflows. For the possibility of using non-CF sources (#949) I've also removed "CurseForge" from the workflow strings. Finally - one functional change; we no longer import translations on commits to main. We continue to export new strings from the enUS file, but that's all. The importing of non-enUS translations continues to happen on the same timer it always has, as well as being manually runnable. --- ...ations.yml => export-all-translations.yml} | 6 +-- .github/workflows/export-translations.yml | 36 +++++++++++++ ...anslations.yml => import-translations.yml} | 22 +++----- Makefile | 50 ++++++++----------- 4 files changed, 66 insertions(+), 48 deletions(-) rename .github/workflows/{upload_all_translations.yml => export-all-translations.yml} (88%) create mode 100644 .github/workflows/export-translations.yml rename .github/workflows/{update_translations.yml => import-translations.yml} (67%) diff --git a/.github/workflows/upload_all_translations.yml b/.github/workflows/export-all-translations.yml similarity index 88% rename from .github/workflows/upload_all_translations.yml rename to .github/workflows/export-all-translations.yml index ae070e530..cd8775be7 100644 --- a/.github/workflows/upload_all_translations.yml +++ b/.github/workflows/export-all-translations.yml @@ -1,5 +1,5 @@ --- -name: Upload All Translations +name: Export All Translations on: workflow_dispatch: {} @@ -16,8 +16,8 @@ jobs: - name: Install Python dependencies run: pip install -r .github/scripts/requirements.txt - - name: Upload CurseForge Translations - run: make push-all-locales + - name: Export All Translations + run: make translations-export-all env: CF_API_KEY: ${{ secrets.CF_API_KEY }} diff --git a/.github/workflows/export-translations.yml b/.github/workflows/export-translations.yml new file mode 100644 index 000000000..3231c7816 --- /dev/null +++ b/.github/workflows/export-translations.yml @@ -0,0 +1,36 @@ +--- +name: Export Translations +on: + push: + branches: + - main + workflow_dispatch: {} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: 'pip' + + - name: Install Python dependencies + run: pip install -r .github/scripts/requirements.txt + + - name: Export Translations + run: make translations-export + env: + CF_API_KEY: ${{ secrets.CF_API_KEY }} + + - name: Send Webhook Notification + if: failure() + run: | + git clone https://github.com/DiscordHooks/github-actions-discord-webhook.git webhook + bash webhook/send.sh $JOB_STATUS $WEBHOOK_URL + env: + JOB_STATUS: ${{ job.status }} + HOOK_OS_NAME: ${{ runner.os }} + WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} + WORKFLOW_NAME: ${{ github.workflow }} diff --git a/.github/workflows/update_translations.yml b/.github/workflows/import-translations.yml similarity index 67% rename from .github/workflows/update_translations.yml rename to .github/workflows/import-translations.yml index 3d2a63633..d50d9b213 100644 --- a/.github/workflows/update_translations.yml +++ b/.github/workflows/import-translations.yml @@ -1,9 +1,6 @@ --- -name: Process CurseForge Translations +name: Import External Translations on: - push: - branches: - - main schedule: - cron: '0 18 * * *' workflow_dispatch: {} @@ -21,24 +18,19 @@ jobs: - name: Install Python dependencies run: pip install -r .github/scripts/requirements.txt - - name: Upload CurseForge Translations - run: make push-locales - env: - CF_API_KEY: ${{ secrets.CF_API_KEY }} - - - name: Download CurseForge Translations - run: make pull-locales + - name: Import External Translations + run: make translations-import env: CF_API_KEY: ${{ secrets.CF_API_KEY }} - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: - commit-message: Import CurseForge Localization - branch: actions/import-cf-localization + commit-message: Import External Translations + branch: actions/import-external-translations delete-branch: true - title: Import CurseForge Localization - body: Automated import of CurseForge localization. + title: Import External Translations + body: Automated import of external translation strings. author: GitHub reviewers: Meorawr, Solanya diff --git a/Makefile b/Makefile index e55cb3971..dc596855f 100644 --- a/Makefile +++ b/Makefile @@ -10,53 +10,43 @@ CF_PROJECT_ID := 75973 LOCALES := enUS deDE esES esMX frFR itIT koKR ptBR ruRU zhCN zhTW LOCALES_DIR := totalRP3/Locales -LOCALE_PUSH_TARGETS := $(addprefix push-locales-,$(LOCALES)) -LOCALE_PULL_TARGETS := $(addprefix pull-locales-,$(LOCALES)) -PUSH_LOCALES := enUS -PULL_LOCALES := $(filter-out enUS,$(LOCALES)) +LOCALES_SCRIPT := $(PYTHON) .github/scripts/localization.py +EXPORT_LOCALES := enUS +IMPORT_LOCALES := $(filter-out $(EXPORT_LOCALES),$(LOCALES)) .DEFAULT: all .DELETE_ON_ERROR: .FORCE: +.PHONY: all check dist libs schema -.PHONY: all all: dist -.PHONY: check -check: .github/scripts/ui.xsd +check: schema pre-commit run --all-files -.PHONY: dist dist: curl -s $(PACKAGER_URL) | bash -s -- -dS -.PHONY: libs libs: curl -s $(PACKAGER_URL) | bash -s -- -cdlz cp -aTv .release/$(LIBDIR) $(LIBDIR) -.PHONY: locales -locales: push-locales pull-locales +schema: + curl -s $(SCHEMA_URL) -o .github/scripts/ui.xsd -.PHONY: push-all-locales -push-all-locales: $(addprefix push-locales-,$(LOCALES)) +.PHONY: translations translations-export translations-export-all translations-import translations-import-all +translations: translations-export translations-import +translations-export: $(addprefix translations-export-,$(EXPORT_LOCALES)) +translations-export-all: $(addprefix translations-export-,$(LOCALES)) +translations-import: $(addprefix translations-import-,$(IMPORT_LOCALES)) +translations-import-all: $(addprefix translations-import-,$(LOCALES)) -.PHONY: push-locales -push-locales: $(addprefix push-locales-,$(PUSH_LOCALES)) +translations-export-enUS: EXPORT_OPTIONS := --delete-missing-phrases -.PHONY: $(LOCALE_PUSH_TARGETS) -$(LOCALE_PUSH_TARGETS): push-locales-%: - $(PYTHON) .github/scripts/localization.py upload --locale $* --project-id $(CF_PROJECT_ID) <$(LOCALES_DIR)/$*.lua +.PHONY: $(addprefix translations-export-,$(LOCALES)) +$(addprefix translations-export-,$(LOCALES)): translations-export-%: + $(LOCALES_SCRIPT) upload --locale $* --project-id $(CF_PROJECT_ID) $(EXPORT_OPTIONS) <$(LOCALES_DIR)/$*.lua -.PHONY: pull-all-locales -pull-all-locales: $(addprefix pull-locales-,$(LOCALES)) - -.PHONY: pull-locales -pull-locales: $(addprefix pull-locales-,$(PULL_LOCALES)) - -.PHONY: $(LOCALE_PULL_TARGETS) -$(LOCALE_PULL_TARGETS): pull-locales-%: - $(PYTHON) .github/scripts/localization.py download --locale $* --project-id $(CF_PROJECT_ID) >$(LOCALES_DIR)/$*.lua - -.github/scripts/ui.xsd: .FORCE - curl -s $(SCHEMA_URL) -o $@ +.PHONY: $(addprefix translations-import-,$(LOCALES)) +$(addprefix translations-import-,$(LOCALES)): translations-import-%: + $(LOCALES_SCRIPT) download --locale $* --project-id $(CF_PROJECT_ID) $(IMPORT_OPTIONS) >$(LOCALES_DIR)/$*.lua