You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

translation-checker.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. __DIR__ . '/../settings/l10n',
  24. ];
  25. $apps = new \DirectoryIterator(__DIR__ . '/../apps');
  26. foreach ($apps as $app) {
  27. if (!file_exists($app->getPathname() . '/l10n')) {
  28. continue;
  29. }
  30. $directories[] = $app->getPathname() . '/l10n';
  31. }
  32. $errors = [];
  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. if (json_last_error() !== JSON_ERROR_NONE) {
  45. echo '[Error] Could not parse: ' . $file->getPathname() . "\n";
  46. echo ' ' . json_last_error_msg() . "\n";
  47. $errors[] = $file->getPathname() . "\n" . ' ' . json_last_error_msg() . "\n";
  48. } else {
  49. echo '[OK] ' . $file->getPathname() . "\n";
  50. }
  51. }
  52. }
  53. echo "\n\n";
  54. if (count($errors) > 0) {
  55. echo sprintf('ERROR: There were %d errors:', count($errors)) . "\n";
  56. echo implode("\n", $errors) . "\n";
  57. exit(1);
  58. }
  59. echo 'OK: all files parse' . "\n";
  60. exit(0);