Skip to content

Commit 4552bc3

Browse files
committed
Refactored task files
1 parent 2db958a commit 4552bc3

File tree

2 files changed

+146
-118
lines changed

2 files changed

+146
-118
lines changed

Taskfile.yml

Lines changed: 14 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ version: '3'
33
# https://taskfile.dev/usage/#env-files
44
dotenv: ['.env.local', '.env']
55

6+
includes:
7+
translation: ./task/Taskfile.translation.yml
8+
69
vars:
710
# https://taskfile.dev/reference/templating/
811
BASE_URL: '{{.TASK_BASE_URL | default .COMPOSE_SERVER_DOMAIN | default .COMPOSE_DOMAIN | default "https://hoeringsportal.local.itkdev.dk"}}'
@@ -47,12 +50,12 @@ vars:
4750

4851
# - hoeringsportal_admin
4952

50-
# During testing and development, you can override TRANSLATION_MODULES and TRANSLATION_THEMES to not process all modules and themes, e.g.
51-
#
52-
# TRANSLATION_MODULES:
53-
# - hoeringsportal_citizen_proposal
54-
#
55-
# TRANSLATION_THEMES: []
53+
# # During testing and development, you can override TRANSLATION_MODULES and TRANSLATION_THEMES to not process all modules and themes, e.g.
54+
# #
55+
TRANSLATION_MODULES:
56+
- hoeringsportal_citizen_proposal
57+
58+
TRANSLATION_THEMES: []
5659

5760
tasks:
5861
default:
@@ -286,124 +289,17 @@ tasks:
286289

287290
translations:import:
288291
cmds:
289-
- task drush -- locale:import --type=not-customized --override=not-customized da ../translations/custom-translations.da.po
290-
# - task drush -- php:eval "var_export(\Drupal::state()->get('locale.translation.formulae', []))"
291-
# - 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''da'']))->render(), range(0, 5)));"'
292-
# - 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''en'']))->render(), range(0, 5)));"'
292+
- task compose -- exec phpfpm bash -c '(cd web && ../vendor/bin/drush locale:import --type=customized --override=all da ../translations/custom-translations.da.po)'
293+
- task drush -- php:eval "var_export(\Drupal::state()->get('locale.translation.formulae', []))"
294+
- 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''da'']))->render(), range(0, 5)));"'
295+
- 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''en'']))->render(), range(0, 5)));"'
293296
silent: true
294297

