Skip to content

Commit 54d035f

Browse files
authored
Translation improvements (#1670)
- Adds several commands to update/generate translations and to detect unused translations. - Adds a new workflow to add new translation strings from Twig- and/or Php-files into the .po-files for every language. - Runs .mo-file generation as part of the build-process.
1 parent bad213c commit 54d035f

File tree

208 files changed

+21822
-27342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+21822
-27342
lines changed

.github/workflows/php.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ jobs:
108108
--dry-run \
109109
--php-version=${{ steps.setup-php.outputs.php-version }}
110110
111+
- name: Check for unused translations
112+
continue-on-error: true
113+
run: composer translations:unused
114+
111115
security:
112116
name: Security checks
113117
runs-on: [ubuntu-latest]

.github/workflows/translations.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
name: Build translations
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches: ['simplesamlphp-*', 'master']
7+
paths:
8+
- '**.po'
9+
- '**.php'
10+
- '**.twig'
11+
pull_request:
12+
branches: ['*']
13+
paths:
14+
- '**.po'
15+
- '**.php'
16+
- '**.twig'
17+
workflow_dispatch:
18+
19+
jobs:
20+
quality:
21+
name: Quality checks
22+
runs-on: ['ubuntu-latest']
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
#- uses: actions/setup-python@v4
28+
# with:
29+
# python-version: '3.10'
30+
31+
#- run: pip install lint-po
32+
33+
#- name: Lint PO(T) files
34+
# run: |
35+
# lint-po locales/*/LC_MESSAGES/*.po
36+
# lint-po modules/*/locales/*/LC_MESSAGES/*.po
37+
38+
build:
39+
name: Build PO-files
40+
runs-on: ['ubuntu-latest']
41+
needs: quality
42+
43+
outputs:
44+
files_changed: ${{ steps.changes.outputs.files_changed }}
45+
46+
steps:
47+
- name: Setup PHP, with composer and extensions
48+
id: setup-php
49+
# https://github.com/shivammathur/setup-php
50+
uses: shivammathur/setup-php@v2
51+
with:
52+
# Should be the higest supported version, so we can use the newest tools
53+
php-version: '8.2'
54+
coverage: none
55+
56+
- uses: actions/checkout@v3
57+
58+
- name: Install Composer dependencies
59+
run: composer install --no-progress --prefer-dist --optimize-autoloader
60+
61+
- name: Generate new updated PO-files
62+
run: php bin/translations translations:update:translatable --module main
63+
64+
- name: Diff the changes after building
65+
shell: pwsh
66+
# Give an id to the step, so we can reference it later
67+
id: changes
68+
run: |
69+
git add --all
70+
$Diff = git diff --cached --name-only
71+
72+
# Check if any of the translation files have changed (added, modified, deleted)
73+
$SourceDiff = $Diff | Where-Object {
74+
$_ -match '^*.po'
75+
}
76+
echo "Changed files"
77+
echo $SourceDiff
78+
79+
$HasSourceDiff = $SourceDiff.Length -gt 0
80+
echo "($($SourceDiff.Length) changes)"
81+
echo "files_changed=$HasSourceDiff" >> $env:GITHUB_OUTPUT
82+
83+
- name: Zip artifact for deployment
84+
if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed
85+
run: zip build.zip -r .
86+
87+
- uses: actions/upload-artifact@v3
88+
if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed
89+
with:
90+
name: build
91+
path: build.zip
92+
retention-days: 1
93+
94+
commit:
95+
name: Commit changes to assets
96+
needs: build
97+
if: needs.build.outputs.files_changed == 'true' && github.event_name == 'push'
98+
runs-on: [ubuntu-latest]
99+
100+
steps:
101+
- uses: actions/download-artifact@v3
102+
with:
103+
name: build
104+
105+
- name: unzip artifact for deployment
106+
run: |
107+
unzip build.zip
108+
rm build.zip
109+
110+
- name: Add & Commit
111+
uses: EndBug/add-and-commit@v9
112+
with:
113+
# The arguments for the `git add` command (see the paragraph below for more info)
114+
# Default: '.'
115+
add: "['**/*.mo', '**/*.po']"
116+
117+
# Determines the way the action fills missing author name and email. Three options are available:
118+
# - github_actor -> UserName <UserName@users.noreply.github.com>
119+
# - user_info -> Your Display Name <your-actual@email.com>
120+
# - github_actions -> github-actions <email associated with the github logo>
121+
# Default: github_actor
122+
default_author: github_actions
123+
124+
# The message for the commit.
125+
# Default: 'Commit from GitHub Actions (name of the workflow)'
126+
message: "[skip ci] Auto-rebuild translations"
127+
128+
# The way the action should handle pathspec errors from the add and remove commands.
129+
# Three options are available:
130+
# - ignore -> errors will be logged but the step won't fail
131+
# - exitImmediately -> the action will stop right away, and the step will fail
132+
# - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail.
133+
# Default: ignore
134+
pathspec_error_handling: exitImmediately
135+
136+
cleanup:
137+
name: Cleanup artifacts
138+
needs: [build, commit]
139+
runs-on: [ubuntu-latest]
140+
if: |
141+
always() &&
142+
needs.commit.result == 'success' ||
143+
(needs.build.result == 'success' && needs.commit.result == 'skipped')
144+
145+
steps:
146+
- uses: geekyeggo/delete-artifact@v2
147+
with:
148+
name: |
149+
build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata/*
88
/public/assets/*
99
.phpunit.result.cache
1010
.phive
11+
**.mo
1112

1213
# https://www.gitignore.io/api/osx,windows,linux,netbeans,sublimetext,composer,phpstorm,vagrant
1314
# Created by https://www.gitignore.io

bin/get-translatable-strings

Lines changed: 0 additions & 61 deletions
This file was deleted.

bin/translations

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use SimpleSAML\Command\UnusedTranslatableStringsCommand;
5+
use SimpleSAML\Command\UpdateBinaryTranslationsCommand;
6+
use SimpleSAML\Command\UpdateTranslatableStringsCommand;
7+
use Symfony\Component\Console\Application;
8+
9+
umask(000);
10+
set_time_limit(0);
11+
12+
require __DIR__.'/../vendor/autoload.php';
13+
14+
$application = new Application();
15+
$application->add(new UnusedTranslatableStringsCommand());
16+
$application->add(new UpdateBinaryTranslationsCommand());
17+
$application->add(new UpdateTranslatableStringsCommand());
18+
$application->run();

composer.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@
9393
"twig/twig": "^3.3.8"
9494
},
9595
"require-dev": {
96+
"ext-curl": "*",
97+
"ext-pdo_sqlite": "*",
98+
99+
"gettext/php-scanner": "1.3.1",
96100
"mikey179/vfsstream": "~1.6",
97101
"simplesamlphp/simplesamlphp-test-framework": "^1.5.1",
98-
"simplesamlphp/xml-security": "^1.6.0"
102+
"simplesamlphp/xml-security": "^1.6.0",
103+
"symfony/translation": "^6.0"
99104
},
100105
"suggest": {
101106
"predis/predis": "Needed if a Redis server is used to store session information",
@@ -120,5 +125,16 @@
120125
"branch-alias": {
121126
"dev-master": "3.0.x-dev"
122127
}
128+
},
129+
"scripts": {
130+
"translations:unused": "php bin/translations translations:unused",
131+
"translations:update:binary": "php bin/translations translations:update:binary",
132+
"translations:update:translatable": "php bin/translations translations:update:translatable",
133+
"post-install-cmd": [
134+
"php bin/translations translations:update:binary"
135+
],
136+
"post-update-cmd": [
137+
"php bin/translations translations:update:binary"
138+
]
123139
}
124140
}

0 commit comments

Comments
 (0)