aboutsummaryrefslogtreecommitdiff
path: root/Neutron-trunk/api/lang
diff options
context:
space:
mode:
Diffstat (limited to 'Neutron-trunk/api/lang')
-rw-r--r--Neutron-trunk/api/lang/processor.php57
-rw-r--r--Neutron-trunk/api/lang/setup.php56
2 files changed, 113 insertions, 0 deletions
diff --git a/Neutron-trunk/api/lang/processor.php b/Neutron-trunk/api/lang/processor.php
new file mode 100644
index 0000000..8ab2e99
--- /dev/null
+++ b/Neutron-trunk/api/lang/processor.php
@@ -0,0 +1,57 @@
+<?php
+
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang")) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang", "fr");
+}
+
+$langsel = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang");
+$lang = [];
+
+if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel)) {
+ $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/");
+ foreach ($langprops as $langprop) {
+ if ($langprop != "." && $langprop != "..") {
+ $langpieces = explode("/", implode("/", explode("\\", $langprop)));
+ $langitemsel = explode(".", $langpieces[count($langpieces) - 1]);
+ $langitem = $langitemsel[count($langitemsel) - 1];
+ if ($langitemsel[count($langitemsel) - 1] != "json") {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON.");
+ } else {
+ json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop), true);
+ if (json_last_error() == JSON_ERROR_NONE) {
+ $lang[$langitemsel[count($langitemsel) - 2]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop), true);
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry.");
+ }
+ }
+ }
+ }
+} else {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr")) {
+ echo("Unable to load language files: unable to find selected language files, loading fallback files");
+ $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/");
+ foreach ($langprops as $langprop) {
+ if ($langprop != "." && $langprop != "..") {
+ $langpieces = explode("/", implode("/", explode("\\", $langprop)));
+ $langitemsel = explode(".", $langpieces[count($langpieces) - 1]);
+ $langitem = $langitemsel[count($langitemsel) - 1];
+ if ($langitemsel[count($langitemsel) - 1] != "json") {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON.");
+ } else {
+ json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop), true);
+ if (json_last_error() == JSON_ERROR_NONE) {
+ $lang[$langitemsel[count($langitemsel) - 2]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop), true);
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry.");
+ }
+ }
+ }
+ }
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language files: unable to find selected language files, and unable to find fallback language files");
+ }
+}
+
+if (isset($_GET['verboseLang'])) {
+ var_dump($lang);
+} \ No newline at end of file
diff --git a/Neutron-trunk/api/lang/setup.php b/Neutron-trunk/api/lang/setup.php
new file mode 100644
index 0000000..88792e2
--- /dev/null
+++ b/Neutron-trunk/api/lang/setup.php
@@ -0,0 +1,56 @@
+<?php
+
+if (!isset($_GET['lang'])) {
+ $nolang = true;
+} else {
+ $nolang = false;
+
+ $langsel = $_GET['lang'];
+ echo("<script>const lang = '" . $langsel . "';</script>");
+ $lang = [];
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel)) {
+ $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel);
+ foreach ($langprops as $langprop) {
+ if ($langprop != "." && $langprop != "..") {
+ $langpieces = explode("/", implode("/", explode("\\", $langprop)));
+ $langitemsel = explode(".", $langpieces[count($langpieces) - 1]);
+ $langitem = $langitemsel[count($langitemsel) - 1];
+ if ($langitemsel[count($langitemsel) - 1] != "json") {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON.");
+ } else {
+ json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop));
+ if (json_last_error() == JSON_ERROR_NONE) {
+ $lang[$langitemsel[count($langitemsel) - 2]] = (array)json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop));
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry.");
+ }
+ }
+ }
+ }
+ } else {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr")) {
+ echo("Unable to load language files: unable to find selected language files, loading fallback files");
+ $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr");
+ foreach ($langprops as $langprop) {
+ if ($langprop != "." && $langprop != "..") {
+ $langpieces = explode("/", implode("/", explode("\\", $langprop)));
+ $langitemsel = explode(".", $langpieces[count($langpieces) - 1]);
+ $langitem = $langitemsel[count($langitemsel) - 1];
+ if ($langitemsel[count($langitemsel) - 1] != "json") {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON.");
+ } else {
+ json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop));
+ if (json_last_error() == JSON_ERROR_NONE) {
+ $lang[$langitemsel[count($langitemsel) - 2]] = (array)json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop));
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry.");
+ }
+ }
+ }
+ }
+ } else {
+ require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language files: unable to find selected language files, and unable to find fallback language files");
+ }
+ }
+} \ No newline at end of file