295298
translations:export:
296299
cmds:
297-
# @todo Which types should we use here?
298-
- task drush -- locale:export da --types=customized > translations/custom-translations.da.po
300+
- task compose -- exec phpfpm bash -c '(cd web && ../vendor/bin/drush locale:export da --types=customized > ../translations/custom-translations.da.po)'
299301
# Fix plurals spec in PO file
300302
# https://drupalsun.com/eelke/2020/08/17/tale-mistranslated-plurals
301303
# https://www.drupal.org/project/drupal/issues/3496223
302304
- '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'
303305
silent: true
304-
305-
translations:diff:
306-
cmds:
307-
# Ignore some PO metadata when git diff'ing, e.g.
308-
#
309-
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
310-
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
311-
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' web/*/custom/*/translations/*.po translations/*.po
312-
313-
translations:checkout:
314-
cmds:
315-
- git checkout web/*/custom/*/translations/*.po translations/*.po
316-
# https://taskfile.dev/reference/schema#precondition
317-
preconditions:
318-
- sh: task translations:diff
319-
msg: |
320-
Translations seem to have changed.
321-
322-
Run
323-
324-
task translations:diff
325-
326-
to check.
327-
328-
translations:extract:
329-
cmds:
330-
- task drush -- --yes pm:install potx
331-
- task: translations:extract:modules
332-
- task: translations:extract:themes
333-
- task drush -- --yes pm:uninstall potx
334-
silent: true
335-
336-
translations:extract:modules:
337-
cmds:
338-
# https://github.com/go-task/task/discussions/1543
339-
- for:
340-
matrix:
341-
MODULE:
342-
ref: .TRANSLATION_MODULES
343-
LANGUAGE:
344-
- da
345-
cmd: |
346-
task drush -- potx single --folder=modules/custom/{{.ITEM.MODULE}}/ --language {{.ITEM.LANGUAGE}} --translations && \
347-
mkdir -p web/modules/custom/{{.ITEM.MODULE}}/translations && \
348-
mv web/general.pot web/modules/custom/{{.ITEM.MODULE}}/translations/{{.ITEM.MODULE}}.{{.ITEM.LANGUAGE}}.po
349-
internal: true
350-
351-
translations:extract:themes:
352-
cmds:
353-
# https://github.com/go-task/task/discussions/1543
354-
- for:
355-
matrix:
356-
THEME:
357-
ref: .TRANSLATION_THEMES
358-
LANGUAGE:
359-
- da
360-
# `drush potx` always writes to web/general.pot, so we move this file
361-
# into the desired destination in the `translations` folder inside the
362-
# module folder.
363-
cmd: |
364-
task drush -- potx single --folder=themes/custom/{{.ITEM.THEME}}/ --language {{.ITEM.LANGUAGE}} --translations && \
365-
mkdir -p web/themes/custom/{{.ITEM.THEME}}/translations && \
366-
mv web/general.pot web/themes/custom/{{.ITEM.THEME}}/translations/{{.ITEM.THEME}}.{{.ITEM.LANGUAGE}}.po
367-
internal: true
368-
369-
# @todo Can we use `drush locale:check` and/or `drush locale:update` to update
370-
# module translations without overriding existing translations?
371-
# @todo Do we want to override (existing) translations?
372-
translations:import:modules:
373-
cmds:
374-
- for:
375-
matrix:
376-
MODULE:
377-
ref: .TRANSLATION_MODULES
378-
cmd: task drush -- locale:import-all --override=none modules/custom/{{.ITEM.MODULE}}/translations/
379-
internal: true
380-
381-
translations:import:themes:
382-
cmds:
383-
- for:
384-
matrix:
385-
THEME:
386-
ref: .TRANSLATION_THEMES
387-
cmd: task drush -- locale:import-all --override=none themes/custom/{{.ITEM.THEME}}/translations/
388-
internal: true
389-
390-
translations:import:all:
391-
cmds:
392-
- task: translations:import:modules
393-
- task: translations:import:themes
394-
silent: true
395-
396-
config-translations:export:
397-
cmds:
398-
- task drush -- config_translation_po:export da > translations/config-translations.da.po
399-
# Fix plurals spec in PO file
400-
# https://drupalsun.com/eelke/2020/08/17/tale-mistranslated-plurals
401-
# https://www.drupal.org/project/drupal/issues/3496223
402-
- 'task compose -- exec phpfpm sed -i "s/Plural-Forms: nplurals=2; plural=(n > 1);/Plural-Forms: nplurals=2; plural=(n != 1);/" translations/config-translations.da.po'
403-
silent: true
404-
405-
config-translations:import:
406-
cmds:
407-
# Note: We use an empty type to import as not-customized.
408-
- task drush -- config_translation_po:import --type='' --override=not-customized da ../translations/config-translations.da.po
409-
silent: true

task/Taskfile.translation.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
version: '3'
2+
3+
vars:
4+
5+
tasks:
6+
translations:import:
7+
cmds:
8+
- task drush -- locale:import --type=not-customized --override=not-customized da ../translations/custom-translations.da.po
9+
# - task drush -- php:eval "var_export(\Drupal::state()->get('locale.translation.formulae', []))"
10+
# - 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''da'']))->render(), range(0, 5)));"'
11+
# - 'task drush -- php:eval "var_export(array_map(static fn (\$count) => (new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(\$count, ''1 item'', ''@count items'', options: [''langcode'' => ''en'']))->render(), range(0, 5)));"'
12+
silent: true
13+
14+
translations:export:
15+
cmds:
16+
# @todo Which types should we use here?
17+
- task drush -- locale:export da --types=customized > translations/custom-translations.da.po
18+
# Fix plurals spec in PO file
19+
# https://drupalsun.com/eelke/2020/08/17/tale-mistranslated-plurals
20+
# https://www.drupal.org/project/drupal/issues/3496223
21+
- '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'
22+
silent: true
23+
24+
translations:diff:
25+
cmds:
26+
# Ignore some PO metadata when git diff'ing, e.g.
27+
#
28+
# "POT-Creation-Date: 2025-03-12 18:18+0100\n"
29+
# "PO-Revision-Date: 2025-03-12 18:18+0100\n"
30+
- git diff --exit-code --ignore-blank-lines --ignore-matching-lines='^"PO.*-Date' web/*/custom/*/translations/*.po translations/*.po
31+
32+
translations:checkout:
33+
cmds:
34+
- git checkout web/*/custom/*/translations/*.po translations/*.po
35+
# https://taskfile.dev/reference/schema#precondition
36+
preconditions:
37+
- sh: task {{.TASK | replace ":checkout" ":diff" }}
38+
msg: |
39+
Translations seem to have changed.
40+
41+
Run
42+
43+
task {{.TASK | replace ":checkout" ":diff" }}
44+
45+
to check.
46+
47+
translations:extract:
48+
cmds:
49+
- task drush -- --yes pm:install potx
50+
- task: translations:extract:modules
51+
- task: translations:extract:themes
52+
- task drush -- --yes pm:uninstall potx
53+
silent: true
54+
requires:
55+
vars:
56+
- TRANSLATION_MODULES
57+
- TRANSLATION_THEMES
58+
59+
translations:extract:modules:
60+
cmds:
61+
# https://github.com/go-task/task/discussions/1543
62+
- for:
63+
matrix:
64+
MODULE:
65+
ref: .TRANSLATION_MODULES
66+
LANGUAGE:
67+
- da
68+
cmd: |
69+
task drush -- potx single --folder=modules/custom/{{.ITEM.MODULE}}/ --language {{.ITEM.LANGUAGE}} --translations && \
70+
mkdir -p web/modules/custom/{{.ITEM.MODULE}}/translations && \
71+
mv web/general.pot web/modules/custom/{{.ITEM.MODULE}}/translations/{{.ITEM.MODULE}}.{{.ITEM.LANGUAGE}}.po
72+
internal: true
73+
74+
translations:extract:themes:
75+
cmds:
76+
# https://github.com/go-task/task/discussions/1543
77+
- for:
78+
matrix:
79+
THEME:
80+
ref: .TRANSLATION_THEMES
81+
LANGUAGE:
82+
- da
83+
# `drush potx` always writes to web/general.pot, so we move this file
84+
# into the desired destination in the `translations` folder inside the
85+
# module folder.
86+
cmd: |
87+
task drush -- potx single --folder=themes/custom/{{.ITEM.THEME}}/ --language {{.ITEM.LANGUAGE}} --translations && \
88+
mkdir -p web/themes/custom/{{.ITEM.THEME}}/translations && \
89+
mv web/general.pot web/themes/custom/{{.ITEM.THEME}}/translations/{{.ITEM.THEME}}.{{.ITEM.LANGUAGE}}.po
90+
internal: true
91+
92+
# @todo Can we use `drush locale:check` and/or `drush locale:update` to update
93+
# module translations without overriding existing translations?
94+
# @todo Do we want to override (existing) translations?
95+
translations:import:modules:
96+
cmds:
97+
- for:
98+
matrix:
99+
MODULE:
100+
ref: .TRANSLATION_MODULES
101+
cmd: task drush -- locale:import-all --override=none modules/custom/{{.ITEM.MODULE}}/translations/
102+
internal: true
103+
104+
translations:import:themes:
105+
cmds:
106+
- for:
107+
matrix:
108+
THEME:
109+
ref: .TRANSLATION_THEMES
110+
cmd: task drush -- locale:import-all --override=none themes/custom/{{.ITEM.THEME}}/translations/
111+
internal: true
112+
113+
translations:import:all:
114+
cmds:
115+
- task: translations:import:modules
116+
- task: translations:import:themes
117+
silent: true
118+
119+
config-translations:export:
120+
cmds:
121+
- task drush -- config_translation_po:export da > translations/config-translations.da.po
122+
# Fix plurals spec in PO file
123+
# https://drupalsun.com/eelke/2020/08/17/tale-mistranslated-plurals
124+
# https://www.drupal.org/project/drupal/issues/3496223
125+
- 'task compose -- exec phpfpm sed -i "s/Plural-Forms: nplurals=2; plural=(n > 1);/Plural-Forms: nplurals=2; plural=(n != 1);/" translations/config-translations.da.po'
126+
silent: true
127+
128+
config-translations:import:
129+
cmds:
130+
# Note: We use an empty type to import as not-customized.
131+
- task drush -- config_translation_po:import --type='' --override=not-customized da ../translations/config-translations.da.po
132+
silent: true

0 commit comments

Comments
 (0)