Skip to content

Commit d3c2c7b

Browse files
authored
Merge pull request #587 from itk-dev/feature/translations-cleanup
Translations cleanup
2 parents 88afe8f + b3de2f7 commit d3c2c7b

19 files changed

Lines changed: 123 additions & 87 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ jobs:
207207
docker compose exec phpfpm vendor/bin/drush site:install --existing-config --yes
208208
209209
- run: |
210-
task translation:extract
210+
task translations:extract
211211
212212
# https://github.com/mxschmitt/action-tmate?tab=readme-ov-file#manually-triggered-debug
213213
# Enable tmate debugging if debug logging is enabled (cf.
@@ -219,4 +219,4 @@ jobs:
219219
if: 1 == runner.debug
220220

221221
- run: |
222-
task translation:diff
222+
task translations:git:diff

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-587](https://github.com/itk-dev/deltag.aarhus.dk/pull/587)
10+
Cleaned up translations
911
* [PR-586](https://github.com/itk-dev/hoeringsportal/pull/586)
1012
* Added course content type
1113
* Added activity wrapper for public_events and courses

Taskfile.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version: "3"
44
dotenv: [".env.local", ".env"]
55

66
includes:
7-
translation:
8-
taskfile: ./task/Taskfile.translation.yml
7+
translations:
8+
taskfile: ./task/Taskfile.translations.yml
99
vars:
1010
TRANSLATION_MODULES:
1111
# - aarhus_hero
@@ -352,6 +352,7 @@ tasks:
352352
silent: true
353353

354354
translations:import:
355+
desc: Import and update translations
355356
cmds:
356357
- task compose -- exec phpfpm bash -c '(cd web && ../vendor/bin/drush locale:import --type=customized --override=all da ../translations/custom-translations.da.po)'
357358
- task drush -- locale:check

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"drupal/masquerade": "^2.0",
9797
"drupal/webprofiler": "^10.3",
9898
"ergebnis/composer-normalize": "^2.44",
99-
"itk-dev/drupal_translation_extractor": "dev-itk_translation_extractor",
99+
"itk-dev/drupal_translation_extractor": "^1.0",
100100
"mglaman/phpstan-drupal": "^1.1",
101101
"phpstan/extension-installer": "^1.2",
102102
"phpstan/phpstan-deprecation-rules": "^1.1",
@@ -188,10 +188,6 @@
188188
}
189189
}
190190
},
191-
"itk-dev/drupal_translation_extractor": {
192-
"type": "vcs",
193-
"url": "https://github.com/itk-dev/drupal_translation_extractor"
194-
},
195191
"// @see web/modules/contrib/search_autocomplete/readme.md": {
196192
"type": "package",
197193
"package": {

composer.lock

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/Translations.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Translations
2+
3+
We use [the "translation server" stuff from the Interface Translation
4+
module](https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.phh) for translations, i.e.
5+
all module and theme [.info.yml
6+
files](https://www.drupal.org/docs/develop/creating-modules/let-drupal-know-about-your-module-with-an-infoyml-file)
7+
contains something like
8+
9+
``` yaml
10+
"interface translation project": «module/theme name»
11+
"interface translation server pattern": «modules|themes»/custom/%project/translations/%project.%language.po
12+
```
13+
14+
and each module/theme has a `translations` folder containing `.po` files with translations.
15+
16+
The translations can be imported via Drush by running these commands:
17+
18+
``` shell
19+
drush locale:check
20+
drush locale:update
21+
drush cache:rebuild
22+
```
23+
24+
To make life a little easier, all this[^1] can be done by running
25+
26+
[^1]: Plus any additional project specific translations.
27+
28+
``` shell
29+
task translations:import
30+
```
31+
32+
## Extracting translations
33+
34+
We use the [Translation extractor module](https://github.com/itk-dev/drupal_translation_extractor) to extract
35+
translations from code (PHP and templates) in (custom) modules and themes.
36+
37+
> [!NOTE]
38+
> The Translation extractor module is only needed (and hence only installed) during development and therefore it's also
39+
> [excluded from configuration synchronization](https://www.drupal.org/node/3079028) in `settings.php`:
40+
>
41+
> ``` php
42+
> # web/sites/default/settings.php
43+
> $settings['config_exclude_modules'][] = 'drupal_translation_extractor';
44+
> ```
45+
46+
Update module and theme translations by running
47+
48+
```sh
49+
task translations:extract
50+
```
51+
52+
See `includes.translation` in [../Taskfile.yml](../Taskfile.yml) and [the included
53+
Taskfile](../task/Taskfile.translation.yml) for details and the list of custom modules and themes that we extract
54+
translations from (it may not make sense to do it for all custom modules and themes).
55+
56+
Use `task translations:diff` to check for any changes. New (or empty) translations are marked as
57+
"[fuzzy](https://www.gnu.org/software/gettext/manual/html_node/Fuzzy-Entries.html)" and default Danish translations for
58+
these must be added.
59+
60+
> [!TIP]
61+
> [Poedit](https://poedit.net/) is an excellent tools for editing po files.

documentation/localDevelopment.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,7 @@ task coding-standards:markdown:check
158158

159159
## About translations
160160

161-
We use [the "translation server" stuff from the Interface Translation
162-
module](https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.phh) for translations (see
163-
[hoeringsportal.info.yml](web/themes/custom/hoeringsportal/hoeringsportal.info.yml) for an example).
164-
165-
Update and import translations by running
166-
167-
```sh
168-
task drush -- locale:check
169-
task drush -- locale:update
170-
task drush -- cache:rebuild
171-
```
172-
173-
Update module and theme translations by running
174-
175-
```sh
176-
task translation:extract
177-
```
178-
179-
Use `task translation:diff` to check for any changes. New (or empty) translations are marked as
180-
"[fuzzy](https://www.gnu.org/software/gettext/manual/html_node/Fuzzy-Entries.html)" and default Danish translations for
181-
these must be added.
182-
183-
> [!TIP]
184-
> [Poedit](https://poedit.net/) is an excellent tools for editing po files.
161+
See [Translations](Translations.md) for details on how we handle translations.
185162

186163
<details>
187164
<summary>Do we still use/need this</summary>
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,6 @@ tasks:
3131
find translations web/*/custom/* -name '*.*.po' -ls
3232
silent: true
3333

34-
diff:
35-
desc: "`git diff` all translation files ignoring some date metadata changes"
36-
cmds:
37-
# Ignore some PO metadata when git diff'ing, e.g.
38-
#
39-
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
40-
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
41-
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' '*.po'
42-
43-
checkout:
44-
desc: '`git checkout` all translation file changes if only date metadata is changed (cf. `task {{.TASK | replace ":checkout" ":diff" }}`)'
45-
cmds:
46-
- git checkout '*.po'
47-
# https://taskfile.dev/reference/schema#precondition
48-
preconditions:
49-
- sh: task {{.TASK | replace ":checkout" ":diff" }}
50-
msg: |
51-
Translations seem to have changed.
52-
53-
Run
54-
55-
task {{.TASK | replace ":checkout" ":diff" }}
56-
57-
to check.
58-
5934
extract:
6035
cmds:
6136
- task drush -- pm:install drupal_translation_extractor
@@ -76,7 +51,37 @@ tasks:
7651
ref: .TRANSLATION_LANGUAGES
7752
THEME:
7853
ref: .TRANSLATION_THEMES
54+
55+
# Git restore po files that contain only timestamp changes.
56+
- cmd: |
57+
git restore $(comm -23 <(git diff --name-only --ignore-blank-lines '*.po' | sort) <(git diff --name-only --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' '*.po' | sort))
58+
7959
vars:
8060
EXTRACT_COMMAND: task drush -- drupal_translation_extractor:translation:extract --dump-messages --force --sort=asc --output '%source_dir/translations/%project.%language.po' --no-fill {{.CLI_ARGS}}
8161
# EXTRACT_COMMAND: task drush -- drupal_translation_extractor:translation:extract --dump-messages --force --sort=asc --output '%source_dir/translations/%project.%language.po' {{.CLI_ARGS}}
8262
# EXTRACT_COMMAND: task drush -- drupal_translation_extractor:translation:extract --dump-messages --force --sort=asc --output '%source_dir/translations/%project.%language.po' --fill-from-string-storage {{.CLI_ARGS}}
63+
64+
git:diff:
65+
desc: "`git diff` all translation files ignoring timestamp changes"
66+
cmds:
67+
# Ignore some PO metadata when git diff'ing, e.g.
68+
#
69+
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
70+
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
71+
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' '*.po'
72+
73+
git:restore:
74+
desc: '`git restore` all translation file changes if only timestamps are changed (cf. `task {{.TASK | replace ":restore" ":diff" }}`)'
75+
cmds:
76+
- git restore '*.po'
77+
# https://taskfile.dev/reference/schema#precondition
78+
preconditions:
79+
- sh: task {{.TASK | replace ":restore" ":diff" }}
80+
msg: |
81+
Translations seem to have changed.
82+
83+
Run
84+
85+
task {{.TASK | replace ":restore" ":diff" }}
86+
87+
to check.

web/modules/custom/hoeringsportal_activity/translations/hoeringsportal_activity.da.po

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Danish translation of
1+
# Danish translation of module hoeringsportal_activity
22
#
33
msgid ""
44
msgstr ""
@@ -46,3 +46,4 @@ msgstr ""
4646

4747
msgid "Examples: Public meeting, Guided walk, Workshop."
4848
msgstr "Eksempler: Borgermøder, guidede ture eller workshops."
49+

web/modules/custom/hoeringsportal_anonymous_edit/translations/hoeringsportal_anonymous_edit.da.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Danish translation of
1+
# Danish translation of module hoeringsportal_anonymous_edit
22
#
33
msgid ""
44
msgstr ""

0 commit comments

Comments
 (0)