|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Transfer. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
|
7
|
|
|
* in the root directory. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Transfer\EzPlatform\Repository\Values; |
|
10
|
|
|
|
|
11
|
|
|
use Transfer\EzPlatform\Exception\LanguageNotFoundException; |
|
12
|
|
|
use Transfer\EzPlatform\Repository\Values\Mapper\LanguageMapper; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Language object. |
|
16
|
|
|
* |
|
17
|
|
|
* @see http://transfer-framework.com/docs/1.0/sources_and_targets/ezplatform/the_objects/languageobject.html |
|
18
|
|
|
*/ |
|
19
|
|
|
class LanguageObject extends EzPlatformObject |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var LanguageMapper |
|
23
|
|
|
*/ |
|
24
|
|
|
private $mapper; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return LanguageMapper |
|
28
|
|
|
*/ |
|
29
|
39 |
|
public function getMapper() |
|
30
|
|
|
{ |
|
31
|
39 |
|
if (!$this->mapper) { |
|
32
|
39 |
|
$this->mapper = new LanguageMapper($this); |
|
33
|
39 |
|
} |
|
34
|
|
|
|
|
35
|
39 |
|
return $this->mapper; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Because a name is required. |
|
40
|
|
|
* |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $defaultNameMapping = array( |
|
44
|
|
|
'ara-SA' => 'Arabic', |
|
45
|
|
|
'cat-ES' => 'Catalan', |
|
46
|
|
|
'chi-CN' => 'Simplified Chinese', |
|
47
|
|
|
'chi-HK' => 'Traditional Chinese (HongKong)', |
|
48
|
|
|
'chi-TW' => 'Traditional Chinese (Taiwan)', |
|
49
|
|
|
'cro-HR' => 'Croatian (Hrvatski)', |
|
50
|
|
|
'cze-CZ' => 'Czech', |
|
51
|
|
|
'dan-DK' => 'Danish', |
|
52
|
|
|
'dut-NL' => 'Dutch', |
|
53
|
|
|
'ell-GR' => 'Greek (Hellenic)', |
|
54
|
|
|
'eng-AU' => 'English (Australia)', |
|
55
|
|
|
'eng-CA' => 'English (Canada)', |
|
56
|
|
|
'eng-GB' => 'English (United Kingdom)', |
|
57
|
|
|
'eng-NZ' => 'English (New Zealand)', |
|
58
|
|
|
'eng-US' => 'English (American)', |
|
59
|
|
|
'epo-EO' => 'Esperanto', |
|
60
|
|
|
'esl-ES' => 'Spanish (Spain)', |
|
61
|
|
|
'esl-MX' => 'Spanish (Mexico)', |
|
62
|
|
|
'fin-FI' => 'Finnish', |
|
63
|
|
|
'fre-BE' => 'French (Belgium)', |
|
64
|
|
|
'fre-CA' => 'French (Canada)', |
|
65
|
|
|
'fre-FR' => 'French (France)', |
|
66
|
|
|
'ger-DE' => 'German', |
|
67
|
|
|
'heb-IL' => 'Hebrew', |
|
68
|
|
|
'hin-IN' => 'Hindi (India)', |
|
69
|
|
|
'hun-HU' => 'Hungarian', |
|
70
|
|
|
'ind-ID' => 'Indonesian', |
|
71
|
|
|
'ita-IT' => 'Italian', |
|
72
|
|
|
'jpn-JP' => 'Japanese', |
|
73
|
|
|
'kor-KR' => 'Korean', |
|
74
|
|
|
'nno-NO' => 'Norwegian (Nynorsk)', |
|
75
|
|
|
'nor-NO' => 'Norwegian (Bokmal)', |
|
76
|
|
|
'pol-PL' => 'Polish', |
|
77
|
|
|
'por-BR' => 'Portuguese (Brazil)', |
|
78
|
|
|
'por-MZ' => 'Portuguese (Mozambique)', |
|
79
|
|
|
'por-PT' => 'Portuguese (Portugal)', |
|
80
|
|
|
'rus-RU' => 'Russian', |
|
81
|
|
|
'ser-SR' => 'Serbian (Srpski)', |
|
82
|
|
|
'slk-SK' => 'Slovak', |
|
83
|
|
|
'srp-RS' => 'Serbian (Српски)', |
|
84
|
|
|
'swe-SE' => 'Swedish', |
|
85
|
|
|
'tur-TR' => 'Turkish', |
|
86
|
|
|
'ukr-UA' => 'Ukrainian', |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* LanguageObject constructor. |
|
91
|
|
|
* |
|
92
|
|
|
* @param array $data |
|
93
|
|
|
* |
|
94
|
|
|
* @throws LanguageNotFoundException |
|
95
|
|
|
*/ |
|
96
|
42 |
|
public function __construct($data, $properties = []) |
|
97
|
|
|
{ |
|
98
|
42 |
|
parent::__construct($data, $properties); |
|
99
|
42 |
|
if (!isset($this->data['name'])) { |
|
100
|
42 |
|
$this->data['name'] = $this->getDefaultName($this->data['code']); |
|
101
|
41 |
|
} |
|
102
|
41 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Allows direct control in LanguageCreateStruct. |
|
106
|
|
|
* |
|
107
|
|
|
* @param \Closure $callback |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function setStructCallback(\Closure $callback) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$this->setProperty('struct_callback', $callback); |
|
112
|
1 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param string $code |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
* |
|
119
|
|
|
* @throws LanguageNotFoundException |
|
120
|
|
|
*/ |
|
121
|
42 |
|
public function getDefaultName($code) |
|
122
|
|
|
{ |
|
123
|
42 |
|
if (!array_key_exists($code, $this->defaultNameMapping)) { |
|
124
|
1 |
|
throw new LanguageNotFoundException(sprintf('Default language name for code "%s" not found.', $code)); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
41 |
|
return $this->defaultNameMapping[$code]; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|