1
0

translation-checker.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (json_last_error() !== JSON_ERROR_NONE) {
  45. $errors[] = $file->getPathname() . "\n" . ' ' . json_last_error_msg() . "\n";
  46. } else {
  47. $valid++;
  48. }
  49. }
  50. }
  51. if (count($errors) > 0) {
  52. echo sprintf('ERROR: There were %d errors:', count($errors)) . "\n\n";
  53. echo implode("\n", $errors);
  54. exit(1);
  55. }
  56. echo 'OK: ' . $valid . ' files parse' . "\n";
  57. exit(0);