Files
webgui/plugins/dynamix/Language.page
2020-04-29 20:56:15 +02:00

131 lines
4.8 KiB
Plaintext

Menu="WebGui"
Title="Language"
Icon="icon-language"
Tag="icon-language"
---
<?PHP
/* Copyright 2005-2020, Lime Technology
* Copyright 2012-2020, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$installed = ['English'];
$keys = parse_ini_file('webGui/include/languages.key',false,INI_SCANNER_RAW);
foreach (glob("$docroot/languages/*",GLOB_ONLYDIR) as $dir) $installed[] = rtrim(strtok($keys[basename($dir)],'('));
?>
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.switchbutton.css')?>">
<style>
select.wide{min-width:<?=$themes2?'314':'300'?>px}
div.notice{margin-top:70px;margin-bottom:30px}
</style>
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
<script>
var keys = {};
<?foreach ($keys as $key => $name) echo "keys['$key'] = '".rtrim(strtok($keys[$key],'('))."'\n";?>
function upload(form) {
var language = form.language.value;
if (!language) {
swal({title:'_(Missing Language)_',text:'_(Please select a language before proceeding)_!',type:'error',confirmButtonText:'_(Ok)_'});
return;
}
var cmd = form.check.checked ? 'rm' :'add';
var title = form.check.checked ? '_(Language support deleted)_' : '_(Language support added)_';
$.post("/webGui/include/FileUpload.php",{cmd:cmd,filename:language,filedata:form.file.value},function(list){
if (list.indexOf('Error 500')==-1) {
var installed = ['English'];
var name = list.split(',');
for (var i=0; i < name.length; i++) installed.push(keys[name[i]]);
$('#installed').text(installed.join(', '));
swal({title:title,text:'_(See)_ <a href="/Settings/DisplaySettings">_(Display Settings)_</a> _(to select your language)_',type:'success',html:true,confirmButtonText:'_(Ok)_'});
$('#uploadbutton').prop('disabled',true);
}
});
}
function getZIPfile(event,form) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var name = input.files[0].name;
if (name.slice(-4)=='.zip') {
form.file.value = reader.result;
$('#uploadbutton').prop('disabled',false);
for (var n = 0; n < form.language.length; n++) if (form.language.options[n].text.indexOf(name.slice(0,-4))>0) {form.language.selectedIndex = n; break;}
} else {
swal({title:'_(Wrong File Extension)_',text:'_(Only ZIP files are allowed)_',type:'error',confirmButtonText:'_(Ok)_'});
}
};
reader.readAsDataURL(input.files[0]);
}
function screenUpdate(check) {
$('#uploadbutton').prop('disabled',false);
$('#selectlang').toggle('slow');
if (check) $('#uploadbutton').val("_(Delete)_"); else $('#uploadbutton').val("_(Upload)_")
}
function installXML(name) {
var file = name.trim();
if (file) openBox('/plugins/dynamix.plugin.manager/scripts/language&arg1=install&arg2='+file,'_(Install Language)_',600,900);
}
$(function() {
$('.advancedview').switchButton({
labels_placement: 'left',
on_label: '_(Developer)_',
off_label: '_(User)_',
});
$('.advancedview').change(function(){
$('.advanced').toggle('slow');
$('.basic').toggle('slow');
});
});
</script>
<span class="status vhshift"><input type="checkbox" class="advancedview"></span>
<div markdown="1" class="basic">
<div class="notice">_(Use this to install official language packs)_</div>
_(Installed languages)_:
: <?=implode(', ',$installed)?>
_(Enter URL of language pack XML file)_
: &nbsp;
<dl>
<form name="xml_install" method="POST" target="progressFrame">
<dt><input type="text" name="file" id="xml_file" maxlength="1024" value="" style="width:90%"></dt>
<dd><input type="button" value="_(Install)_" onclick="installXML(this.form.file.value)" style="margin:0"></dd>
</form>
</dl>
</div>
<div markdown="1" class="advanced" style="display:none">
<div class="notice">_(Use this to develop language packs)_</div>
<form markdown="1">
<input type="hidden" name="file" value="">
_(Installed languages)_:
: <span id="installed"><?=implode(', ',$installed)?></span>
_(Select language)_:
: <select name="language" class="wide">
<?=mk_option(1, "", "---")?>
<?foreach ($keys as $key => $name) echo mk_option(1, $key, $name)?>
</select><input name="check" type="checkbox" onchange="screenUpdate(this.checked)">_(Remove the installed language)_
<div id="selectlang" markdown="1">
_(Select language file)_:
: <input type="file" accept=".zip" onchange="getZIPfile(event,this.form)">
</div>
&nbsp;
: <input id="uploadbutton" type="button" value="_(Upload)_" onclick="upload(this.form)" disabled><input type="button" value="_(Done)_" class="lock" onclick="done()">
</form>
</div>