From 18725b554bfb2248e531c89db1e2fe07200f3292 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Oct 2015 13:23:45 +0200 Subject: [PATCH] Option MAIN_REPLACE_TRANS_xx_XX is now completely implemented. --- htdocs/core/class/translate.class.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 8235f99d129..89ab0019865 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -580,10 +580,9 @@ class Translate $str=$this->tab_translate[$key]; // Make some string replacement after translation - $replacekey='MAIN_REPLACE_TRANS_'.$this->defaultlang; - if (! empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1,string2:newstring2 + $replacekey='MAIN_REPLACE_TRANS_'.$this->defaultlang; + if (! empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 { - // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX $tmparray=explode(';', $conf->global->$replacekey); foreach($tmparray as $tmp) { @@ -660,17 +659,17 @@ class Translate { $str=$this->tab_translate[$key]; - // Overwrite translation - $overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang; - if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2 + // Make some string replacement after translation + $replacekey='MAIN_REPLACE_TRANS_'.$this->defaultlang; + if (! empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 { - $tmparray=explode(',', $conf->global->$overwritekey); + $tmparray=explode(';', $conf->global->$replacekey); foreach($tmparray as $tmp) { $tmparray2=explode(':',$tmp); - if ($tmparray2[0]==$key) { $str=$tmparray2[1]; break; } + $str=preg_replace('/'.preg_quote($tmparray2[0]).'/',$tmparray2[1],$str); } - } + } if (! preg_match('/^Format/',$key)) { @@ -982,7 +981,8 @@ class Translate } /** - * Return an array with content of all loaded translation keys (found into this->tab_translate) + * Return an array with content of all loaded translation keys (found into this->tab_translate) so + * we get a substitution array we can use for substitutions (for mail or ODT generation for example) * * @return array Array of translation keys lang_key => string_translation_loaded */ @@ -997,9 +997,3 @@ class Translate return $substitutionarray; } } - - -function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext) { - global $str; - print 'str='.$str; -}