]> source.dussan.org Git - nextcloud-server.git/commitdiff
ci: Restrict RTL characters to RTL languages backport/47349/stable30 48308/head
authorJoas Schilling <coding@schilljs.com>
Wed, 18 Sep 2024 09:03:13 +0000 (11:03 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 24 Sep 2024 09:29:46 +0000 (09:29 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
build/translation-checker.php

index 399031c12ae45fdf2add3fecd670a7638d4df671..b6d947ecbf091cbb363a0669cb80fca9d23b1315 100644 (file)
@@ -16,6 +16,35 @@ $untranslatedApps = [
        'testing',
 ];
 
+// Next line only looks messed up, but it works. Don't touch it!
+$rtlCharacters = [
+       '\x{061C}', // ARABIC LETTER MARK
+       '\x{0623}', // ARABIC LETTER ALEF WITH HAMZA ABOVE
+       '\x{200E}', // LEFT-TO-RIGHT MARK
+       '\x{200F}', // RIGHT-TO-LEFT MARK
+       '\x{202A}', // LEFT-TO-RIGHT EMBEDDING
+       '\x{202B}', // RIGHT-TO-LEFT EMBEDDING
+       '\x{202C}', // POP DIRECTIONAL FORMATTING
+       '\x{202D}', // LEFT-TO-RIGHT OVERRIDE
+       '\x{202E}', // RIGHT-TO-LEFT OVERRIDE
+       '\x{2066}', // LEFT-TO-RIGHT ISOLATE
+       '\x{2067}', // RIGHT-TO-LEFT ISOLATE
+       '\x{2068}', // FIRST STRONG ISOLATE
+       '\x{2069}', // POP DIRECTIONAL ISOLATE
+       '\x{206C}', // INHIBIT ARABIC FORM SHAPING
+       '\x{206D}', // ACTIVATE ARABIC FORM SHAPING
+];
+
+$rtlLanguages = [
+       'ar', // Arabic
+       'fa', // Persian
+       'he', // Hebrew
+       'ps', // Pashto,
+       'ug', // 'Uyghurche / Uyghur
+       'ur_PK', // Urdu
+       'uz', // Uzbek Afghan
+];
+
 $valid = 0;
 $errors = [];
 $apps = new \DirectoryIterator(__DIR__ . '/../apps');
@@ -46,6 +75,12 @@ foreach ($directories as $dir) {
                }
 
                $content = file_get_contents($file->getPathname());
+
+               $language = pathinfo($file->getFilename(), PATHINFO_FILENAME);
+               if (!in_array($language, $rtlLanguages, true) && preg_match('/[' . implode('', $rtlCharacters) . ']/u', $content)) {
+                       $errors[] = $file->getPathname() . "\n" . '  ' . 'Contains a RTL limited character in the translations.' . "\n";
+               }
+
                $json = json_decode($content, true);
 
                $translations = json_encode($json['translations']);