translation-checker.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. $directories = [
  22. __DIR__ . '/../core/l10n',
  23. ];
  24. $apps = new \DirectoryIterator(__DIR__ . '/../apps');
  25. foreach ($apps as $app) {
  26. if (!file_exists($app->getPathname() . '/l10n')) {
  27. continue;
  28. }
  29. $directories[] = $app->getPathname() . '/l10n';
  30. }
  31. $errors = [];
  32. $valid = 0;
  33. foreach ($directories as $dir) {
  34. if (!file_exists($dir)) {
  35. continue;
  36. }
  37. $directory = new \DirectoryIterator($dir);
  38. foreach ($directory as $file) {
  39. if ($file->getExtension() !== 'json') {
  40. continue;
  41. }
  42. $content = file_get_contents($file->getPathname());
  43. $json = json_decode($content, true);
  44. $translations = json_encode($json['translations']);
  45. if (strpos($translations, '|') !== false) {
  46. $errors[] = $file->getPathname() . "\n" . ' ' . 'Contains a | in the translations' . "\n";
  47. }
  48. if (json_last_error() !== JSON_ERROR_NONE) {
  49. $errors[] = $file->getPathname() . "\n" . ' ' . json_last_error_msg() . "\n";
  50. } else {
  51. $valid++;
  52. }
  53. }
  54. }
  55. if (count($errors) > 0) {
  56. echo sprintf('ERROR: There were %d errors:', count($errors)) . "\n\n";
  57. echo implode("\n", $errors);
  58. exit(1);
  59. }
  60. echo 'OK: ' . $valid . ' files parse' . "\n";
  61. exit(0);