aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/translation.php
blob: 4ca6ec83148303ec5232f16d3c085eac0516d300 (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
58
59
60
61
62
63
64
65
66
67
<?php
/*
 * File: ratatoeskr/sys/translation.php
 * Load translation.
 *
 * License:
 * This file is part of Ratatöskr.
 * Ratatöskr is licensed unter the MIT / X11 License.
 * See "ratatoeskr/licenses/ratatoeskr" for more information.
 */

require_once(dirname(__FILE__) . "/utils.php");
require_once(dirname(__FILE__) . "/init_ste.php");

if(!defined("SETUP"))
    require_once(dirname(__FILE__) . "/models.php");

if(!defined("TRANSLATION_PLUGIN_LOADED"))
{
    $ste->register_tag(
        "get_translation",
        function($ste, $params, $sub)
        {
            global $translation;
            if((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]])))
                return "";
            $rv = $translation[$params["for"]];
            return (!empty($params["raw"])) ? $rv : htmlesc($rv);
        }
    );
    define("TRANSLATION_PLUGIN_LOADED", True);
}

/*
 * Function: load_language
 * Load a language (i.e. set the global $translation variable).
 *
 * Parameters:
 *  $lang - The language (2-Letter code, e.g. "en", "de", "it" ...) to load. NULL for default (from database).
 */
function load_language($lang=NULL)
{
    if(!defined("SETUP"))
    {
        global $ratatoeskr_settings;
        if($lang === NULL)
            $lang = $ratatoeskr_settings["default_language"];
    }
    else
    {
        if($lang === NULL)
            $lang = "en";
    }

    /*
     * Because we will include an file defined by the $lang param, we will
     * only allow alphabetic characters, so this function should not be
     * vulnerable to LFI-Exploits...
     */
    $lang = implode("", array_filter(str_split($lang, 1), "ctype_alpha"));

    require(dirname(__FILE__) . "/../translations/$lang.php");

    $GLOBALS["translation"] = $translation;
}

?>