Merge pull request #677 from bergware/mutli-language

Multi-language support
This commit is contained in:
tom mortensen
2020-05-10 20:18:02 -07:00
committed by GitHub
4 changed files with 2088 additions and 34 deletions

View File

@@ -324,7 +324,7 @@ function formatWarning(val) {
[$date,$duration,$speed,$status,$error] = last_parity_log();?>
<? if ($status==0):?>
<td class="wrap"><?=sprintf(_('Last checked on **%s**'),my_lang(my_time($date).my_lang(day_count($date),1)))?><br><?=sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0')?>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=my_lang(my_check($duration,$speed),2)?></td></tr>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=_(my_lang(my_check($duration,$speed),2))?></td></tr>
<? else:?>
<td class="wrap"><?=sprintf(_('Last check incomplete on **%s**'),my_lang(my_time($date).my_lang(day_count($date),1)))?><br><?=sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0')?>
<i class="fa fa-fw fa-dot-circle-o"></i>_(Error code)_: <?=my_error($status)?></td></tr>
@@ -333,7 +333,7 @@ function formatWarning(val) {
[$date,$duration,$speed,$status,$error] = explode('|', read_parity_log($var['sbSynced']));
if ($status==0):?>
<td class="wrap"><?=sprintf(_('Last checked on **%s**'),my_lang(my_time($var['sbSynced']).my_lang(day_count($var['sbSynced']),1)))?><br><?=sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0')?>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=my_lang(my_check($duration,$speed),2)?></td></tr>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=_(my_lang(my_check($duration,$speed),2))?></td></tr>
<? else:?>
<td class="wrap"><?=sprintf(_('Last check incomplete on **%s**'),my_lang(my_time($var['sbSynced']).my_lang(day_count($var['sbSynced']),1)))?><br><?=sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0')?>
<i class="fa fa-fw fa-dot-circle-o"></i>_(Error code)_: <?=my_error($status)?></td></tr>
@@ -342,7 +342,7 @@ function formatWarning(val) {
$duration = $var['sbSynced2']-$var['sbSynced'];
$speed = $duration?my_scale($var['mdResyncSize']*1024/$duration,$unit,1)." $unit/sec":'';?>
<td class="wrap"><?=sprintf(_('Last check completed on **%s**'),my_lang(my_time($var['sbSynced2']).my_lang(day_count($var['sbSynced2']),1)))?><br><?=sprintf(_('Finding **%s** error'.($var['sbSyncErrs']==1?'':'s')),$var['sbSyncErrs']?:'0')?>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=my_lang(my_check($duration,$speed),2)?></td></tr>
<i class="fa fa-fw fa-clock-o"></i>_(Duration)_: <?=_(my_lang(my_check($duration,$speed),2))?></td></tr>
<? endif;
endif;
else:

File diff suppressed because it is too large Load Diff

View File

@@ -406,7 +406,7 @@ case 'parity':
echo _('Parity has not been checked yet');
} elseif ($status==0) {
echo sprintf(_('Last checked on **%s**'),my_lang(my_time($date).my_lang(day_count($date),1))).'<br> '.sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0');
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').": ".my_lang(my_check($duration,$speed),2);
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').": "._(my_lang(my_check($duration,$speed),2));
} else {
echo sprintf(_('Last check incomplete on **%s**'),my_lang(my_time($date).my_lang(day_count($date),1))).'<br>'.sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0');
echo " <i class='fa fa-fw fa-dot-circle-o'></i> "._('Error code').": ".my_error($status);
@@ -416,7 +416,7 @@ case 'parity':
list($entry,$duration,$speed,$status,$error) = explode('|', read_parity_log($var['sbSynced'],!$idle));
if ($status==0) {
echo sprintf(_('Last checked on **%s**'),my_lang(my_time($var['sbSynced']).my_lang(day_count($var['sbSynced']),1))).'<br>'.sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0');
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').": ".my_lang(my_check($duration,$speed),2);
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').": "._(my_lang(my_check($duration,$speed),2));
} else {
echo sprintf(_('Last check incomplete on **%s**'),my_lang(my_time($var['sbSynced']).my_lang(day_count($var['sbSynced']),1))).'<br>'.sprintf(_('Finding **%s** error'.($error==1?'':'s')),$error?:'0');
echo " <i class='fa fa-fw fa-dot-circle-o'></i> "._('Error code').": ".my_error($status);
@@ -431,7 +431,7 @@ case 'parity':
$duration = $var['sbSynced2']-$var['sbSynced'];
$speed = $duration?my_scale($var['mdResyncSize']*1024/$duration,$unit,1)." $unit/sec":'';
echo sprintf(_('Last check completed on **%s**'),my_lang(my_time($var['sbSynced2']).my_lang(day_count($var['sbSynced2']),1))).'<br>'.sprintf(_('Finding **%s** error'.($var['sbSyncErrs']==1?'':'s')),$var['sbSyncErrs']?:'0');
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').': '.my_lang(my_check($duration,$speed),2);
echo " <i class='fa fa-fw fa-clock-o'></i> "._('Duration').': '._(my_lang(my_check($duration,$speed),2));
}
if ($idle) {
list($m,$h) = explode(' ', $parity['hour']);

View File

@@ -66,36 +66,38 @@ function translate($key) {
return !$plug;
}
$language = [];
$locale = $_SESSION['locale'] ?: 'en_US';
$locale = $_SESSION['locale'];
$return = "function _(t){return t;}";
$text = "$docroot/languages/$locale/translations.txt";
$help = "$docroot/languages/$locale/helptext.txt";
$jscript = "$docroot/webGui/javascript/translate.en_US.js";
$root = "$docroot/webGui/help/helptext.txt";
$help = "$docroot/webGui/help/helptext.dot";
if (file_exists($text)) {
$store = "$docroot/languages/$locale/translations.dot";
// global translations
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
$language = unserialize(file_get_contents($store));
}
if (file_exists($help)) {
// global help text
$store = "$docroot/languages/$locale/helptext.dot";
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($help)));
$language = array_merge($language,unserialize(file_get_contents($store)));
}
$jscript = "$docroot/webGui/javascript/translate.$locale.js";
if (!file_exists($jscript)) {
// create javascript file with translations
$source = [];
$files = glob("$docroot/languages/$locale/javascript*.txt",GLOB_NOSORT);
foreach ($files as $js) $source = array_merge($source,parse_lang_file($js));
if (count($source)) {
$script = ['function _(t){var l={};'];
foreach ($source as $key => $value) $script[] = "l[\"$key\"]=\"$value\";";
$script[] ="return l[t.replace(/\&amp;|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"']|<.+?\/?>/g,'').replace(/ +/g,' ')]||t;}";
file_put_contents($jscript,implode('',$script));
} else {
file_put_contents($jscript,$return);
if ($locale) {
$text = "$docroot/languages/$locale/translations.txt";
if (file_exists($text)) {
$store = "$docroot/languages/$locale/translations.dot";
// global translations
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
$language = unserialize(file_get_contents($store));
}
if (file_exists("$docroot/languages/$locale/helptext.txt")) {
$root = "$docroot/languages/$locale/helptext.txt";
$help = "$docroot/languages/$locale/helptext.dot";
}
$jscript = "$docroot/webGui/javascript/translate.$locale.js";
if (!file_exists($jscript)) {
// create javascript file with translations
$source = [];
$files = glob("$docroot/languages/$locale/javascript*.txt",GLOB_NOSORT);
foreach ($files as $js) $source = array_merge($source,parse_lang_file($js));
if (count($source)) {
$script = ['function _(t){var l={};'];
foreach ($source as $key => $value) $script[] = "l[\"$key\"]=\"$value\";";
$script[] ="return l[t.replace(/\&amp;|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"']|<.+?\/?>/g,'').replace(/ +/g,' ')]||t;}";
file_put_contents($jscript,implode('',$script));
} else {
file_put_contents($jscript,$return);
}
}
}
// split URI into translation levels
@@ -110,4 +112,10 @@ foreach($uri as $more) {
$language = array_merge($language,unserialize(file_get_contents($other)));
}
}
// help text
if (!file_exists($help)) file_put_contents($help,serialize(parse_lang_file($root)));
$language = array_merge($language,unserialize(file_get_contents($help)));
// remove unused variables
unset($return,$jscript,$root,$help,$store,$uri,$more,$text,$other);
?>