mirror of
https://github.com/unraid/webgui.git
synced 2026-01-28 20:49:04 -06:00
Multi-language support
This commit is contained in:
@@ -15,24 +15,30 @@ session_start();
|
||||
session_write_close();
|
||||
|
||||
function _($text) {
|
||||
// PHP translation function _
|
||||
global $language;
|
||||
if (!$text) return '';
|
||||
$data = $language[preg_replace(['/\&|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"\']|<.+?\/?>/','/^(null|yes|no|true|false|on|off|none)$/i','/ +/'],['','$1.',' '],$text)] ?? $text;
|
||||
return strpos($data,'*')===false ? $data : preg_replace(['/\*\*(.+?)\*\*/','/\*(.+?)\*/'],['<b>$1</b>','<i>$1</i>'],$data);
|
||||
}
|
||||
function parse_lang_file($file) {
|
||||
// parser for translation files, includes some trickery to handle PHP quirks.
|
||||
return array_filter(parse_ini_string(preg_replace(['/^(null|yes|no|true|false|on|off|none)=/mi','/^([^>].*)=(.*)$/m','/^:(.+_(help|plug)):$/m','/^:end$/m'],['$1.=','$1="$2"','_$1_="','"'],str_replace(["\"\n",'"'],["\" \n",'\"'],file_get_contents($file)))),'secured',ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
function parse_help_file($file) {
|
||||
// parser for help text files (multi-line sections), includes some trickery to handle PHP quirks.
|
||||
return parse_ini_string(preg_replace(['/^$/m','/^([^:;].+)$/m','/^:(.+_help):$/m','/^:end$/m'],['>','>$1','_$1_="','"'],str_replace(["\"\n",'"'],["\" \n",'\"'],file_get_contents($file))));
|
||||
}
|
||||
function parse_text($text) {
|
||||
// inline text parser
|
||||
return preg_replace_callback('/_\((.+?)\)_/m',function($m){return _($m[1]);},preg_replace(["/^:(.+_help):$/m","/^:(.+_plug):$/m","/^:end$/m"],["<?translate(\"_$1_\");?>","<?if (translate(\"_$1_\")):?>","<?endif;?>"],$text));
|
||||
}
|
||||
function parse_file($file,$markdown=true) {
|
||||
// replacement of PHP include function
|
||||
return $markdown ? Markdown(parse_text(file_get_contents($file))) : parse_text(file_get_contents($file));
|
||||
}
|
||||
function parse_array($text,&$array) {
|
||||
// multi keyword parser
|
||||
parse_str(str_replace([' ',':'],['&','='],$text),$array);
|
||||
}
|
||||
function my_lang($text,$do=0) {
|
||||
@@ -61,9 +67,11 @@ function my_lang($text,$do=0) {
|
||||
return $text;
|
||||
}
|
||||
function secured($v,$k) {
|
||||
// remove potential dangerous tags
|
||||
return strlen($v) && !preg_match('#<(script|iframe)(.*?)>(.+?)</(script|iframe)>|<(link|meta)\s(.+?)/?>#is',html_entity_decode($v));
|
||||
}
|
||||
function translate($key) {
|
||||
// replaces multi-line sections
|
||||
global $language;
|
||||
if ($plug = isset($language[$key])) eval('?>'.Markdown($language[$key]));
|
||||
return !$plug;
|
||||
|
||||
Reference in New Issue
Block a user