Skip to content

Commit

Permalink
Translation improvements (simplesamlphp#1670)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
tvdijen authored Sep 5, 2023
1 parent bad213c commit 54d035f
Show file tree
Hide file tree
Showing 208 changed files with 21,822 additions and 27,342 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ jobs:
--dry-run \
--php-version=${{ steps.setup-php.outputs.php-version }}
- name: Check for unused translations
continue-on-error: true
run: composer translations:unused

security:
name: Security checks
runs-on: [ubuntu-latest]
Expand Down
149 changes: 149 additions & 0 deletions .github/workflows/translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
name: Build translations

on: # yamllint disable-line rule:truthy
push:
branches: ['simplesamlphp-*', 'master']
paths:
- '**.po'
- '**.php'
- '**.twig'
pull_request:
branches: ['*']
paths:
- '**.po'
- '**.php'
- '**.twig'
workflow_dispatch:

jobs:
quality:
name: Quality checks
runs-on: ['ubuntu-latest']

steps:
- uses: actions/checkout@v3

#- uses: actions/setup-python@v4
# with:
# python-version: '3.10'

#- run: pip install lint-po

#- name: Lint PO(T) files
# run: |
# lint-po locales/*/LC_MESSAGES/*.po
# lint-po modules/*/locales/*/LC_MESSAGES/*.po

build:
name: Build PO-files
runs-on: ['ubuntu-latest']
needs: quality

outputs:
files_changed: ${{ steps.changes.outputs.files_changed }}

steps:
- name: Setup PHP, with composer and extensions
id: setup-php
# https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
# Should be the higest supported version, so we can use the newest tools
php-version: '8.2'
coverage: none

- uses: actions/checkout@v3

- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Generate new updated PO-files
run: php bin/translations translations:update:translatable --module main

- name: Diff the changes after building
shell: pwsh
# Give an id to the step, so we can reference it later
id: changes
run: |
git add --all
$Diff = git diff --cached --name-only
# Check if any of the translation files have changed (added, modified, deleted)
$SourceDiff = $Diff | Where-Object {
$_ -match '^*.po'
}
echo "Changed files"
echo $SourceDiff
$HasSourceDiff = $SourceDiff.Length -gt 0
echo "($($SourceDiff.Length) changes)"
echo "files_changed=$HasSourceDiff" >> $env:GITHUB_OUTPUT
- name: Zip artifact for deployment
if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed
run: zip build.zip -r .

- uses: actions/upload-artifact@v3
if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed
with:
name: build
path: build.zip
retention-days: 1

commit:
name: Commit changes to assets
needs: build
if: needs.build.outputs.files_changed == 'true' && github.event_name == 'push'
runs-on: [ubuntu-latest]

steps:
- uses: actions/download-artifact@v3
with:
name: build

- name: unzip artifact for deployment
run: |
unzip build.zip
rm build.zip
- name: Add & Commit
uses: EndBug/add-and-commit@v9
with:
# The arguments for the `git add` command (see the paragraph below for more info)
# Default: '.'
add: "['**/*.mo', '**/*.po']"

# Determines the way the action fills missing author name and email. Three options are available:
# - github_actor -> UserName <[email protected]>
# - user_info -> Your Display Name <[email protected]>
# - github_actions -> github-actions <email associated with the github logo>
# Default: github_actor
default_author: github_actions

# The message for the commit.
# Default: 'Commit from GitHub Actions (name of the workflow)'
message: "[skip ci] Auto-rebuild translations"

# The way the action should handle pathspec errors from the add and remove commands.
# Three options are available:
# - ignore -> errors will be logged but the step won't fail
# - exitImmediately -> the action will stop right away, and the step will fail
# - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail.
# Default: ignore
pathspec_error_handling: exitImmediately

cleanup:
name: Cleanup artifacts
needs: [build, commit]
runs-on: [ubuntu-latest]
if: |
always() &&
needs.commit.result == 'success' ||
(needs.build.result == 'success' && needs.commit.result == 'skipped')
steps:
- uses: geekyeggo/delete-artifact@v2
with:
name: |
build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata/*
/public/assets/*
.phpunit.result.cache
.phive
**.mo

# https://www.gitignore.io/api/osx,windows,linux,netbeans,sublimetext,composer,phpstorm,vagrant
# Created by https://www.gitignore.io
Expand Down
61 changes: 0 additions & 61 deletions bin/get-translatable-strings

This file was deleted.

18 changes: 18 additions & 0 deletions bin/translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env php
<?php

use SimpleSAML\Command\UnusedTranslatableStringsCommand;
use SimpleSAML\Command\UpdateBinaryTranslationsCommand;
use SimpleSAML\Command\UpdateTranslatableStringsCommand;
use Symfony\Component\Console\Application;

umask(000);
set_time_limit(0);

require __DIR__.'/../vendor/autoload.php';

$application = new Application();
$application->add(new UnusedTranslatableStringsCommand());
$application->add(new UpdateBinaryTranslationsCommand());
$application->add(new UpdateTranslatableStringsCommand());
$application->run();
18 changes: 17 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@
"twig/twig": "^3.3.8"
},
"require-dev": {
"ext-curl": "*",
"ext-pdo_sqlite": "*",

"gettext/php-scanner": "1.3.1",
"mikey179/vfsstream": "~1.6",
"simplesamlphp/simplesamlphp-test-framework": "^1.5.1",
"simplesamlphp/xml-security": "^1.6.0"
"simplesamlphp/xml-security": "^1.6.0",
"symfony/translation": "^6.0"
},
"suggest": {
"predis/predis": "Needed if a Redis server is used to store session information",
Expand All @@ -120,5 +125,16 @@
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"scripts": {
"translations:unused": "php bin/translations translations:unused",
"translations:update:binary": "php bin/translations translations:update:binary",
"translations:update:translatable": "php bin/translations translations:update:translatable",
"post-install-cmd": [
"php bin/translations translations:update:binary"
],
"post-update-cmd": [
"php bin/translations translations:update:binary"
]
}
}
Loading

0 comments on commit 54d035f

Please sign in to comment.