mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
BugFix [master] language update (#2628)
Imported Found language ro as ro-ro Romanian (tested by reverse translation) Add placeholders for all found languages Add new missing flags Enhancements to text class * improved sort to keep language-* tags organized at the top * if a language is missing a name tag, add it * changed organizer to not add a final \n * corrected some indenting * added detect_all_languages that attempts to find any languages that haven't been defined in resources/app_languages.php * added language_totals, this is used by the optional languages application to calculate how complete a language is
This commit is contained in:
@@ -6,36 +6,37 @@
|
||||
*/
|
||||
class text {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public $languages;
|
||||
public $legacy_map = array (
|
||||
'he' => 'he-il',
|
||||
'pl' => 'pl-pl',
|
||||
'uk' => 'uk-ua',
|
||||
'ro' => 'ro-ro',
|
||||
'he-il' => 'he',
|
||||
'pl-pl' => 'pl',
|
||||
'uk-ua' => 'uk',
|
||||
'ro-ro' => 'ro',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//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');
|
||||
|
||||
|
||||
//support legacy variable
|
||||
$_SESSION['app']['languages'] = $languages;
|
||||
$this->languages = $languages;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,18 +61,18 @@ class text {
|
||||
|
||||
//get the global app_languages.php
|
||||
if (!$exclude_global && file_exists($_SERVER["PROJECT_ROOT"]."/resources/app_languages.php")) {
|
||||
include $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
|
||||
require $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
|
||||
}
|
||||
|
||||
//get the app_languages.php
|
||||
if ($app_path != null) {
|
||||
$lang_path = $_SERVER["PROJECT_ROOT"]."/".$app_path."/app_languages.php";
|
||||
$lang_path = $_SERVER["PROJECT_ROOT"]."/".$app_path;
|
||||
}
|
||||
else {
|
||||
$lang_path = getcwd().'/app_languages.php';
|
||||
$lang_path = getcwd();
|
||||
}
|
||||
if(file_exists($lang_path)) {
|
||||
require $lang_path;
|
||||
require $lang_path."/app_languages.php";
|
||||
}
|
||||
|
||||
//check the session language
|
||||
@@ -103,14 +104,14 @@ 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) {
|
||||
|
||||
|
||||
//clear $text ready for the import
|
||||
$text = array();
|
||||
|
||||
@@ -132,11 +133,37 @@ class text {
|
||||
$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);
|
||||
if(!$no_sort){
|
||||
if($app_path == 'resources') {
|
||||
$temp_A['language-name'] = $text['language-name'];
|
||||
unset($text['language-name']);
|
||||
foreach($this->languages as $language){
|
||||
$temp_B["language-$language"] = $text["language-$language"];
|
||||
unset($text["language-$language"]);
|
||||
}
|
||||
$temp_C["language-en-us"] = $temp_B["language-en-us"];
|
||||
unset($temp_B["language-en-us"]);
|
||||
ksort($temp_B);
|
||||
$temp_B = array_merge($temp_C, $temp_B);
|
||||
ksort($text);
|
||||
$text = array_merge($temp_A, $temp_B, $text);
|
||||
unset($temp_A, $temp_B, $temp_C);
|
||||
}else {
|
||||
ksort($text);
|
||||
}
|
||||
}else{
|
||||
if($app_path == 'resources') {
|
||||
foreach($this->languages as $language){
|
||||
$label = array_shift($text["language-$language"]);
|
||||
if(strlen($label) == 0)
|
||||
$label = $language;
|
||||
$text["language-$language"]['en-us'] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
$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}-\w{2})\z/', $lang_label, $lang_code)) {
|
||||
if($lang_label == 'language-en-us')
|
||||
@@ -150,40 +177,141 @@ class text {
|
||||
$spacer = "";
|
||||
if(strlen($target_lang) == 11)
|
||||
$spacer = " ";
|
||||
fwrite($lang_file, "\$text['language-$target_lang'$spacer]['en-us'] = \"".$this->escape_str(array_shift($text[$lang_label]))."\";\n");
|
||||
$language_name = $this->escape_str(array_shift($text[$lang_label]));
|
||||
if(strlen($language_name) == 0)
|
||||
$language_name = $this->escape_str($target_lang);
|
||||
fwrite($lang_file, "\$text['language-$target_lang'$spacer]['en-us'] = \"$language_name\";\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 ($this->languages as $lang_code) {
|
||||
$value = "";
|
||||
$append = "";
|
||||
$spacer = "";
|
||||
$target_lang = $lang_code;
|
||||
if(strlen($lang_code) == 2) {
|
||||
if(array_key_exists($lang_code, $this->legacy_map)) {
|
||||
$target_lang = $this->legacy_map[$lang_code];
|
||||
foreach ($this->languages as $lang_code) {
|
||||
$value = "";
|
||||
$append = "";
|
||||
$spacer = "";
|
||||
$target_lang = $lang_code;
|
||||
if(strlen($lang_code) == 2) {
|
||||
if(array_key_exists($lang_code, $this->legacy_map)) {
|
||||
$target_lang = $this->legacy_map[$lang_code];
|
||||
}
|
||||
}
|
||||
if(strlen($target_lang) == 2)
|
||||
$spacer = " ";
|
||||
if(array_key_exists($lang_code, $text[$lang_label]))
|
||||
$value = $text[$lang_label][$lang_code];
|
||||
if(strlen($value) == 0 and array_key_exists($target_lang, $this->legacy_map)) {
|
||||
$value = $text[$lang_label][$this->legacy_map[$target_lang]];
|
||||
}
|
||||
fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");
|
||||
}
|
||||
if(strlen($target_lang) == 2)
|
||||
$spacer = " ";
|
||||
if(array_key_exists($lang_code, $text[$lang_label]))
|
||||
$value = $text[$lang_label][$lang_code];
|
||||
if(strlen($value) == 0 and array_key_exists($target_lang, $this->legacy_map)) {
|
||||
$value = $text[$lang_label][$this->legacy_map[$target_lang]];
|
||||
}
|
||||
fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");
|
||||
}
|
||||
}
|
||||
$last_lang_label = $lang_label;
|
||||
}
|
||||
|
||||
//close the language file
|
||||
fwrite($lang_file, "\n?>\n");
|
||||
fwrite($lang_file, "\n?>");
|
||||
fclose($lang_file);
|
||||
}
|
||||
|
||||
public function detect_all_languages($no_sort = false) {
|
||||
|
||||
//clear $text ready for the import
|
||||
$text = array();
|
||||
$languages = array();
|
||||
|
||||
//fetch all the languages
|
||||
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*/app_languages.php");
|
||||
foreach($files as $file) {
|
||||
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) {
|
||||
if(strlen($language_code) == 2) {
|
||||
if(array_key_exists($language_code, $this->legacy_map)) {
|
||||
$language_code = $this->legacy_map[$language_code];
|
||||
}
|
||||
}
|
||||
$languages[$language_code] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//set $this->languages up according to what we found
|
||||
unset($languages['en-us']);
|
||||
$languages = array_keys($languages);
|
||||
asort($languages);
|
||||
array_unshift($languages, 'en-us');
|
||||
|
||||
//support legacy variable
|
||||
$_SESSION['app']['languages'] = $languages;
|
||||
$this->languages = $languages;
|
||||
|
||||
//rewrite resources/app_languges
|
||||
$this->organize_language('resources', $no_sort);
|
||||
}
|
||||
|
||||
public function language_totals() {
|
||||
|
||||
//setup variables
|
||||
$language_totals = array();
|
||||
$language_totals['languages']['total'] = 0;
|
||||
$language_totals['menu_items']['total'] = 0;
|
||||
$language_totals['app_descriptions']['total'] = 0;
|
||||
foreach ($this->languages as $language_code) {
|
||||
$language_totals[$language_code] = 0;
|
||||
}
|
||||
|
||||
//fetch all the languages
|
||||
$text = array();
|
||||
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*/app_languages.php");
|
||||
foreach($files as $file) {
|
||||
include $file;
|
||||
}
|
||||
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
|
||||
|
||||
//check every tag
|
||||
foreach($text as $label_name => $values) {
|
||||
$language_totals['languages']['total']++;
|
||||
foreach ($this->languages as $language_code) {
|
||||
if(strlen($values[$language_code]) > 0)
|
||||
$language_totals['languages'][$language_code]++;
|
||||
}
|
||||
}
|
||||
unset($text);
|
||||
|
||||
//fetch all the menus
|
||||
$x = 0;
|
||||
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*");
|
||||
foreach($files as $file) {
|
||||
if(file_exists($file . "/app_menu.php"))
|
||||
include $file . "/app_menu.php";
|
||||
if(file_exists($file . "/app_config.php"))
|
||||
include $file . "/app_config.php";
|
||||
$x++;
|
||||
}
|
||||
|
||||
//check every tag
|
||||
foreach($apps as $app) {
|
||||
$language_totals['app_descriptions']['total']++;
|
||||
foreach($app['menu'] as $menu_item) {
|
||||
$language_totals['menu_items']['total']++;
|
||||
foreach ($this->languages as $language_code) {
|
||||
if(strlen($menu_item['title'][$language_code]) > 0)
|
||||
$language_totals['menu_items'][$language_code]++;
|
||||
}
|
||||
}
|
||||
foreach ($this->languages as $language_code) {
|
||||
if(strlen($app['description'][$language_code]) > 0)
|
||||
$language_totals['app_descriptions'][$language_code]++;
|
||||
}
|
||||
}
|
||||
|
||||
return $language_totals;
|
||||
}
|
||||
|
||||
private function escape_str($string = '') {
|
||||
//perform initial escape
|
||||
$string = addslashes(stripslashes($string));
|
||||
|
||||
Reference in New Issue
Block a user