mirror of
https://github.com/unraid/webgui.git
synced 2026-03-02 06:10:55 -06:00
Multi-language support
This commit is contained in:
@@ -3,49 +3,49 @@ var eventURL = '/plugins/dynamix.docker.manager/include/Events.php';
|
||||
function addDockerContainerContext(container, image, template, started, paused, update, autostart, webui, shell, id, Support, Project, Registry) {
|
||||
var opts = [];
|
||||
if (started && !paused) {
|
||||
if (webui !== '' && webui != '#') opts.push({text:'WebUI', icon:'fa-globe', href:webui, target:'_blank'});
|
||||
opts.push({text:'Console', icon:'fa-terminal', action:function(e){e.preventDefault(); dockerTerminal(container,shell);}});
|
||||
if (webui !== '' && webui != '#') opts.push({text:_('WebUI'), icon:'fa-globe', href:webui, target:'_blank'});
|
||||
opts.push({text:_('Console'), icon:'fa-terminal', action:function(e){e.preventDefault(); dockerTerminal(container,shell);}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (update==1) {
|
||||
opts.push({text:'Update', icon:'fa-cloud-download', action:function(e){e.preventDefault(); execUpContainer(container);}});
|
||||
opts.push({text:_('Update'), icon:'fa-cloud-download', action:function(e){e.preventDefault(); execUpContainer(container);}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (started) {
|
||||
if (paused) {
|
||||
opts.push({text:'Resume', icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'resume', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Resume'), icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'resume', container:id}, 'loadlist');}});
|
||||
} else {
|
||||
opts.push({text:'Stop', icon:'fa-stop', action:function(e){e.preventDefault(); eventControl({action:'stop', container:id}, 'loadlist');}});
|
||||
opts.push({text:'Pause', icon:'fa-pause', action:function(e){e.preventDefault(); eventControl({action:'pause', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Stop'), icon:'fa-stop', action:function(e){e.preventDefault(); eventControl({action:'stop', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Pause'), icon:'fa-pause', action:function(e){e.preventDefault(); eventControl({action:'pause', container:id}, 'loadlist');}});
|
||||
}
|
||||
opts.push({text:'Restart', icon:'fa-refresh', action:function(e){e.preventDefault(); eventControl({action:'restart', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Restart'), icon:'fa-refresh', action:function(e){e.preventDefault(); eventControl({action:'restart', container:id}, 'loadlist');}});
|
||||
} else {
|
||||
opts.push({text:'Start', icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'start', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Start'), icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'start', container:id}, 'loadlist');}});
|
||||
}
|
||||
opts.push({divider:true});
|
||||
if (location.pathname.indexOf('/Dashboard') === 0) {
|
||||
opts.push({text:'Logs', icon:'fa-navicon', action:function(e){e.preventDefault(); containerLogs(container, id);}});
|
||||
opts.push({text:_('Logs'), icon:'fa-navicon', action:function(e){e.preventDefault(); containerLogs(container, id);}});
|
||||
}
|
||||
if (template) {
|
||||
opts.push({text:'Edit', icon:'fa-wrench', action:function(e){e.preventDefault(); editContainer(container, template);}});
|
||||
opts.push({text:_('Edit'), icon:'fa-wrench', action:function(e){e.preventDefault(); editContainer(container, template);}});
|
||||
}
|
||||
opts.push({divider:true});
|
||||
opts.push({text:'Remove', icon:'fa-trash', action:function(e){e.preventDefault(); rmContainer(container, image, id);}});
|
||||
opts.push({text:_('Remove'), icon:'fa-trash', action:function(e){e.preventDefault(); rmContainer(container, image, id);}});
|
||||
if (Support) {
|
||||
opts.push({divider:true});
|
||||
opts.push({text:'Support', icon:'fa-question', href:Support, target:'_blank'});
|
||||
opts.push({text:_('Support'), icon:'fa-question', href:Support, target:'_blank'});
|
||||
}
|
||||
if (Project) {
|
||||
opts.push({text:'Project Page', icon:'fa-life-ring', href:Project, target:'_blank'});
|
||||
opts.push({text:_('Project Page'), icon:'fa-life-ring', href:Project, target:'_blank'});
|
||||
}
|
||||
if (Registry) {
|
||||
opts.push({text:'More Info',icon:'fa-info-circle', href:Registry, target:'_blank'});
|
||||
opts.push({text:_('More Info'),icon:'fa-info-circle', href:Registry, target:'_blank'});
|
||||
}
|
||||
context.attach('#'+id, opts);
|
||||
}
|
||||
function addDockerImageContext(image, imageTag) {
|
||||
var opts = [];
|
||||
opts.push({text:'Remove', icon:'fa-trash', action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
|
||||
opts.push({text:_('Remove'), icon:'fa-trash', action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
|
||||
context.attach('#'+image, opts);
|
||||
}
|
||||
function dockerTerminal(container,shell) {
|
||||
@@ -102,9 +102,9 @@ function editContainer(container, template) {
|
||||
location = path+'/UpdateContainer?xmlTemplate=edit:'+template;
|
||||
}
|
||||
function updateContainer(container) {
|
||||
var body = 'Update container: '+container;
|
||||
var body = _('Update container')+': '+container;
|
||||
swal({
|
||||
title:'Are you sure?',
|
||||
title:_('Are you sure?'),
|
||||
text:body,
|
||||
type:'warning',
|
||||
showCancelButton:true,
|
||||
@@ -114,10 +114,10 @@ function updateContainer(container) {
|
||||
});
|
||||
}
|
||||
function rmContainer(container, image, id) {
|
||||
var body = 'Remove container: '+container+'<br><br><label><input id="removeimagechk" type="checkbox" checked style="display:inline;width:unset;height:unset;margin-top:unset;margin-bottom:unset">also remove image</label>';
|
||||
var body = _('Remove container')+': '+container+'<br><br><label><input id="removeimagechk" type="checkbox" checked style="display:inline;width:unset;height:unset;margin-top:unset;margin-bottom:unset">also remove image</label>';
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
swal({
|
||||
title:'Are you sure?',
|
||||
title:_('Are you sure?'),
|
||||
text:body,
|
||||
type:'warning',
|
||||
html:true,
|
||||
@@ -135,10 +135,10 @@ function rmContainer(container, image, id) {
|
||||
});
|
||||
}
|
||||
function rmImage(image, imageName) {
|
||||
var body = 'Remove image: '+$('<textarea />').html(imageName).text();
|
||||
var body = _('Remove image')+': '+$('<textarea />').html(imageName).text();
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
swal({
|
||||
title:'Are you sure?',
|
||||
title:_('Are you sure?'),
|
||||
text:body,
|
||||
type:'warning',
|
||||
showCancelButton:true,
|
||||
@@ -157,7 +157,7 @@ function eventControl(params, spin) {
|
||||
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
|
||||
} else {
|
||||
swal({
|
||||
title:'Execution error', html:true,
|
||||
title:_('Execution error'), html:true,
|
||||
text:data.success, type:'error'
|
||||
},function(){
|
||||
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
|
||||
@@ -195,7 +195,7 @@ function updateAll() {
|
||||
var ct = '';
|
||||
for (var i=0,d; d=docker[i]; i++) if (d.update==1) ct += '&ct[]='+encodeURI(d.name);
|
||||
var cmd = '/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true'+ct;
|
||||
popupWithIframe('Updating all Containers', cmd, true, 'loadlist');
|
||||
popupWithIframe(_('Updating all Containers'), cmd, true, 'loadlist');
|
||||
}
|
||||
function rebuildAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
|
||||
@@ -3,7 +3,7 @@ function ajaxVMDispatch(params, spin){
|
||||
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", params, function(data) {
|
||||
if (data.error) {
|
||||
swal({
|
||||
title:"Execution error", html:true,
|
||||
title:_("Execution error"), html:true,
|
||||
text:data.error, type:"error"
|
||||
},function(){
|
||||
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
|
||||
@@ -19,69 +19,69 @@ function addVMContext(name, uuid, template, state, vncurl, log){
|
||||
var x = path.indexOf("?");
|
||||
if (x!=-1) path = path.substring(0,x);
|
||||
if (vncurl !== "") {
|
||||
opts.push({text:"VNC Remote", icon:"fa-desktop", action:function(e) {
|
||||
opts.push({text:_("VNC Remote"), icon:"fa-desktop", action:function(e) {
|
||||
e.preventDefault();
|
||||
window.open(vncurl, '_blank', 'scrollbars=yes,resizable=yes');
|
||||
}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (state == "running") {
|
||||
opts.push({text:"Stop", icon:"fa-stop", action:function(e) {
|
||||
opts.push({text:_("Stop"), icon:"fa-stop", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-stop", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Pause", icon:"fa-pause", action:function(e) {
|
||||
opts.push({text:_("Pause"), icon:"fa-pause", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-pause", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Restart", icon:"fa-refresh", action:function(e) {
|
||||
opts.push({text:_("Restart"), icon:"fa-refresh", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-restart", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Hibernate", icon:"fa-bed", action:function(e) {
|
||||
opts.push({text:_("Hibernate"), icon:"fa-bed", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-pmsuspend", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Force Stop", icon:"fa-bomb", action:function(e) {
|
||||
opts.push({text:_("Force Stop"), icon:"fa-bomb", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch( {action:"domain-destroy", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
} else if (state == "pmsuspended") {
|
||||
opts.push({text:"Resume", icon:"fa-play", action:function(e) {
|
||||
opts.push({text:_("Resume"), icon:"fa-play", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-pmwakeup", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Force Stop", icon:"fa-bomb", action:function(e) {
|
||||
opts.push({text:_("Force Stop"), icon:"fa-bomb", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-destroy", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
} else if (state == "paused" || state == "unknown") {
|
||||
opts.push({text:"Resume", icon:"fa-play", action:function(e) {
|
||||
opts.push({text:_("Resume"), icon:"fa-play", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-resume", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
opts.push({text:"Force Stop", icon:"fa-bomb", action:function(e) {
|
||||
opts.push({text:_("Force Stop"), icon:"fa-bomb", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-destroy", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
} else {
|
||||
opts.push({text:"Start", icon:"fa-play", action:function(e) {
|
||||
opts.push({text:_("Start"), icon:"fa-play", action:function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch({action:"domain-start", uuid:uuid}, "loadlist");
|
||||
}});
|
||||
}
|
||||
opts.push({divider:true});
|
||||
if (log !== "") {
|
||||
opts.push({text:"Logs", icon:"fa-navicon", action:function(e){e.preventDefault(); openWindow('/webGui/scripts/tail_log&arg1='+log, 'Log for:'+name, 600, 900);}});
|
||||
opts.push({text:_("Logs"), icon:"fa-navicon", action:function(e){e.preventDefault(); openWindow('/webGui/scripts/tail_log&arg1='+log, 'Log for:'+name, 600, 900);}});
|
||||
}
|
||||
opts.push({text:"Edit", icon:"fa-pencil", href:path+'/UpdateVM?uuid='+uuid});
|
||||
opts.push({text:_("Edit"), icon:"fa-pencil", href:path+'/UpdateVM?uuid='+uuid});
|
||||
if (state == "shutoff") {
|
||||
opts.push({divider:true});
|
||||
opts.push({text:"Remove VM", icon:"fa-minus", action:function(e) {
|
||||
opts.push({text:_("Remove VM"), icon:"fa-minus", action:function(e) {
|
||||
e.preventDefault();
|
||||
swal({
|
||||
title:"Are you sure?",
|
||||
text:"Remove definition:"+name,
|
||||
title:_("Are you sure?"),
|
||||
text:_("Remove definition:")+name,
|
||||
type:"warning",
|
||||
showCancelButton:true
|
||||
},function(){
|
||||
@@ -90,11 +90,11 @@ function addVMContext(name, uuid, template, state, vncurl, log){
|
||||
});
|
||||
}});
|
||||
if (template != 'OpenELEC') {
|
||||
opts.push({text:"Remove VM & Disks", icon:"fa-trash", action:function(e) {
|
||||
opts.push({text:_("Remove VM")+" & "+_("Disks"), icon:"fa-trash", action:function(e) {
|
||||
e.preventDefault();
|
||||
swal({
|
||||
title:"Are you sure?",
|
||||
text:"Completely REMOVE "+name+" disk image and definition",
|
||||
title:_("Are you sure?"),
|
||||
text:_("Completely REMOVE")+" "+name+" "+_("disk image and definition"),
|
||||
type:"warning",
|
||||
showCancelButton:true
|
||||
},function(){
|
||||
|
||||
@@ -78,6 +78,7 @@ $notes = " <a href='#' title='"._('View Release Notes')."' onclick=\"openBo
|
||||
</style>
|
||||
|
||||
<script src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
|
||||
<script src="<?autov('/webGui/javascript/translations.js')?>"></script>
|
||||
<script>
|
||||
Shadowbox.init({skipSetup:true});
|
||||
|
||||
|
||||
@@ -59,7 +59,11 @@ case 'add':
|
||||
if ($result) exit(implode(',',$installed));
|
||||
case 'rm':
|
||||
$path = "$docroot/languages/$file";
|
||||
if ($result = is_dir($path)) {exec("rm -rf ".escapeshellarg($path)); @unlink("$boot/$file.lang.zip");}
|
||||
if ($result = is_dir($path)) {
|
||||
exec("rm -rf ".escapeshellarg($path));
|
||||
@unlink("$docroot/webGui/javascript/translations.js");
|
||||
@unlink("$boot/$file.lang.zip");
|
||||
}
|
||||
$installed = [];
|
||||
foreach (glob("$docroot/languages/*",GLOB_ONLYDIR) as $dir) $installed[] = basename($dir);
|
||||
if ($result) exit(implode(',',$installed));
|
||||
|
||||
@@ -79,21 +79,33 @@ $language = [];
|
||||
$locale = $_SESSION['locale'];
|
||||
|
||||
if ($locale) {
|
||||
$uri = explode('/',explode('?',$_SERVER['REQUEST_URI'])[0]);
|
||||
// split URI into translation levels
|
||||
$uri = array_filter(explode('/',strtok($_SERVER['REQUEST_URI'],'?')));
|
||||
$text = "$docroot/languages/$locale/translations.txt";
|
||||
if (file_exists($text)) {
|
||||
$data = "$docroot/languages/$locale/translations.dot";
|
||||
if (!file_exists($data)) file_put_contents($data,serialize(parse_lang_file($text)));
|
||||
$language = unserialize(file_get_contents($data));
|
||||
$basis = "$docroot/languages/$locale/translations.dot";
|
||||
$jsTxt = "$docroot/languages/$locale/javascript.txt";
|
||||
$jsOut = "$docroot/webGui/javascript/translations.js";
|
||||
// global translations
|
||||
if (!file_exists($basis)) file_put_contents($basis,serialize(parse_lang_file($text)));
|
||||
$language = unserialize(file_get_contents($basis));
|
||||
if (!file_exists($jsOut)) {
|
||||
// create javascript file with translations
|
||||
$source = file_exists($jsTxt) ? parse_lang_file($jsTxt) : [];
|
||||
$script = ['function _(t){var l={};'];
|
||||
foreach ($source as $key => $value) $script[] = "l[\"$key\"]=\"$value\";";
|
||||
$script[] ="return l[t.replace(/\&|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"']|<.+?\/?>/g,'').replace(/ +/g,' ')]||t;}";
|
||||
file_put_contents($jsOut,implode('',$script));
|
||||
}
|
||||
}
|
||||
foreach($uri as $add) {
|
||||
if (!$add) continue;
|
||||
$add = strtolower($add);
|
||||
$text = "$docroot/languages/$locale/$add.txt";
|
||||
foreach($uri as $more) {
|
||||
$more = strtolower($more);
|
||||
$text = "$docroot/languages/$locale/$more.txt";
|
||||
if (file_exists($text)) {
|
||||
$data = "$docroot/languages/$locale/$add.dot";
|
||||
if (!file_exists($data)) file_put_contents($data,serialize(parse_lang_file($text)));
|
||||
$language = array_merge($language,unserialize(file_get_contents($data)));
|
||||
// additional translations
|
||||
$other = "$docroot/languages/$locale/$more.dot";
|
||||
if (!file_exists($other)) file_put_contents($other,serialize(parse_lang_file($text)));
|
||||
$language = array_merge($language,unserialize(file_get_contents($other)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user