-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInternationalization.php
More file actions
51 lines (46 loc) · 963 Bytes
/
Internationalization.php
File metadata and controls
51 lines (46 loc) · 963 Bytes
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
<?php
/**
* User: mathieu.savy
* Date: 05/08/13
* Time: 15:02
*/
namespace Lib;
class Internationalization
{
/** @var Dictionary */
private static $dico = null;
/**
* @throws \Exception
*/
public static function init()
{
$default_locale = DEFAULT_LOCALE;
$locale = LOCALE;
if (class_exists($locale))
self::$dico = new $locale();
else
{
$tab = explode("_", $locale);
if (class_exists($tab[0]))
self::$dico = new $tab[0]();
else if (class_exists($default_locale))
self::$dico = new $default_locale();
else
{
if (ENV == MicroMuffin::ENV_DEV)
throw new \Exception("No dictionary found");
}
}
}
/**
* @param $string
* @return null
*/
public static function translate($string)
{
if (is_null(self::$dico) && ENV == MicroMuffin::ENV_PROD)
return null;
else
echo self::$dico->translate($string);
}
}