1<?php 2 3/** 4 * Script to fund untraslated files 5 * 6 * only for development 7 */ 8 9// only from cli 10if (php_sapi_name() != "cli") { die("Cli only!"); } 11 12 13// search for all translated words and put them to array 14$untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && grep -r '_(' * ")); 15// loop and search 16foreach ($untranslated as $u) { 17 // find string 18 $str = get_string_between($u, "_('", "')"); 19 // remove "" and ' 20 $str = trim($str, "',\""); 21 // search for invalud content and remove 22 if (substr($str, 0, 1)!="$") { 23 $all_translations[] = $str; 24 } 25 26 // find string 27 $str = get_string_between($u, '_("', '")'); 28 // remove "" and ' 29 $str = trim($str, "',\""); 30 // search for invalud content and remove 31 if (substr($str, 0, 1)!="$") { 32 $all_translations[] = $str; 33 } 34} 35//unique 36$all_translations = array_unique($all_translations); 37 38 39// search all existing translations 40$untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && more functions/locale/en/LC_MESSAGES/phpipam.po")); 41// loop and create 42foreach ($untranslated as $u) { 43 // search for string 44 if (substr($u, 0, 7)=='msgid "') { 45 $u = str_replace("msgid ", "", $u); 46 $u = trim($u, '"'); 47 $translated[] = $u; 48 } 49} 50 51// remove existing from unique 52foreach ($all_translations as $tr) { 53 if (!in_array($tr, $translated)) { 54 $new[] = $tr; 55 } 56} 57 58// format 59foreach ($new as $tr) { 60 $text[] = "msgid \"$tr\""; 61 $text[] = "msgstr \"\"\n"; 62} 63// join text 64$text = implode("\n",$text); 65 66 67// output changes 68print_r($text); 69 70 71// returns string between 2 separators 72function get_string_between($string, $start, $end){ 73 $string = " ".$string; 74 $ini = strpos($string,$start); 75 if ($ini == 0) return ""; 76 $ini += strlen($start); 77 $len = strpos($string,$end,$ini) - $ini; 78 return substr($string,$ini,$len); 79} 80?>