From 6152e7e2addede53d8d521ebea918563ab3a4e23 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Mon, 24 Sep 2018 18:35:43 -0600 Subject: ncp-web: put configuration in a separate file from available languages --- ncp-web/L10N.php | 36 +++++++++--------------------------- ncp-web/index.php | 26 +++++++++++++------------- ncp-web/langs.cfg | 5 +++++ ncp-web/ncp-web.cfg | 1 - 4 files changed, 27 insertions(+), 41 deletions(-) create mode 100644 ncp-web/langs.cfg delete mode 100644 ncp-web/ncp-web.cfg (limited to 'ncp-web') diff --git a/ncp-web/L10N.php b/ncp-web/L10N.php index 71a2ab18..2fdf5434 100644 --- a/ncp-web/L10N.php +++ b/ncp-web/L10N.php @@ -70,15 +70,7 @@ class L10N { $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 ); } @@ -147,25 +139,15 @@ class L10N 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_='); } } diff --git a/ncp-web/index.php b/ncp-web/index.php index 9c8ca46c..a55bd69f 100644 --- a/ncp-web/index.php +++ b/ncp-web/index.php @@ -114,20 +114,20 @@ HTML; "; - foreach($options as $option) - { - echo ""; - } - echo ""; - echo ""; + $selected_lang=$l->load_language_setting(); + + $fh = fopen('langs.cfg', 'r'); + echo ""; + fclose($fh); ?>
diff --git a/ncp-web/langs.cfg b/ncp-web/langs.cfg new file mode 100644 index 00000000..d43309ff --- /dev/null +++ b/ncp-web/langs.cfg @@ -0,0 +1,5 @@ +auto +en +de +es +zh diff --git a/ncp-web/ncp-web.cfg b/ncp-web/ncp-web.cfg deleted file mode 100644 index 57888595..00000000 --- a/ncp-web/ncp-web.cfg +++ /dev/null @@ -1 +0,0 @@ -LANGUAGE_=[_auto_,en,de,es,zh] -- cgit v1.2.3