White space cleanup on the text class.

This commit is contained in:
FusionPBX
2019-05-25 23:40:51 -06:00
committed by GitHub
parent 03170de257
commit a56a62d00d
+19 -17
View File
@@ -1,4 +1,5 @@
<?php <?php
/** /**
* Get the text for the correct translation * Get the text for the correct translation
* *
@@ -140,15 +141,15 @@ class text {
throw new Exception("failed to import text data from '$app_path'"); throw new Exception("failed to import text data from '$app_path'");
} }
//collect existing comments //collect existing comments
$comment = array(); $comment = array();
$file_handle = fopen($lang_path, "r"); $file_handle = fopen($lang_path, "r");
while (!feof($file_handle)) { while (!feof($file_handle)) {
if(preg_match('/\$text\[[\'"](.+)[\'"]\]\[[\'"](.+)[\'"]]\s+=\s+[\'"].*[\'"];\s+\/\/(.+)/', fgets($file_handle), $matches)){ if(preg_match('/\$text\[[\'"](.+)[\'"]\]\[[\'"](.+)[\'"]]\s+=\s+[\'"].*[\'"];\s+\/\/(.+)/', fgets($file_handle), $matches)){
$comment[$matches[0]][$matches[1]] = $matches[2]; $comment[$matches[0]][$matches[1]] = $matches[2];
} }
} }
fclose($file_handle); fclose($file_handle);
//open the language file for writing //open the language file for writing
$lang_file = fopen($lang_path, 'w'); $lang_file = fopen($lang_path, 'w');
@@ -170,11 +171,11 @@ class text {
$text = array_merge($temp_A, $temp_B, $text); $text = array_merge($temp_A, $temp_B, $text);
unset($temp_A, $temp_B, $temp_C); unset($temp_A, $temp_B, $temp_C);
} }
else { else {
ksort($text); ksort($text);
} }
} }
else { else {
if ($app_path == 'resources') { if ($app_path == 'resources') {
foreach($this->languages as $language) { foreach($this->languages as $language) {
$label = array_shift($text["language-$language"]); $label = array_shift($text["language-$language"]);
@@ -205,7 +206,7 @@ class text {
$language_name = $this->escape_str($target_lang); $language_name = $this->escape_str($target_lang);
fwrite($lang_file, "\$text['language-$target_lang'$spacer]['en-us'] = \"$language_name\";\n"); fwrite($lang_file, "\$text['language-$target_lang'$spacer]['en-us'] = \"$language_name\";\n");
} }
else { else {
//put a line break in between the last tag if it has changed //put a line break in between the last tag if it has changed
if ($last_lang_label != $lang_label) if ($last_lang_label != $lang_label)
@@ -244,9 +245,9 @@ class text {
} }
} }
} }
if(strlen($append) == 0 and array_key_exists($comment, $lang_label) and array_key_exists($comment[$lang_label], $lang_code)) { if(strlen($append) == 0 && array_key_exists($comment, $lang_label) && array_key_exists($comment[$lang_label], $lang_code)) {
$append = " //$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"); fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");
} }
} }
@@ -348,8 +349,9 @@ class text {
} }
} }
foreach ($this->languages as $language_code) { foreach ($this->languages as $language_code) {
if (strlen($app['description'][$language_code]) > 0) if (strlen($app['description'][$language_code]) > 0) {
$language_totals['app_descriptions'][$language_code]++; $language_totals['app_descriptions'][$language_code]++;
}
} }
} }