update-locales.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. function log_and_exec($cmd) {
  3. echo "Running: $cmd\n";
  4. return shell_exec($cmd);
  5. }
  6. if (!function_exists('glob_recursive')) {
  7. // Does not support flag GLOB_BRACE
  8. function glob_recursive($pattern, $flags = 0) {
  9. $files = glob($pattern, $flags);
  10. foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
  11. $files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
  12. }
  13. return $files;
  14. }
  15. }
  16. $dir = dirname(dirname(__FILE__));
  17. include_once "$dir/setup.php";
  18. $file_list = glob_recursive("*.php");
  19. $file_list = array_filter($file_list, function($f) {
  20. return strpos($f, "vendor") === false;
  21. });
  22. $source_files = implode(" ", $file_list);
  23. putenv("LANG=C");
  24. log_and_exec("xgettext $source_files -D $dir -o $dir/locales/singlesignon.pot" .
  25. " -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po --keyword=__sso" .
  26. " --package-name=singlesignon --package-version=" . PLUGIN_SINGLESIGNON_VERSION .
  27. " --msgid-bugs-address=https://github.com/edgardmessias/glpi-singlesignon/issues");
  28. // Replace some KEYWORDS
  29. $pot_content = file_get_contents("$dir/locales/singlesignon.pot");
  30. $pot_content = str_replace("CHARSET", "UTF-8", $pot_content);
  31. file_put_contents("$dir/locales/singlesignon.pot", $pot_content);
  32. log_and_exec("msginit --no-translator -i $dir/locales/singlesignon.pot -l en_GB.UTF8 -o $dir/locales/en_GB.po");
  33. $files = glob("$dir/locales/*.po");
  34. // Build .mo
  35. foreach ($files as $file) {
  36. $lang = basename($file, ".po");
  37. if ($lang !== "en_GB") {
  38. log_and_exec("msgmerge --update $dir/locales/$lang.po $dir/locales/singlesignon.pot --lang=$lang --backup=off");
  39. }
  40. log_and_exec("msgfmt $dir/locales/$lang.po -o $dir/locales/$lang.mo");
  41. }