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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 20 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* Get the text for the correct translation
*
@ -140,15 +141,15 @@ 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);
//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');
@ -170,11 +171,11 @@ class text {
$text = array_merge($temp_A, $temp_B, $text);
unset($temp_A, $temp_B, $temp_C);
}
else {
else {
ksort($text);
}
}
else {
else {
if ($app_path == 'resources') {
foreach($this->languages as $language) {
$label = array_shift($text["language-$language"]);
@ -205,7 +206,7 @@ class text {
$language_name = $this->escape_str($target_lang);
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
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)) {
$append = " //$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]";
}
fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");
}
}
@ -270,7 +271,7 @@ class text {
include $file;
}
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
//check every tag
foreach($text as $lang_codes) {
foreach($lang_codes as $language_code => $value) {
@ -282,7 +283,7 @@ class text {
$languages[$language_code] = 1;
}
}
//set $this->languages up according to what we found
unset($languages['en-us']);
$languages = array_keys($languages);
@ -315,7 +316,7 @@ class text {
include $file;
}
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
//check every tag
foreach($text as $label_name => $values) {
$language_totals['languages']['total']++;
@ -348,8 +349,9 @@ class text {
}
}
foreach ($this->languages as $language_code) {
if (strlen($app['description'][$language_code]) > 0)
$language_totals['app_descriptions'][$language_code]++;
if (strlen($app['description'][$language_code]) > 0) {
$language_totals['app_descriptions'][$language_code]++;
}
}
}