Skip to content

Commit

Permalink
feat(translations): Allow to validate the sync setup of an app
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 10, 2025
1 parent a33e8f2 commit 21e15c6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
4 changes: 2 additions & 2 deletions translations-app/handleAppTranslations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ for version in $versions
do
# skip if the branch doesn't exist
if git branch -r | egrep "^\W*origin/$version$" ; then
echo "Valid branch"
echo "Valid branch: $version"
else
echo "Invalid branch"
echo "Invalid branch: $version"
continue
fi
git checkout $version
Expand Down
35 changes: 30 additions & 5 deletions translations/translationtool/src/translationtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function checkMissingTranslations(string $entry, string $tmpfname): void
}
}

public function createNextcloudFiles(): void {
public function createNextcloudFiles(bool $forceEmptyTranslations = false): void {
foreach ($this->findLanguages() as $language) {
$poFile = $this->translationsPath . '/' . $language . '/' . $this->name . '.po';
$translations = Gettext\Translations::fromPoFile($poFile);
Expand All @@ -148,7 +148,7 @@ public function createNextcloudFiles(): void {
$plurals = $translations->getHeader('Plural-Forms') ?? 'nplurals=2; plural=(n != 1);';

foreach ($translations as $translation) {
if (!$translation->hasTranslation()) {
if (!$forceEmptyTranslations && !$translation->hasTranslation()) {
// Skip if we have no translation (for the base form)
continue;
}
Expand Down Expand Up @@ -562,14 +562,36 @@ public function createPotFiles(): void {
}
}

public function convertPoFiles(): void {
public function convertPoFiles(bool $forceEmptyTranslations = false): void {
foreach ($this->appPaths as $appPath) {
$this->log('Application path: ' . $appPath);
$app = new TranslatableApp($appPath, $this->translationPath, $this);
$app->createNextcloudFiles();
$app->createNextcloudFiles($forceEmptyTranslations);
}
}

public function prepareSourceValidation(): void {
$this->log('Generating POT files');
$this->createPotFiles();

$this->log('Generating en_GB PO files');
foreach ($this->appPaths as $appPath) {
$this->log('Application path: ' . $appPath);

$name = basename($appPath);
$pot = $this->translationPath . '/templates/' . $name . '.pot';
$po = $this->translationPath . '/en_GB/' . $name . '.po';
if (!mkdir($dir = dirname($po)) && !is_dir($dir)) {
$this->log(sprintf('Directory "%s" was not created', $dir));
}
$output = [];
exec('xgettext ' . ' -o ' . $po . ' ' . $pot, $output);
}

$this->log('Converting en_GB PO files to enGB.json');
$this->convertPoFiles(true);
}

public function checkFiles(): void {
// iterate over all apps
foreach ($this->appPaths as $appPath) {
Expand Down Expand Up @@ -658,6 +680,7 @@ public function log(string $message): void {
break;
case 'create-pot-files':
case 'convert-po-files':
case 'prepare-source-validation':
case 'check-files':
$task = $arg;
break;
Expand All @@ -680,7 +703,7 @@ public function log(string $message): void {
echo 'Usage:' . PHP_EOL;
echo ' ' . $toolName . ' <task> [<appName>]' . PHP_EOL;
echo 'Arguments:' . PHP_EOL;
echo ' task: One of: create-pot-files, convert-po-files, check-files' . PHP_EOL;
echo ' task: One of: create-pot-files, convert-po-files, prepare-source-validation, check-files' . PHP_EOL;
echo 'Options:'. PHP_EOL;
echo ' -v, --verbose Verbose mode'. PHP_EOL;
echo ' -h, --help Display command usage'. PHP_EOL;
Expand All @@ -697,6 +720,8 @@ public function log(string $message): void {
$tool->createPotFiles();
} elseif ($task === 'convert-po-files') {
$tool->convertPoFiles();
} elseif ($task === 'prepare-source-validation') {
$tool->prepareSourceValidation();
} elseif ($task === 'check-files') {
$tool->checkFiles();
} else {
Expand Down
Binary file modified translations/translationtool/translationtool.phar
Binary file not shown.
50 changes: 50 additions & 0 deletions translations/validateSyncSetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

if [ ! -d "temp" ]; then
mkdir "temp"
fi

cd temp
echo $PWD

versions='main master stable31 stable30 stable29'
if [ -f '.tx/backport' ]; then
versions="main master $(cat .tx/backport)"
fi

git clone git@github.com:$1/$2
cd $2

for version in $versions
do
# skip if the branch doesn't exist
if git branch -r | egrep "^\W*origin/$version$" ; then
echo "Validating branch: $version"
echo "---"
else
echo "Invalid branch: $version"
continue
fi
git checkout $version

if [ ! -f '.tx/config' ]; then
echo 'Translation config .tx/config is missing'
fi

if [ ! -f 'l10n/.gitkeep' ]; then
echo 'l10n/.gitkeep is missing'
fi

if [ ! -f '.l10nignore' ]; then
echo 'Consider adding .l10nignore and exclude 3rd-party directories like vendor/ and vendor-bin/ as well as directories with compiled javascript assets like js/'
fi

echo 'Checking translation source strings'

php ../../translations/translationtool/translationtool.phar prepare-source-validation
../../translations/validateTranslationFiles.sh .
done

cd ../../
rm -rf temp

0 comments on commit 21e15c6

Please sign in to comment.