Skip to content

Commit

Permalink
Improve import and export of translation strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Meorawr committed Jul 5, 2024
1 parent aa34a04 commit 8d8e65f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Upload All Translations
name: Export All Translations
on:
workflow_dispatch: {}

Expand All @@ -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 }}

Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/export-translations.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
name: Process CurseForge Translations
name: Import External Translations
on:
push:
branches:
- main
schedule:
- cron: '0 18 * * *'
workflow_dispatch: {}
Expand All @@ -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 <[email protected]>
reviewers: Meorawr, Solanya

Expand Down
50 changes: 20 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8d8e65f

Please sign in to comment.