summaryrefslogtreecommitdiffstats
path: root/common/app/classes/Simplel10n.class.php
blob: 7af8564a9086a8268ae09979d3bf54a0e7718413 (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
<?php


class Simplel10n {

    public $locale;
    public $l10nFolder;

    public function __construct($locale='en') {
        $GLOBALS['locale'] = array();
        $this->locale      = $locale;
        $this->l10nFolder  = dirname(__FILE__) . '/../l10n/';
        $this->load($this->l10nFolder . $this->locale);
    }

    public function setL1OnFolder($path) {
        $this->l10nFolder = $path;
    }

    static function getString($str, $comment='') {
        if(array_key_exists($str, $GLOBALS['locale'])) {
            return trim(str_replace('{ok}', '', $GLOBALS['locale'][$str]));
        } else {
            return $str;
        }
    }

    /*
     * This is the same as getString except that we don't remove the {ok} string
     * This is needed only for the extraction script
     */
    static function extractString($str, $comment='') {
        if(array_key_exists($str, $GLOBALS['locale'])) {
            return $GLOBALS['locale'][$str];
        } else {
            return $str;
        }
    }

    static function load($pathToFile) {

        if (!file_exists($pathToFile . '.lang')) return false;

        $file = file($pathToFile . '.lang');

        foreach ($file as $k => $v) {
            if (substr($v,0,1) == ';' && !empty($file[$k+1])) {
                $GLOBALS['locale'][trim(substr($v,1))] = trim($file[$k+1]);
            }
        }
    }
}