Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
docker compose exec phpfpm vendor/bin/drush site:install --existing-config --yes

- run: |
task translation:extract
task translations:extract

# https://github.com/mxschmitt/action-tmate?tab=readme-ov-file#manually-triggered-debug
# Enable tmate debugging if debug logging is enabled (cf.
Expand All @@ -219,4 +219,4 @@ jobs:
if: 1 == runner.debug

- run: |
task translation:diff
task translations:git:diff
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

* [PR-587](https://github.com/itk-dev/deltag.aarhus.dk/pull/587)
Cleaned up translations
* [PR-586](https://github.com/itk-dev/hoeringsportal/pull/586)
* Added course content type
* Added activity wrapper for public_events and courses
Expand Down
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: "3"
dotenv: [".env.local", ".env"]

includes:
translation:
taskfile: ./task/Taskfile.translation.yml
translations:
taskfile: ./task/Taskfile.translations.yml
vars:
TRANSLATION_MODULES:
# - aarhus_hero
Expand Down Expand Up @@ -352,6 +352,7 @@ tasks:
silent: true

translations:import:
desc: Import and update translations
cmds:
- task compose -- exec phpfpm bash -c '(cd web && ../vendor/bin/drush locale:import --type=customized --override=all da ../translations/custom-translations.da.po)'
- task drush -- locale:check
Expand Down
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"drupal/masquerade": "^2.0",
"drupal/webprofiler": "^10.3",
"ergebnis/composer-normalize": "^2.44",
"itk-dev/drupal_translation_extractor": "dev-itk_translation_extractor",
"itk-dev/drupal_translation_extractor": "^1.0",
"mglaman/phpstan-drupal": "^1.1",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1",
Expand Down Expand Up @@ -188,10 +188,6 @@
}
}
},
"itk-dev/drupal_translation_extractor": {
"type": "vcs",
"url": "https://github.com/itk-dev/drupal_translation_extractor"
},
"// @see web/modules/contrib/search_autocomplete/readme.md": {
"type": "package",
"package": {
Expand Down
29 changes: 11 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions documentation/Translations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translations

We use [the "translation server" stuff from the Interface Translation
module](https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.phh) for translations, i.e.
all module and theme [.info.yml
files](https://www.drupal.org/docs/develop/creating-modules/let-drupal-know-about-your-module-with-an-infoyml-file)
contains something like

``` yaml
"interface translation project": «module/theme name»
"interface translation server pattern": «modules|themes»/custom/%project/translations/%project.%language.po
```

and each module/theme has a `translations` folder containing `.po` files with translations.

The translations can be imported via Drush by running these commands:

``` shell
drush locale:check
drush locale:update
drush cache:rebuild
```

To make life a little easier, all this[^1] can be done by running

[^1]: Plus any additional project specific translations.

``` shell
task translations:import
```

## Extracting translations

We use the [Translation extractor module](https://github.com/itk-dev/drupal_translation_extractor) to extract
translations from code (PHP and templates) in (custom) modules and themes.

> [!NOTE]
> The Translation extractor module is only needed (and hence only installed) during development and therefore it's also
> [excluded from configuration synchronization](https://www.drupal.org/node/3079028) in `settings.php`:
>
> ``` php
> # web/sites/default/settings.php
> $settings['config_exclude_modules'][] = 'drupal_translation_extractor';
> ```

Update module and theme translations by running

```sh
task translations:extract
```

See `includes.translation` in [../Taskfile.yml](../Taskfile.yml) and [the included
Taskfile](../task/Taskfile.translation.yml) for details and the list of custom modules and themes that we extract
translations from (it may not make sense to do it for all custom modules and themes).

Use `task translations:diff` to check for any changes. New (or empty) translations are marked as
"[fuzzy](https://www.gnu.org/software/gettext/manual/html_node/Fuzzy-Entries.html)" and default Danish translations for
these must be added.

> [!TIP]
> [Poedit](https://poedit.net/) is an excellent tools for editing po files.
25 changes: 1 addition & 24 deletions documentation/localDevelopment.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,7 @@ task coding-standards:markdown:check

## About translations

We use [the "translation server" stuff from the Interface Translation
module](https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/locale/locale.api.phh) for translations (see
[hoeringsportal.info.yml](web/themes/custom/hoeringsportal/hoeringsportal.info.yml) for an example).

Update and import translations by running

```sh
task drush -- locale:check
task drush -- locale:update
task drush -- cache:rebuild
```

Update module and theme translations by running

```sh
task translation:extract
```

Use `task translation:diff` to check for any changes. New (or empty) translations are marked as
"[fuzzy](https://www.gnu.org/software/gettext/manual/html_node/Fuzzy-Entries.html)" and default Danish translations for
these must be added.

> [!TIP]
> [Poedit](https://poedit.net/) is an excellent tools for editing po files.
See [Translations](Translations.md) for details on how we handle translations.

<details>
<summary>Do we still use/need this</summary>
Expand Down
55 changes: 30 additions & 25 deletions task/Taskfile.translation.yml → task/Taskfile.translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,6 @@ tasks:
find translations web/*/custom/* -name '*.*.po' -ls
silent: true

diff:
desc: "`git diff` all translation files ignoring some date metadata changes"
cmds:
# Ignore some PO metadata when git diff'ing, e.g.
#
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' '*.po'

checkout:
desc: '`git checkout` all translation file changes if only date metadata is changed (cf. `task {{.TASK | replace ":checkout" ":diff" }}`)'
cmds:
- git checkout '*.po'
# https://taskfile.dev/reference/schema#precondition
preconditions:
- sh: task {{.TASK | replace ":checkout" ":diff" }}
msg: |
Translations seem to have changed.

Run

task {{.TASK | replace ":checkout" ":diff" }}

to check.

extract:
cmds:
- task drush -- pm:install drupal_translation_extractor
Expand All @@ -76,7 +51,37 @@ tasks:
ref: .TRANSLATION_LANGUAGES
THEME:
ref: .TRANSLATION_THEMES

# Git restore po files that contain only timestamp changes.
- cmd: |
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))

vars:
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}}
# EXTRACT_COMMAND: task drush -- drupal_translation_extractor:translation:extract --dump-messages --force --sort=asc --output '%source_dir/translations/%project.%language.po' {{.CLI_ARGS}}
# 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}}

git:diff:
desc: "`git diff` all translation files ignoring timestamp changes"
cmds:
# Ignore some PO metadata when git diff'ing, e.g.
#
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' '*.po'

git:restore:
desc: '`git restore` all translation file changes if only timestamps are changed (cf. `task {{.TASK | replace ":restore" ":diff" }}`)'
cmds:
- git restore '*.po'
# https://taskfile.dev/reference/schema#precondition
preconditions:
- sh: task {{.TASK | replace ":restore" ":diff" }}
msg: |
Translations seem to have changed.

Run

task {{.TASK | replace ":restore" ":diff" }}

to check.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_activity
#
msgid ""
msgstr ""
Expand Down Expand Up @@ -46,3 +46,4 @@ msgstr ""

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_anonymous_edit
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_citizen_proposal
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_citizen_proposal_archiving
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_dialogue
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_hearing
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_project_timeline
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module hoeringsportal_public_meeting
#
msgid ""
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion web/modules/custom/itk_admin/translations/itk_admin.da.po
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module itk_admin
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of
# Danish translation of module itk_admin_links
#
msgid ""
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Danish translation of hoeringsportal theme
# Danish translation of theme hoeringsportal
#
msgid ""
msgstr ""
Expand Down