/
Lang.php
46 lines (40 loc) · 911 Bytes
/
Lang.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
<?php
namespace Tpay\OpenApi\Locale;
use Tpay\OpenApi\Utilities\TpayException;
class Lang extends Keys
{
static $currentLanguage = 'en';
/**
* Change current language
*
* @param string $lang language code
*
* @throws TpayException
*/
public static function setLang($lang)
{
if (array_key_exists($lang, static::$translations)) {
static::$currentLanguage = $lang;
} else {
throw new TpayException('This language is not supported: '.$lang);
}
}
/**
* Get and print translated string
*/
public static function lang($key)
{
echo static::get($key);
}
/**
* Get translated string
*
* @param string $key
*
* @return string
*/
public static function get($key)
{
return static::$translations[static::$currentLanguage][$key];
}
}