diff --git a/dev/translation/autotranslator.php b/dev/translation/autotranslator.php index e8fbb0183f7..d705e8716db 100644 --- a/dev/translation/autotranslator.php +++ b/dev/translation/autotranslator.php @@ -31,12 +31,13 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You ar usingr PH for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; exit; } // Include Dolibarr environment require_once($path."../../htdocs/master.inc.php"); +require_once($path."../../htdocs/lib/files.lib.php"); // After this $db is an opened handler to database. We close it at end of file. // Load main language strings @@ -54,7 +55,7 @@ $dir=DOL_DOCUMENT_ROOT."/langs"; // Check parameters if (! isset($argv[2])) { - print "Usage: ".$script_file." lang_code_src lang_code_dest [langfile.lang]\n"; + print "Usage: ".$script_file." lang_code_src lang_code_dest|all [langfile.lang]\n"; print "Example: ".$script_file." en_US pt_PT\n"; print "Rem: lang_code to use can be found on http://www.google.com/language_tools\n"; exit; @@ -71,14 +72,17 @@ if (isset($argv[3])) } print 'Files will be generated/updated in directory '.$dir."\n"; -if (! is_dir($dir.'/'.$argv[2])) +if ($argv[2] != 'all') { - print 'Create directory '.$dir.'/'.$argv[2]."\n"; - $result=mkdir($dir.'/'.$argv[2]); - if (! $result) + if (! is_dir($dir.'/'.$argv[2])) { - $db->close(); - return -1; + print 'Create directory '.$dir.'/'.$argv[2]."\n"; + $result=mkdir($dir.'/'.$argv[2]); + if (! $result) + { + $db->close(); + return -1; + } } } diff --git a/dev/translation/langAutoParser.class.php b/dev/translation/langAutoParser.class.php index 2161ee70139..66dc84f5fe4 100644 --- a/dev/translation/langAutoParser.class.php +++ b/dev/translation/langAutoParser.class.php @@ -50,34 +50,64 @@ class langAutoParser { $fileContent = null; $this->translatedFiles = array(); $refPath = $this->langDir.$this->refLang.self::DIR_SEPARATOR.$file; - $destPath = $this->langDir.$this->destLang.self::DIR_SEPARATOR.$file; - $fileContent = file($refPath,FILE_IGNORE_NEW_LINES | -FILE_SKIP_EMPTY_LINES); + $fileContent = file($refPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); print "Processing file " . $file . ", with ".sizeof($fileContent)." lines
\n"; - // Check destination file presence - if ( ! file_exists( $destPath ) ){ - // No file presente generate file - echo "File not found: " . $file . "
\n"; - echo "Generating file " . $file . "
\n"; - $this->createTranslationFile($destPath); - } - // Translate lines - $fileContentDest = file($destPath,FILE_IGNORE_NEW_LINES | -FILE_SKIP_EMPTY_LINES); - $newlines=0; - foreach($fileContent as $line){ - $key = $this->getLineKey($line); - $value = $this->getLineValue($line); - if ($key && $value) + + // Define target dirs + $targetlangs=array($this->destLang); + if ($this->destLang == 'all') + { + $targetlangs=array(); + + // If we must process all languages + $arraytmp=dol_dir_list($this->langDir,'directories',0); + foreach($arraytmp as $dirtmp) { - $newlines+=$this->translateFileLine($fileContentDest,$file,$key,$value); + if ($dirtmp['name'] === $this->refLang) continue; // We discard source language + if (preg_match('/^en/i',$dirtmp['name'])) continue; // We discard en_* languages + if (preg_match('/^fr/i',$dirtmp['name'])) continue; // We discard fr_* languages + if (preg_match('/^es/i',$dirtmp['name'])) continue; // We discard es_* languages + if (preg_match('/es_CA/i',$dirtmp['name'])) continue; // We discard es_CA language + if (preg_match('/^\./i',$dirtmp['name'])) continue; // We discard files .* + if (preg_match('/^CVS/i',$dirtmp['name'])) continue; // We discard CVS + $targetlangs[]=$dirtmp['name']; } + //var_dump($targetlangs); } - $this->updateTranslationFile($destPath,$file); - echo "New translated lines: " . $newlines . "
\n"; - $this->time_end = date('Y-m-d H:i:s'); - #if ($counter ==3) die('fim'); + // Process translation of source file for each target languages + foreach($targetlangs as $mydestLang) + { + + $destPath = $this->langDir.$mydestLang.self::DIR_SEPARATOR.$file; + // Check destination file presence + if ( ! file_exists( $destPath ) ){ + // No file present, we generate file + echo "File not found: " . $destPath . ". We generate it.
\n"; + $this->createTranslationFile($destPath,$mydestLang); + } + else + { + echo "Updating file: " . $destPath . "
\n"; + } + + // Translate lines + $fileContentDest = file($destPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); + $newlines=0; + foreach($fileContent as $line){ + $key = $this->getLineKey($line); + $value = $this->getLineValue($line); + if ($key && $value) + { + $newlines+=$this->translateFileLine($fileContentDest,$file,$key,$value); + } + } + + $this->updateTranslationFile($destPath,$file); + echo "New translated lines: " . $newlines . "
\n"; + $this->time_end = date('Y-m-d H:i:s'); + #if ($counter ==3) die('fim'); + } } } @@ -99,10 +129,10 @@ FILE_SKIP_EMPTY_LINES); return; } - private function createTranslationFile($path){ + private function createTranslationFile($path,$mydestlang){ $fp = fopen($path, 'w+'); fwrite($fp, "/*\r\n"); - fwrite($fp, " * Language code: {$this->destLang}\r\n"); + fwrite($fp, " * Language code: {$mydestlang}\r\n"); fwrite($fp, " * Automatic generated via autotranslator.php tool\r\n"); fwrite($fp, " * Generation date " . $this->time. "\r\n"); fwrite($fp, " */\r\n");