PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lang.php

http://github.com/vrana/adminer
PHP | 62 lines | 8 code | 0 blank | 54 comment | 5 complexity | 8acd7dba9e8f59e699e59787eaf8ea62 MD5 | raw file
  1. #!/usr/bin/env php
  2. <?php
  3. error_reporting(6135); // errors and warnings
  4. unset($_COOKIE["adminer_lang"]);
  5. $_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
  6. if (isset($_SESSION["lang"])) {
  7. include dirname(__FILE__) . "/adminer/include/lang.inc.php";
  8. if (isset($_SERVER["argv"][2]) || (!isset($langs[$_SESSION["lang"]]) && $_SESSION["lang"] != "xx")) {
  9. echo "Usage: php lang.php [lang]\nPurpose: Update adminer/lang/*.inc.php from source code messages.\n";
  10. exit(1);
  11. }
  12. }
  13. $messages_all = array();
  14. foreach (array_merge(
  15. glob(dirname(__FILE__) . "/adminer/*.php"),
  16. glob(dirname(__FILE__) . "/adminer/include/*.php"),
  17. glob(dirname(__FILE__) . "/adminer/drivers/*.php"),
  18. glob(dirname(__FILE__) . "/editor/*.php"),
  19. glob(dirname(__FILE__) . "/editor/include/*.php")
  20. ) as $filename) {
  21. $file = file_get_contents($filename);
  22. if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
  23. $messages_all += array_combine($matches[1], $matches[2]);
  24. }
  25. }
  26. foreach (glob(dirname(__FILE__) . "/adminer/lang/" . ($_SESSION["lang"] ? $_SESSION["lang"] : "*") . ".inc.php") as $filename) {
  27. $messages = $messages_all;
  28. $file = file_get_contents($filename);
  29. $file = str_replace("\r", "", $file);
  30. preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $file, $matches, PREG_SET_ORDER);
  31. $s = "";
  32. foreach ($matches as $match) {
  33. if (isset($messages[$match[3]])) {
  34. // keep current messages
  35. $s .= "$match[1]$match[2],\n";
  36. unset($messages[$match[3]]);
  37. } else {
  38. // comment deprecated messages
  39. $s .= "$match[1]// $match[2],\n";
  40. }
  41. }
  42. if ($messages) {
  43. if (basename($filename) != "en.inc.php") {
  44. $s .= "\n";
  45. }
  46. foreach ($messages as $idf => $val) {
  47. // add new messages
  48. if ($val == "," && strpos($idf, "%d")) {
  49. $s .= "\t$idf => array(),\n";
  50. } elseif (basename($filename) != "en.inc.php") {
  51. $s .= "\t$idf => null,\n";
  52. }
  53. }
  54. }
  55. $s = "<?php\n\$translations = array(\n$s);\n";
  56. if ($s != $file) {
  57. file_put_contents($filename, $s);
  58. echo "$filename updated.\n";
  59. }
  60. }