From ddf3a2941450ce1470b4fd8ec66cbb8e75769751 Mon Sep 17 00:00:00 2001 From: Emmanuel Pelletier Date: Fri, 19 Jul 2024 12:27:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90(crowdin)=20make=20crowdin=20work?= =?UTF-8?q?=20with=20frontend=20translations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - upload local translation files on push - make crowdin create a pull request when new translations are made through the crowdin website (webhook configured on crowdin-end) --- .github/workflows/crowdin-download.yml | 33 ++++++++++++++++++++++++++ .github/workflows/meet.yml | 20 +++++++++------- Makefile | 18 ++++++-------- crowdin/config.yml | 29 +++++++++++----------- docker-compose.yml | 2 +- env.d/development/crowdin.dist | 4 ++-- src/frontend/package.json | 2 +- 7 files changed, 70 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/crowdin-download.yml diff --git a/.github/workflows/crowdin-download.yml b/.github/workflows/crowdin-download.yml new file mode 100644 index 00000000..855f6c40 --- /dev/null +++ b/.github/workflows/crowdin-download.yml @@ -0,0 +1,33 @@ +name: Download Crowdin translations + +on: + workflow_dispatch: + types: [file-fully-translated] + +permissions: + contents: write + pull-requests: write + +jobs: + crowdin: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download Crowdin files + uses: crowdin/github-action@v2 + with: + upload_sources: false + upload_translations: false + download_translations: true + localization_branch_name: l10n_crowdin_translations + create_pull_request: true + pull_request_title: "New Crowdin translations" + pull_request_body: "New Crowdin pull request with translations" + pull_request_base_branch_name: "main" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} + CROWDIN_BASE_PATH: ${{ github.workspace }} diff --git a/.github/workflows/meet.yml b/.github/workflows/meet.yml index 89207349..b259dab8 100644 --- a/.github/workflows/meet.yml +++ b/.github/workflows/meet.yml @@ -218,12 +218,14 @@ jobs: run: make frontend-i18n-extract - name: Upload files to Crowdin - run: | - docker run \ - --rm \ - -e CROWDIN_API_TOKEN=$CROWDIN_API_TOKEN \ - -e CROWDIN_PROJECT_ID=$CROWDIN_PROJECT_ID \ - -e CROWDIN_BASE_PATH=$CROWDIN_BASE_PATH \ - -v "${{ github.workspace }}:/app" \ - crowdin/cli:3.16.0 \ - crowdin upload sources -c /app/crowdin/config.yml + uses: crowdin/github-action@v2 + with: + config: crowdin/config.yml + upload_sources: true + upload_translations: true + download_translations: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} + CROWDIN_BASE_PATH: ${{ github.workspace }} + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} diff --git a/Makefile b/Makefile index d2b725c6..e7ed0cb7 100644 --- a/Makefile +++ b/Makefile @@ -229,10 +229,13 @@ crowdin-upload: ## Upload source translations to Crowdin @$(COMPOSE_RUN_CROWDIN) upload sources -c crowdin/config.yml .PHONY: crowdin-upload +crowdin-upload-translations: ## Upload translations to Crowdin + @$(COMPOSE_RUN_CROWDIN) upload translations -c crowdin/config.yml +.PHONY: crowdin-upload-translations + i18n-compile: ## compile all translations i18n-compile: \ - back-i18n-compile \ - frontend-i18n-compile + back-i18n-compile .PHONY: i18n-compile i18n-generate: ## create the .pot files and extract frontend messages @@ -295,23 +298,16 @@ help: @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-30s$(RESET) %s\n", $$1, $$2}' .PHONY: help -# FIXME : adapt this command -frontend-i18n-extract: ## Extract the frontend translation inside a json to be used for Crowdin - cd $(PATH_FRONT) && yarn i18n:extract +frontend-i18n-extract: ## Check the frontend code and generate missing translations keys in translation files + cd $(PATH_FRONT) && npm run i18n:extract .PHONY: frontend-i18n-extract -# FIXME : adapt this command frontend-i18n-generate: ## Generate the frontend json files used for Crowdin frontend-i18n-generate: \ crowdin-download-sources \ frontend-i18n-extract .PHONY: frontend-i18n-generate -# FIXME : adapt this command -frontend-i18n-compile: ## Format the Crowdin json files used deploy to the apps - cd $(PATH_FRONT) && yarn i18n:deploy -.PHONY: frontend-i18n-compile - # -- K8S build-k8s-cluster: ## build the kubernetes cluster using kind ./bin/start-kind.sh diff --git a/crowdin/config.yml b/crowdin/config.yml index c0436bf1..d0134c50 100644 --- a/crowdin/config.yml +++ b/crowdin/config.yml @@ -1,7 +1,7 @@ # # Your crowdin's credentials # -api_token_env: CROWDIN_API_TOKEN +api_token_env: CROWDIN_PERSONAL_TOKEN project_id_env: CROWDIN_PROJECT_ID base_path_env: CROWDIN_BASE_PATH @@ -14,16 +14,17 @@ preserve_hierarchy: true # # Files configuration # -files: [ - { - source : "/backend/locale/django.pot", - dest: "/backend-meet.pot", - translation : "/backend/locale/%locale_with_underscore%/LC_MESSAGES/django.po" - }, - { - source: "/frontend/packages/i18n/locales/impress/translations-crowdin.json", - dest: "/frontend-impress.json", - translation: "/frontend/packages/i18n/locales/impress/%two_letters_code%/translations.json", - skip_untranslated_strings: true, - }, -] +files: + [ + { + source: "src/backend/locale/django.pot", + dest: "/backend-meet.pot", + translation: "src/backend/locale/%locale_with_underscore%/LC_MESSAGES/django.po", + }, + { + source: "src/frontend/src/locales/fr/**/*", + translation: "src/frontend/src/locales/%two_letters_code%/**/%original_file_name%", + dest: "/%original_file_name%", + skip_untranslated_strings: true, + }, + ] diff --git a/docker-compose.yml b/docker-compose.yml index f287fc73..3b997d87 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -100,7 +100,7 @@ services: image: jwilder/dockerize crowdin: - image: crowdin/cli:3.16.0 + image: crowdin/cli:4.0.0 volumes: - ".:/app" env_file: diff --git a/env.d/development/crowdin.dist b/env.d/development/crowdin.dist index 1218e3b7..a4edc3d7 100644 --- a/env.d/development/crowdin.dist +++ b/env.d/development/crowdin.dist @@ -1,3 +1,3 @@ -CROWDIN_API_TOKEN=Your-Api-Token +CROWDIN_PERSONAL_TOKEN=Your-Api-Token CROWDIN_PROJECT_ID=Your-Project-Id -CROWDIN_BASE_PATH=/app/src +CROWDIN_BASE_PATH=/app diff --git a/src/frontend/package.json b/src/frontend/package.json index 6730f7c9..4a42f5a3 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -8,7 +8,7 @@ "build": "panda codegen && tsc -b && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", - "i18n:extract": "i18next -c i18next-parser.config.json" + "i18n:extract": "npx i18next -c i18next-parser.config.json" }, "dependencies": { "@livekit/components-react": "2.3.3",