|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@link Localization_Locale} class. |
|
4
|
|
|
* @package Localization |
|
5
|
|
|
* @subpackage Core |
|
6
|
|
|
* @see Localization_Locale |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace AppLocalize; |
|
10
|
|
|
|
|
11
|
|
|
use AppLocalize\Localization\Countries\BaseCountry; |
|
12
|
|
|
use AppLocalize\Localization\Currencies\CurrencyInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Individual locale representation with information about |
|
16
|
|
|
* the country and currency. |
|
17
|
|
|
* |
|
18
|
|
|
* @package Localization |
|
19
|
|
|
* @subpackage Core |
|
20
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class Localization_Locale implements LocaleInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public const ERROR_LOCALE_LABEL_MISSING = 39102; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $localeName; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var BaseCountry |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $country; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $countryCode; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $languageCode; |
|
45
|
|
|
|
|
46
|
|
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
|
|
$localeName = explode('\\', get_class($this)); |
|
49
|
|
|
$localeName = array_pop($localeName); |
|
50
|
|
|
$tokens = explode('_', $localeName); |
|
51
|
|
|
|
|
52
|
|
|
$this->localeName = $localeName; |
|
53
|
|
|
$this->countryCode = strtolower($tokens[1]); |
|
54
|
|
|
$this->languageCode = strtolower($tokens[0]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getLanguageCode() : string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->languageCode; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function isLocaleKnown(string $localeName) : bool |
|
63
|
|
|
{ |
|
64
|
|
|
return Localization::isLocaleSupported($localeName); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Retrieves the shortened version of the locale name, |
|
69
|
|
|
* e.g. "en" or "de". |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
* @deprecated |
|
73
|
|
|
* @see Localization_Locale::getLanguageCode() |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getShortName() : string |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getLanguageCode(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Retrieves the two-letter country code of |
|
82
|
|
|
* the locale. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string Lowercase code, e.g. "uk" |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getCountryCode() : string |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->countryCode; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Checks if this locale is the builtin application locale |
|
93
|
|
|
* (the one in which application strings are written). |
|
94
|
|
|
* |
|
95
|
|
|
* @return boolean |
|
96
|
|
|
* @see Localization::BUILTIN_LOCALE_NAME |
|
97
|
|
|
*/ |
|
98
|
|
|
public function isNative() : bool |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getName() === Localization::BUILTIN_LOCALE_NAME; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getCountry() : BaseCountry |
|
104
|
|
|
{ |
|
105
|
|
|
if(!isset($this->country)) { |
|
106
|
|
|
$this->country = Localization::createCountries()->getByID($this->getCountryCode()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $this->country; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function getCurrency() : CurrencyInterface |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->getCountry()->getCurrency(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|