Enhance - Text class (#3012)

try and preserve existing comments when organizing a language
This commit is contained in:
Mafoo 2018-03-06 17:06:56 +00:00 committed by FusionPBX
parent 0ecb6d5929
commit ae55af8848
1 changed files with 13 additions and 0 deletions

View File

@ -140,6 +140,16 @@ class text {
throw new Exception("failed to import text data from '$app_path'");
}
//collect existing comments
$comment = array();
$file_handle = fopen($lang_path, "r");
while (!feof($file_handle)) {
if(preg_match('/\$text\[[\'"](.+)[\'"]\]\[[\'"](.+)[\'"]]\s+=\s+[\'"].*[\'"];\s+\/\/(.+)/', fgets($file_handle), $matches)){
$comment[$matches[0]][$matches[1]] = $matches[2];
}
}
fclose($file_handle);
//open the language file for writing
$lang_file = fopen($lang_path, 'w');
date_default_timezone_set('UTC');
@ -234,6 +244,9 @@ class text {
}
}
}
if(strlen($append) == 0 and array_key_exists($comment, $lang_label) and array_key_exists($comment[$lang_label], $lang_code)) {
$append = " //$comment[$lang_label][$lang_code]";
}
fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");
}
}