Skip to content
Snippets Groups Projects
Commit 6092266f authored by Bob Mottram's avatar Bob Mottram
Browse files

Switching language within the web UI

parent 0c5726a5
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,7 @@ FIREWALL_DOMAINS=/root/${PROJECT_NAME}-firewall-domains.cfg
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin"
language_file="$webadmin_install_dir/.language.txt"
system_monitor_file="$webadmin_install_dir/.system_monitor.txt"
dynamic_dns_file="$webadmin_install_dir/.dynamicdns.txt"
reset_file="$webadmin_install_dir/.reset.txt"
......@@ -1342,6 +1343,47 @@ function update_dynamic_dns {
fi
}
function change_language {
if [ -f "$language_file" ]; then
language=$(cat "$language_file")
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin"
if [ -f "$webadmin_install_dir/language_template.html" ]; then
if grep -q "\"$language\"" "$webadmin_install_dir/language_template.html"; then
cp "$webadmin_install_dir/language_template.html" "$webadmin_install_dir/language.html"
sed -i "s|\"$language\"|\"$language\" selected|g" "$webadmin_install_dir/language.html"
chown www-data:www-data "$webadmin_install_dir/language.html"
config_language=$(grep "DEFAULT_LANGUAGE=" "$CONFIGURATION_FILE" | awk -F '=' '{print $2}')
if [[ "$config_language" != "$language" ]]; then
curr_language=$(web_admin_get_language_subdir)
if [ -d "/usr/share/${PROJECT_NAME}/webadmin/${curr_language}" ]; then
# copy files for the new language
cp -r "/usr/share/${PROJECT_NAME}/webadmin/${curr_language}/*" "/usr/share/${PROJECT_NAME}/webadmin/"
# recreate some screens from templates
regenerate_blocklist
touch "$system_monitor_file"
update_system_monitor
fi
chown -R www-data:www-data "$webadmin_install_dir/*"
sed -i "s|DEFAULT_LANGUAGE=.*|DEFAULT_LANGUAGE=$language|g" "$CONFIGURATION_FILE"
locale-gen "${language}"
update-locale LANG="${language}"
update-locale LANGUAGE="${language}"
update-locale LC_MESSAGES="${language}"
update-locale LC_ALL="${language}"
update-locale LC_CTYPE="${language}"
fi
fi
fi
rm "$language_file"
fi
}
function update_system_monitor {
if [ -f "$system_monitor_file" ]; then
rm "$system_monitor_file"
......@@ -1435,6 +1477,7 @@ do
update_blocklist
update_dynamic_dns
update_system_monitor
change_language
backup_and_restore
backup_and_restore_keys
add_remove_users
......
......@@ -720,6 +720,23 @@ function webadmin_update_system_monitor {
fi
}
function webadmin_change_language {
read_config_param DEFAULT_LANGUAGE
language="$DEFAULT_LANGUAGE"
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin"
if [ -f "$webadmin_install_dir/language_template.html" ]; then
if grep -q "\"$language\"" "$webadmin_install_dir/language_template.html"; then
cp "$webadmin_install_dir/language_template.html" "$webadmin_install_dir/language.html"
sed -i "s|\"$language\"|\"$language\" selected|g" "$webadmin_install_dir/language.html"
chown www-data:www-data "$webadmin_install_dir/language.html"
sed -i "s|DEFAULT_LANGUAGE=.*|DEFAULT_LANGUAGE=$language|g" "$CONFIGURATION_FILE"
fi
fi
}
function install_web_admin {
# This is intended as an admin web user interface
# similar to Plinth or the yunohost
......@@ -881,6 +898,8 @@ function install_web_admin {
mkdir -p "/var/www/${local_hostname}/htdocs/plinth"
fi
webadmin_change_language
web_admin_create_users
# make list of apps which can be added
......
<!DOCTYPE html>
<html>
<head>
<style>
#headerpic {
width: 60%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 220px;
}
.header {
text-align: center;
padding: 32px;
}
.headertext {
color: #72a7cf;
text-align: center;
font-size: 120%;
font-weight: bold;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 600px;
margin: auto;
text-align: center;
font-family: arial;
clear: both;
}
.card input[type=text] {
width: 90%;
clear: both;
text-align: center;
color: black;
background-color: lightblue;
}
.card input[type=password] {
width: 90%;
clear: both;
text-align: center;
color: black;
background-color: lightblue;
}
.appurl {
color: grey;
font-size: 100%;
}
.welcomeheader {
color: black;
font-size: 200%;
font-weight: bold;
}
.descriptiontext {
color: black;
font-size: 90%;
}
.logintext {
color: black;
font-size: 120%;
font-weight: bold;
color: #981737;
}
button {
border: none;
outline: 0;
display: inline-block;
padding: 8px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
a {
text-decoration: none;
color: black;
}
button:hover, a:hover {
opacity: 0.7;
}
.chip {
display: inline-block;
padding: 0 25px;
height: 50px;
font-size: 70%;
line-height: 50px;
border-radius: 25px;
background-color: #f1f1f1;
}
.chip img {
float: left;
margin: 0 10px 0 -25px;
height: 50px;
width: 50px;
border-radius: 50%;
}
.languagelist {
font-size: 100%;
font-weight: bold;
color: black;
background-color: lightblue;
}
</style>
</head>
<body>
<div class="card">
<div class="header">
<a href="settings.html"><img id="headerpic" class="img-responsive" src="images/logo.png"></a><br>
<p class="headertext">Choose your language</p>
<form action="language.php" method="post">
<select class="languagelist" name="language" size="10">
<option value="en_GB.UTF-8">English</option>
<option value="af_ZA.UTF-8">Afrikaans</option>
<option value="sq_AL.UTF-8">Albanian</option>
<option value="ar_SA.UTF-8">Arabic</option>
<option value="eu_ES.UTF-8">Basque</option>
<option value="be_BY.UTF-8">Belarusian</option>
<option value="bs_BA.UTF-8">Bosnian</option>
<option value="bg_BG.UTF-8">Bulgarian</option>
<option value="ca_ES.UTF-8">Catalan</option>
<option value="hr_HR.UTF-8">Croatian</option>
<option value="zh_CN.UTF-8">Chinese (Simplified)</option>
<option value="zh_TW.UTF-8">Chinese (Traditional)</option>
<option value="cs_CZ.UTF-8">Czech</option>
<option value="da_DK.UTF-8">Danish</option>
<option value="nl_NL.UTF-8">Dutch</option>
<option value="en_US.UTF-8">English (US)</option>
<option value="et_EE.UTF-8">Estonian</option>
<option value="fa_IR.UTF-8">Farsi</option>
<option value="ph_PH.UTF-8">Filipino</option>
<option value="fi_FI.UTF-8">Finnish</option>
<option value="fr_FR.UTF-8">French</option>
<option value="fr_CA.UTF-8">French (Canada)</option>
<option value="ga.UTF-8">Gaelic</option>
<option value="l_ES.UTF-8">Gallego</option>
<option value="ka_GE.UTF-8">Georgian</option>
<option value="de_DE.UTF-8">German</option>
<option value="de_DE.UTF-8">German (Personal)</option>
<option value="el_GR.UTF-8">Greek</option>
<option value="gu.UTF-8">Gujarati</option>
<option value="he_IL.utf8">Hebrew</option>
<option value="hi_IN.UTF-8">Hindi</option>
<option value="hu.UTF-8">Hungarian</option>
<option value="is_IS.UTF-8">Icelandic</option>
<option value="id_ID.UTF-8">Indonesian</option>
<option value="it_IT.UTF-8">Italian</option>
<option value="ja_JP.UTF-8">Japanese</option>
<option value="kn_IN.UTF-8">Kannada</option>
<option value="km_KH.UTF-8">Khmer</option>
<option value="ko_KR.UTF-8">Korean</option>
<option value="lo_LA.UTF-8">Lao</option>
<option value="lt_LT.UTF-8">Lithuanian</option>
<option value="lat.UTF-8">Latvian</option>
<option value="ml_IN.UTF-8">Malayalam</option>
<option value="ms_MY.UTF-8">Malaysian</option>
<option value="mi_NZ.UTF-8">Maori (Ngai Tahu)</option>
<option value="mi_NZ.UTF-8">Maori (Waikoto Uni)</option>
<option value="mn.UTF-8">Mongolian</option>
<option value="no_NO.UTF-8">Norwegian</option>
<option value="nn_NO.UTF-8">Norwegian (Primary)</option>
<option value="nn_NO.UTF-8">Nynorsk</option>
<option value="pl.UTF-8">Polish</option>
<option value="pt_PT.UTF-8">Portuguese</option>
<option value="pt_BR.UTF-8">Portuguese (Brazil)</option>
<option value="ro_RO.UTF-8">Romanian</option>
<option value="ru_RU.UTF-8">Russian</option>
<option value="mi_NZ.UTF-8">Samoan</option>
<option value="sr_CS.UTF-8">Serbian</option>
<option value="sk_SK.UTF-8">Slovak</option>
<option value="sl_SI.UTF-8">Slovenian</option>
<option value="so_SO.UTF-8">Somali</option>
<option value="es_ES.UTF-8">Spanish (International)</option>
<option value="sv_SE.UTF-8">Swedish</option>
<option value="tl.UTF-8">Tagalog</option>
<option value="ta_IN.UTF-8">Tamil</option>
<option value="th_TH.UTF-8">Thai</option>
<option value="tr_TR.UTF-8">Turkish</option>
<option value="uk_UA.UTF-8">Ukrainian</option>
<option value="vi_VN.UTF-8">Vietnamese</option>
</select>
<br><br>
<input type="submit" name="submitlanguagecancel" value="Cancel">
<input type="submit" name="submitlanguage" value="Select">
</form>
<br>
</div>
</div>
</body>
</html>
......@@ -51,7 +51,7 @@
.column {
-ms-flex: 25%;
flex: 25%;
flex: 15%;
max-width: 25%;
padding: 0 4px;
}
......@@ -109,6 +109,14 @@
</a>
</div>
</div>
<div class="column">
<div>
<a href="./language.html">
<img src="images/language.png" style="width:100%">
<center>Language</center>
</a>
</div>
</div>
<div class="column">
<div>
<a href="reset.html">
......
......@@ -9,7 +9,7 @@ if (isset($_POST['submitddns'])) {
$ddns_username = htmlspecialchars($_POST['ddns_username']);
$ddns_password = htmlspecialchars($_POST['ddns_password']);
$ddns_file = fopen(".dynamicdns.txt", "w") or die("Unable to create setup file");
$ddns_file = fopen(".dynamicdns.txt", "w") or die("Unable to create dynamicdns file");
fwrite($ddns_file, $ddns.','.$ddns_username.','.$ddns_password);
fclose($ddns_file);
}
......
webadmin/images/language.png

28.7 KiB

<?php
// Change language
$output_filename = "settings.html";
if (isset($_POST['submitlanguage'])) {
$language = htmlspecialchars($_POST['language']);
$language_file = fopen(".language.txt", "w") or die("Unable to create language file");
fwrite($language_file, $language);
fclose($language_file);
}
$htmlfile = fopen("$output_filename", "r") or die("Unable to open $output_filename");
echo fread($htmlfile,filesize("$output_filename"));
fclose($htmlfile);
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment