forked from ifrpl/muyo
/
locale.php
66 lines (57 loc) · 1.22 KB
/
locale.php
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
<?php
// Copyright IF Research Sp. z o.o. 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
if( !function_exists('locale') )
{
/**
* @param string $lang
*/
function locale($lang)
{
global $config;
$lang = str_replace('..','',$lang);
$lang = str_replace('/','',$lang);
if(file_exists($file = '../locale/'.$lang.'.php'))
{
require_once $file;
}
elseif(file_exists($file = '../locale/en_US.php'))
{
require_once $file;
}
else
{
$locale = array();
}
if( debug_assert(isset($locale), "locale {$lang} isn't defined") )
{
$config->lang = $lang;
$config->locale = object($locale);
}
}
}
if( !function_exists('tr') )
{
/**
* @param string $ret
*
* @return mixed
*/
function tr($ret)
{
global $config;
if(!isset($config->locale->{$ret}))
{
$filePath = defined('ROOT_PATH') ? ROOT_PATH : '';
$filePath .= '/locale/'.$config->lang.'.found';
file_put_contents(
$filePath,
"\$locale['{$ret}'] = '{$ret}';\n",
FILE_APPEND
);
}
return isset($config->locale->$ret)?$config->locale->$ret:$ret;
}
}