-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLocale.php
90 lines (73 loc) · 1.38 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Quokka Framework
*
* @copyright Copyright 2012 Fabien Casters
* @license http://www.gnu.org/licenses/lgpl.html Lesser General Public License
*/
namespace Quokka;
/**
* \Quokka\Locale
*
* @package Quokka
* @author Fabien Casters
*/
class Locale {
/**
* @var string
*/
private $_default = 'en_US.UTF8';
/**
* @var array
*/
private $_locales = ['en_US.UTF8'];
/**
*
* @param $default string
* @param $locales array
* @return void
*/
public function __construct($default, $locales) {
$this->setDefault($default);
$this->_locales = $locales;
}
/**
*
* @return void
*/
public function setDefault($locale) {
setlocale(LC_ALL, $locale);
putenv('LC_ALL=' . $locale);
$this->_default = $locale;
}
/**
*
* @return string
*/
public function getLocale() {
return $this->_default;
}
/**
*
* @return string
*/
public function getLang() {
$info = explode('_', $this->_default, 1);
return $info[0];
}
/**
*
* @return array
*/
public function getLocales() {
return $this->_locales;
}
/**
*
* @param $locale string
* @return void
*/
public function addLocale($locale) {
$this->_locales[] = $locale;
}
}