Skip to content

Commit 4c9051b

Browse files
committed
Extracted translations and added translation settings
# Conflicts: # .github/workflows/pr.yaml # CHANGELOG.md # composer.lock
1 parent ba57449 commit 4c9051b

File tree

36 files changed

+2658
-98
lines changed

36 files changed

+2658
-98
lines changed

.github/workflows/pr.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,23 @@ jobs:
372372
- name: Reverse patch
373373
run: |
374374
docker compose exec phpfpm patch --strip=1 --verbose --input=${{ matrix.patch }} --reverse
375+
376+
check-translations:
377+
runs-on: ubuntu-latest
378+
steps:
379+
- uses: actions/checkout@v4
380+
- uses: arduino/setup-task@v2
381+
with:
382+
repo-token: ${{ secrets.GITHUB_TOKEN }}
383+
384+
- name: Install site
385+
run: |
386+
docker network create frontend
387+
task site-install --yes
388+
389+
- name: Extract translations
390+
run: |
391+
task translations:extract
392+
393+
- run: |
394+
task translations:diff

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ private-files
4545
/playwright/.cache/
4646

4747
config/sync/**/webform.webform.*
48+
49+
web/*/custom/*/translations/*.*.mo

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
* [PR-468](https://github.com/itk-dev/hoeringsportal/pull/468)
10+
Added module and theme translations
911
* [PR-428](https://github.com/itk-dev/hoeringsportal/pull/428)
1012
Upgraded to PHP 8.4
1113
* [PR-494](https://github.com/itk-dev/hoeringsportal/pull/494)

Taskfile.yml

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ vars:
1313
PRETIX_URL: '{{.TASK_PRETIX_URL | default "http://pretix.hoeringsportal.local.itkdev.dk"}}'
1414
PRETIX_ORGANIZER: '{{.TASK_PRETIX_ORGANIZER | default "dpl-cms"}}'
1515

16+
CUSTOM_MODULES:
17+
sh: ls web/modules/custom/*/*.info.yml | xargs basename -s '.info.yml'
18+
19+
CUSTOM_THEMES:
20+
sh: ls web/themes/custom/*/*.info.yml | xargs basename -s '.info.yml'
21+
1622
tasks:
1723
default:
1824
cmds:
@@ -52,12 +58,13 @@ tasks:
5258

5359
site-open:
5460
cmds:
55-
- if command -v open 2>&1 >/dev/null; then open "$(task site-url)"; else echo "$(task site-url)"; fi
61+
# `open` is defined in GitHub Actions (ubuntu-latest), but cannot actually be run without error. Therefore we add `|| true` to prevent errors.
62+
- if command -v open 2>&1 >/dev/null; then open "$(task site-url)" || true; else echo "$(task site-url)"; fi
5663
silent: true
5764

5865
site-open-admin:
5966
cmds:
60-
- if command -v open 2>&1 >/dev/null; then open "{{.URL}}"; else echo "{{.URL}}"; fi
67+
- if command -v open 2>&1 >/dev/null; then open "{{.URL}}" || true; else echo "{{.URL}}"; fi
6168
vars:
6269
URL:
6370
sh: task drush -- user:login --no-browser
@@ -258,3 +265,79 @@ tasks:
258265
# https://www.drupal.org/project/drupal/issues/3496223
259266
- 'task compose -- exec phpfpm sed -i "s/Plural-Forms: nplurals=2; plural=(n > 1);/Plural-Forms: nplurals=2; plural=(n != 1);/" translations/custom-translations.da.po'
260267
silent: true
268+
269+
translations:extract:modules:
270+
cmds:
271+
# https://github.com/go-task/task/discussions/1543
272+
- for:
273+
matrix:
274+
MODULE:
275+
ref: .CUSTOM_MODULES
276+
LANGUAGE:
277+
- da
278+
cmd: |
279+
task drush -- potx single --folder=modules/custom/{{.ITEM.MODULE}}/ --language {{.ITEM.LANGUAGE}} --translations && \
280+
mkdir -p web/modules/custom/{{.ITEM.MODULE}}/translations && \
281+
mv web/general.pot web/modules/custom/{{.ITEM.MODULE}}/translations/{{.ITEM.MODULE}}.{{.ITEM.LANGUAGE}}.po
282+
internal: true
283+
284+
translations:extract:themes:
285+
cmds:
286+
# https://github.com/go-task/task/discussions/1543
287+
- for:
288+
matrix:
289+
THEME:
290+
ref: .CUSTOM_THEMES
291+
LANGUAGE:
292+
- da
293+
# `drush potx` always writes to web/general.pot, so we move this file
294+
# into the desired destination in the `translations` folder inside the
295+
# module folder.
296+
cmd: |
297+
task drush -- potx single --folder=themes/custom/{{.ITEM.THEME}}/ --language {{.ITEM.LANGUAGE}} --translations && \
298+
mkdir -p web/themes/custom/{{.ITEM.THEME}}/translations && \
299+
mv web/general.pot web/themes/custom/{{.ITEM.THEME}}/translations/{{.ITEM.THEME}}.{{.ITEM.LANGUAGE}}.po
300+
internal: true
301+
302+
translations:diff:
303+
cmds:
304+
# Ignore some PO metadata when git diff'ing, e.g.
305+
#
306+
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
307+
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
308+
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' web/*/custom/*/translations
309+
310+
translations:extract:
311+
cmds:
312+
- task drush -- --yes pm:install potx
313+
- task: translations:extract:modules
314+
- task: translations:extract:themes
315+
- task drush -- --yes pm:uninstall potx
316+
silent: true
317+
318+
# @todo Can we use `drush locale:check` and/or `drush locale:update` to update
319+
# module translations without overriding existing translations?
320+
# @todo Do we want to override (existing) translations?
321+
translations:import:modules:
322+
cmds:
323+
- for:
324+
matrix:
325+
MODULE:
326+
ref: .CUSTOM_MODULES
327+
cmd: task drush -- locale:import-all --override=none modules/custom/{{.ITEM.MODULE}}/translations/
328+
silent: true
329+
330+
translations:import:themes:
331+
cmds:
332+
- for:
333+
matrix:
334+
THEME:
335+
ref: .CUSTOM_THEMES
336+
cmd: task drush -- locale:import-all --override=none themes/custom/{{.ITEM.THEME}}/translations/
337+
silent: true
338+
339+
translations:import:all:
340+
cmds:
341+
- task: translations:import:modules
342+
- task: translations:import:themes
343+
silent: true

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"drupal/content_fixtures": "dev-3498162-not-compatible-with",
8585
"drupal/core-dev": "^10.0",
8686
"drupal/masquerade": "^2.0",
87+
"drupal/potx": "^1.1",
8788
"drupal/webprofiler": "^10.3",
8889
"ergebnis/composer-normalize": "^2.44",
8990
"mglaman/phpstan-drupal": "^1.1",

documentation/Translation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Translation
2+
3+
We use [Translation template extractor](https://www.drupal.org/project/potx) to extract translations from custom modules
4+
and themes.
5+
6+
We use the `interface translation` stuff defined in
7+
[locale.api.php](https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.php).
8+
9+
Extract translations by running
10+
11+
``` shell name=translations:extract
12+
task translations:extract
13+
```
14+
15+
Import (extracted) translations by running
16+
17+
``` shell name=translations:import:all
18+
task translations:import:all
19+
```

web/modules/custom/hoeringsportal_citizen_proposal/hoeringsportal_citizen_proposal.info.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ core_version_requirement: ^8.8 || ^9 || ^10
66
dependencies:
77
- twig_tweak:twig_tweak
88
- drupal:symfony_mailer
9+
10+
# https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.php
11+
'interface translation project': hoeringsportal_citizen_proposal
12+
'interface translation server pattern': modules/custom/%project/translations/%project.%language.po

0 commit comments

Comments
 (0)