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 374fabd0ef
commit 157db18dc7
+22 -20
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");
} }
} }
@@ -270,7 +271,7 @@ class text {
include $file; include $file;
} }
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php"; include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
//check every tag //check every tag
foreach($text as $lang_codes) { foreach($text as $lang_codes) {
foreach($lang_codes as $language_code => $value) { foreach($lang_codes as $language_code => $value) {
@@ -282,7 +283,7 @@ class text {
$languages[$language_code] = 1; $languages[$language_code] = 1;
} }
} }
//set $this->languages up according to what we found //set $this->languages up according to what we found
unset($languages['en-us']); unset($languages['en-us']);
$languages = array_keys($languages); $languages = array_keys($languages);
@@ -315,7 +316,7 @@ class text {
include $file; include $file;
} }
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php"; include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
//check every tag //check every tag
foreach($text as $label_name => $values) { foreach($text as $label_name => $values) {
$language_totals['languages']['total']++; $language_totals['languages']['total']++;
@@ -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]++;
}
} }
} }