mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Enhance translator
This commit is contained in:
parent
86006b0f30
commit
8a9417ed59
|
|
@ -14,8 +14,8 @@
|
|||
/**
|
||||
* Class to parse language files and translate them
|
||||
*/
|
||||
class langAutoParser {
|
||||
|
||||
class langAutoParser
|
||||
{
|
||||
private $translatedFiles = array();
|
||||
private $destLang = '';
|
||||
private $refLang = '';
|
||||
|
|
@ -95,7 +95,8 @@ class langAutoParser {
|
|||
|
||||
$destPath = $this->langDir.$mydestLang.self::DIR_SEPARATOR.$file;
|
||||
// Check destination file presence
|
||||
if ( ! file_exists( $destPath ) ){
|
||||
if (! file_exists($destPath))
|
||||
{
|
||||
// No file present, we generate file
|
||||
echo "File not found: " . $destPath . ". We generate it.<br>\n";
|
||||
$this->createTranslationFile($destPath,$mydestLang);
|
||||
|
|
@ -119,7 +120,7 @@ class langAutoParser {
|
|||
|
||||
$this->updateTranslationFile($destPath,$file,$mydestLang);
|
||||
echo "New translated lines: " . $newlines . "<br>\n";
|
||||
#if ($counter ==3) die('fim');
|
||||
//if ($counter ==3) die('fim');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,9 +128,10 @@ class langAutoParser {
|
|||
/**
|
||||
* Update file with new translations
|
||||
*
|
||||
* @param unknown_type $destPath
|
||||
* @param unknown_type $file
|
||||
* @param unknown_type $mydestLang
|
||||
* @param string $destPath Target path
|
||||
* @param string $file File
|
||||
* @param string $mydestLang Target language code
|
||||
* @return void
|
||||
*/
|
||||
private function updateTranslationFile($destPath,$file,$mydestLang)
|
||||
{
|
||||
|
|
@ -154,8 +156,9 @@ class langAutoParser {
|
|||
/**
|
||||
* Create a new translation file
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $mydestlang
|
||||
* @param string $path Path
|
||||
* @param string $mydestlang Target language code
|
||||
* @return void
|
||||
*/
|
||||
private function createTranslationFile($path,$mydestlang)
|
||||
{
|
||||
|
|
@ -172,12 +175,12 @@ class langAutoParser {
|
|||
/**
|
||||
* Put in array translatedFiles[$file], line of a new tranlated pair
|
||||
*
|
||||
* @param $content Existing content of dest file
|
||||
* @param $file Target file name translated (xxxx.lang)
|
||||
* @param $key Key to translate
|
||||
* @param $value Existing value in source file
|
||||
* @param string Language code (ie: fr_FR)
|
||||
* @return int 0=Nothing translated, 1=Record translated
|
||||
* @param string $content Existing content of dest file
|
||||
* @param string $file Target file name translated (xxxx.lang)
|
||||
* @param string $key Key to translate
|
||||
* @param string $value Existing value in source file
|
||||
* @param string $mydestLang Language code (ie: fr_FR)
|
||||
* @return int 0=Nothing translated, 1=Record translated
|
||||
*/
|
||||
private function translateFileLine($content,$file,$key,$value,$mydestLang)
|
||||
{
|
||||
|
|
@ -214,7 +217,8 @@ class langAutoParser {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param unknown_type $line
|
||||
* @param string $line Line found into file
|
||||
* @return string Key
|
||||
*/
|
||||
private function getLineKey($line)
|
||||
{
|
||||
|
|
@ -224,7 +228,8 @@ class langAutoParser {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param unknown_type $line
|
||||
* @param string $line Line found into file
|
||||
* @return string Value
|
||||
*/
|
||||
private function getLineValue($line)
|
||||
{
|
||||
|
|
@ -234,7 +239,8 @@ class langAutoParser {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param unknown_type $lang
|
||||
* @param string $lang Language code
|
||||
* @return array Array
|
||||
*/
|
||||
private function getTranslationFilesArray($lang)
|
||||
{
|
||||
|
|
@ -251,12 +257,12 @@ class langAutoParser {
|
|||
/**
|
||||
* Return translation of a value
|
||||
*
|
||||
* @param $src_texts Array with one value
|
||||
* @param $src_lang
|
||||
* @param $dest_lang
|
||||
* @return string Value translated
|
||||
* @param array $src_texts Array with one value
|
||||
* @param string $src_lang Language code source
|
||||
* @param string $dest_lang Language code target
|
||||
* @return string Value translated
|
||||
*/
|
||||
private function translateTexts($src_texts = array(), $src_lang, $dest_lang)
|
||||
private function translateTexts($src_texts, $src_lang, $dest_lang)
|
||||
{
|
||||
$tmp=explode('_',$src_lang);
|
||||
if ($tmp[0] == $tmp[1]) $src_lang=$tmp[0];
|
||||
|
|
@ -269,11 +275,11 @@ class langAutoParser {
|
|||
|
||||
$src_texts_query = "";
|
||||
$src_text_to_translate=preg_replace('/%s/','SSSSS',join('',$src_texts));
|
||||
|
||||
$src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate);
|
||||
|
||||
$src_texts_query .= "&q=".urlencode($src_text_to_translate);
|
||||
|
||||
$url =
|
||||
"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0".$src_texts_query."&langpair=".urlencode($lang_pair);
|
||||
$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0".$src_texts_query."&langpair=".urlencode($lang_pair);
|
||||
|
||||
// sendRequest
|
||||
// note how referer is set manually
|
||||
|
|
@ -305,7 +311,9 @@ class langAutoParser {
|
|||
|
||||
$rep=$json['responseData']['translatedText'];
|
||||
$rep=preg_replace('/SSSSS/i','%s',$rep);
|
||||
|
||||
$rep=preg_replace('/NNNNN/i','\n\n',$rep);
|
||||
$rep=preg_replace('/'/i','\'',$rep);
|
||||
|
||||
//print "OK ".join('',$src_texts).' => '.$rep."\n";
|
||||
|
||||
return $rep;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user