Skip to content
Newer
Older
100755 63 lines (60 sloc) 2.09 KB
56ac3d1 @vrana Mark scripts as executable
authored May 25, 2012
1 #!/usr/bin/env php
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
2 <?php
1bc77f8 Report user errors
jakubvrana authored Aug 28, 2009
3 error_reporting(6135); // errors and warnings
0116b9d Don't set cookie in compile scripts
jakubvrana authored Sep 10, 2009
4 unset($_COOKIE["adminer_lang"]);
5 $_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
6 if (isset($_SESSION["lang"])) {
e1bc7af Change directory structure
jakubvrana authored Jun 13, 2009
7 include dirname(__FILE__) . "/adminer/include/lang.inc.php";
0116b9d Don't set cookie in compile scripts
jakubvrana authored Sep 10, 2009
8 if (isset($_SERVER["argv"][2]) || !isset($langs[$_SESSION["lang"]])) {
ea4fd61 Join translations
jakubvrana authored Jul 22, 2009
9 echo "Usage: php lang.php [lang]\nPurpose: Update adminer/lang/*.inc.php from source code messages.\n";
438ca05 Separate languages
jakubvrana authored Jul 26, 2007
10 exit(1);
11 }
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
12 }
13
430034c Cottage homework
jakubvrana authored Jul 9, 2007
14 $messages_all = array();
ea4fd61 Join translations
jakubvrana authored Jul 22, 2009
15 foreach (array_merge(
16 glob(dirname(__FILE__) . "/adminer/*.php"),
17 glob(dirname(__FILE__) . "/adminer/include/*.php"),
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
18 glob(dirname(__FILE__) . "/adminer/drivers/*.php"),
ea4fd61 Join translations
jakubvrana authored Jul 22, 2009
19 glob(dirname(__FILE__) . "/editor/*.php"),
dc05ef6 Remove empty array
jakubvrana authored Aug 21, 2009
20 glob(dirname(__FILE__) . "/editor/include/*.php")
21 ) as $filename) {
ea4fd61 Join translations
jakubvrana authored Jul 22, 2009
22 $file = file_get_contents($filename);
23 if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) { // lang() always uses apostrophes
24 $messages_all += array_combine($matches[1], $matches[2]);
8943678 sprintf() in lang()
jakubvrana authored Jul 9, 2007
25 }
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
26 }
27
0116b9d Don't set cookie in compile scripts
jakubvrana authored Sep 10, 2009
28 foreach (glob(dirname(__FILE__) . "/adminer/lang/" . ($_SESSION["lang"] ? $_SESSION["lang"] : "*") . ".inc.php") as $filename) {
430034c Cottage homework
jakubvrana authored Jul 9, 2007
29 $messages = $messages_all;
16cdb67 Separate Editor translations
jakubvrana authored Jul 3, 2009
30 $file = file_get_contents($filename);
53804a2 @vrana Immunity against CRLF
authored Oct 16, 2010
31 $file = str_replace("\r", "", $file);
6ab272b @vrana Allow comments in translations
authored Oct 17, 2010
32 preg_match_all("~^(\\s*(?:// [^'].*\\s+)?)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $file, $matches, PREG_SET_ORDER);
c645807 PHP 4 compatibility
jakubvrana authored Aug 7, 2007
33 $s = "";
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
34 foreach ($matches as $match) {
35 if (isset($messages[$match[3]])) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
36 // keep current messages
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
37 $s .= "$match[1]$match[2],\n";
38 unset($messages[$match[3]]);
39 } else {
64ba924 Comments
jakubvrana authored Jun 21, 2009
40 // comment deprecated messages
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
41 $s .= "$match[1]// $match[2],\n";
42 }
43 }
6775ac1 @vrana Whitespace
authored Oct 22, 2010
44 if ($messages) {
87d617c @vrana No extra newline for English
authored Nov 12, 2010
45 if (basename($filename) != "en.inc.php") {
46 $s .= "\n";
47 }
6775ac1 @vrana Whitespace
authored Oct 22, 2010
48 foreach ($messages as $idf => $val) {
49 // add new messages
50 if ($val == "," && strpos($idf, "%d")) {
51 $s .= "\t$idf => array(),\n";
52 } elseif (basename($filename) != "en.inc.php") {
53 $s .= "\t$idf => null,\n";
54 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
55 }
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
56 }
16cdb67 Separate Editor translations
jakubvrana authored Jul 3, 2009
57 $s = "<?php\n\$translations = array(\n$s);\n";
58 if ($s != $file) {
59 fwrite(fopen($filename, "w"), $s); // file_put_contents() since PHP 5
60 echo "$filename updated.\n";
61 }
7418af0 Czech translation
jakubvrana authored Jul 5, 2007
62 }
Something went wrong with that request. Please try again.