aboutsummaryrefslogtreecommitdiff
path: root/Neutron-trunk/api/lang/processor.php
blob: 8ab2e99cedf95a9a783d0b259641016d02b6a536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
}