mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
BugFix [master] Languages add missing text placeholders (#2572)
* BugFix [master] Languages add missing text placeholders add placeholders for missing language text reorganise file so languages are in a consistent order with en-us always first, and the remaining stored alphabetically space out tag names to make them line up for readability * add organize_language to text class also add get_languages
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -84,6 +84,94 @@ class text {
|
||||
//return the array of translations
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* reorganize an app_languages.php into a consistent format
|
||||
* @var string $app_path examples: app/exec or core/domains
|
||||
* @var string $no_sort don't sort the text label order
|
||||
*/
|
||||
public function organize_language($app_path = null, $no_sort = false) {
|
||||
|
||||
//fetch the languages
|
||||
$languages = get_languages();
|
||||
|
||||
//clear $text ready for the import
|
||||
$text = array();
|
||||
|
||||
//get the app_languages.php
|
||||
if ($app_path == null) {
|
||||
throw new Exception("\$app_path must be specified");
|
||||
}
|
||||
$lang_path = $_SERVER["PROJECT_ROOT"]."/".$app_path."/app_languages.php";
|
||||
if(!file_exists($lang_path)){
|
||||
throw new Exception("could not find app_languages for '$app_path'");
|
||||
}
|
||||
require $lang_path;
|
||||
|
||||
if (!is_array($text)) {
|
||||
throw new Exception("failed to import text data from '$app_path'");
|
||||
}
|
||||
|
||||
//open the language file for writing
|
||||
$lang_file = fopen($lang_path, 'w');
|
||||
date_default_timezone_set('UTC');
|
||||
fwrite($lang_file, "<?php\n#This file was last reorganized on " . date("jS \of F Y h:i:s A e") . "\n");
|
||||
if(!$no_sort)
|
||||
ksort($text);
|
||||
$last_lang_label = "";
|
||||
foreach ($text as $lang_label => $lang_codes) {
|
||||
|
||||
//behave differently if we are one of the special language-* tags
|
||||
if(preg_match('/\Alanguage-\w{2}(?:-\w{2})?\z/',$lang_label)) {
|
||||
if($lang_label == 'language-en-us')
|
||||
fwrite($lang_file, "\n");
|
||||
$spacer = "";
|
||||
if(strlen($lang_label) == 11)
|
||||
$spacer = " ";
|
||||
fwrite($lang_file, "\$text['$lang_label'$spacer]['en-us'] = \"".array_shift($text[$lang_label])."\";\n");
|
||||
}else{
|
||||
|
||||
//put a line break in between the last tag if it has changed
|
||||
if($last_lang_label != $lang_label)
|
||||
fwrite($lang_file, "\n");
|
||||
foreach ($languages as $lang_code) {
|
||||
$value = "";
|
||||
$append = "";
|
||||
$spacer = "";
|
||||
if(strlen($lang_code) == 2)
|
||||
$spacer = " ";
|
||||
if(array_key_exists($lang_code, $text[$lang_label]))
|
||||
$value = $text[$lang_label][$lang_code];
|
||||
fwrite($lang_file, "\$text['$lang_label']['$lang_code'$spacer] = \"".$value."\";$append\n");
|
||||
}
|
||||
}
|
||||
$last_lang_label = $lang_label;
|
||||
}
|
||||
|
||||
//close the language file
|
||||
fwrite($lang_file, "\n?>\n");
|
||||
fclose($lang_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the list of installed languages detected in resources
|
||||
*/
|
||||
public function get_languages() {
|
||||
|
||||
//define the text array
|
||||
$text = array();
|
||||
|
||||
//get the global app_languages.php so we can get the list of languages
|
||||
include $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
|
||||
|
||||
//get the list of languages, remove en-us, sort it then put en-us in front
|
||||
unset($text['language-name']['en-us']);
|
||||
$languages = array_keys($text['language-name']);
|
||||
asort($languages);
|
||||
array_unshift($languages, 'en-us');
|
||||
return $languages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user