Skip to content

Commit

Permalink
ncp-web: put configuration in a separate file from available languages
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Sep 25, 2018
1 parent cdbb750 commit 6152e7e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ armbian/
raspbian_root
raspbian_boot
ncp-web/wizard.cfg
ncp-web/ncp-web.cfg
docker-armhf/qemu-arm-static
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

[v0.60.7](https://github.com/nextcloud/nextcloudpi/commit/bd464b2) (2018-09-24) docker: disable auto-upgrade until it is adapted to containers
[v0.60.8](https://github.com/nextcloud/nextcloudpi/commit/57999b6) (2018-09-24) ncp-web: put configuration in a separate file from available languages

[v0.60.6](https://github.com/nextcloud/nextcloudpi/commit/1150ed8) (2018-09-24) nc-format-USB: fix
[v0.60.7](https://github.com/nextcloud/nextcloudpi/commit/cdbb750) (2018-09-24) docker: disable auto-upgrade until it is adapted to containers

[v0.60.6 ](https://github.com/nextcloud/nextcloudpi/commit/1150ed8) (2018-09-24) nc-format-USB: fix

[v0.60.5 ](https://github.com/nextcloud/nextcloudpi/commit/3de5fe0) (2018-09-23) armbian: fix locales for ncp-config

Expand Down
36 changes: 9 additions & 27 deletions ncp-web/L10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ function save($lang)
{
$cfg = 'ncp-web.cfg';
$line = file_get_contents( $cfg );
$str = '';
if (preg_match('/^LANGUAGE_=\[(([_\w]+,)*[_\w]+)\]$/', $line, $matches)) {
$options = explode(',', $matches[1]);
foreach ($options as $option) {
$opt = trim( $option, "_" );
$str .= $opt == $lang ? '_' . $opt . '_,' : $opt . ',';
}
}
$str = 'LANGUAGE_=[' . rtrim( $str, ',' ) . ']';
$str = "LANGUAGE_=$lang";
return file_put_contents( $cfg , $str );
}

Expand Down Expand Up @@ -147,25 +139,15 @@ function find_language(array $available_languages, $desired_language)
return array_keys($langs)[0];
}

function load_language_setting($modules_path)
function load_language_setting()
{
$webui_config_file = 'ncp-web.cfg';
$fh = fopen($webui_config_file, 'r')
or exit('{ "output": "' . $webui_config_file . ' read error" }');
$lang = "auto";
while ($line = fgets($fh)) {
// drop down menu
if (preg_match('/^LANGUAGE_=\[(([_\w]+,)*[_\w]+)\]$/', $line, $matches)) {
$options = explode(',', $matches[1]);
foreach ($options as $option) {
if ($option[0] == "_" && $option[count($option) - 1] == "_") {
fclose($fh);
$lang = trim($option, '_');
}
}
fclose($fh);
return $lang;
}
}
$fh = fopen($webui_config_file, 'r');
if ($fh === false)
return "auto";

$lang=file_get_contents($webui_config_file);
fclose($fh);
return ltrim($lang, 'LANGUAGE_=');
}
}
26 changes: 13 additions & 13 deletions ncp-web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@
</a>
<?php
// language selection drop
if( preg_match('/^(\w+)_=\[(([_\w]+,)*[_\w]+)\]$/', file_get_contents( 'ncp-web.cfg') , $matches) )
{
$options = explode(",", $matches[2]);
echo "<select id=\"language-selection\" name=\"$matches[1]\">";
foreach($options as $option)
{
echo "<option value='". trim($option, "_") ."' ";
if( $option[0] == "_" && $option[count($option) - 1] == "_" )
echo "selected='selected'";
echo ">". trim($option, "_") ."</option>";
}
echo "<option value=\"[new]\">new..</option>";
echo "</select>";
$selected_lang=$l->load_language_setting();

$fh = fopen('langs.cfg', 'r');
echo "<select id=\"language-selection\" name=\"language-selection\">";
while ($line = fgets($fh)) {
echo "<option value='" . $line . "' ";
error_log("NACHO $line - $selected_lang");
if( $line == $selected_lang )
echo "selected='selected'";
echo ">". $line ."</option>";
}
echo "<option value=\"[new]\">new..</option>";
echo "</select>";
fclose($fh);
?>
</div>
<div id="header-right">
Expand Down
5 changes: 5 additions & 0 deletions ncp-web/langs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
auto
en
de
es
zh
1 change: 0 additions & 1 deletion ncp-web/ncp-web.cfg

This file was deleted.

0 comments on commit 6152e7e

Please sign in to comment.