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
|
|
|
|
10
|
|
|
namespace Transfer\EzPlatform\Repository\Values; |
11
|
|
|
|
12
|
|
|
use Transfer\EzPlatform\Exception\LanguageNotFoundException; |
13
|
|
|
use Transfer\EzPlatform\Repository\Values\Mapper\LanguageMapper; |
14
|
|
|
|
15
|
|
|
/* |
16
|
|
|
|
17
|
|
|
** Available keys: ** |
18
|
|
|
|
19
|
|
|
$data = [ |
20
|
|
|
code => string |
21
|
|
|
name => string |
22
|
|
|
enabled => bool |
23
|
|
|
], |
24
|
|
|
$properties = [ |
25
|
|
|
id => int |
26
|
|
|
action => int {@link see \Transfer\EzPlatform\Data\Action\Enum\Action} |
27
|
|
|
] |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
** Required on `create`: |
31
|
|
|
**** Required by transfer: |
32
|
|
|
code |
33
|
|
|
|
34
|
|
|
**** Required by eZ: |
35
|
|
|
code |
36
|
|
|
name |
37
|
|
|
|
38
|
|
|
** Required on `update`: |
39
|
|
|
**** Required by transfer: |
40
|
|
|
code |
41
|
|
|
name |
42
|
|
|
|
43
|
|
|
**** Required by eZ: |
44
|
|
|
code |
45
|
|
|
name |
46
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Content type object. |
51
|
|
|
*/ |
52
|
|
|
class LanguageObject extends EzPlatformObject |
53
|
|
|
{ |
54
|
|
|
/** |
55
|
|
|
* @var LanguageMapper |
56
|
|
|
*/ |
57
|
|
|
private $mapper; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return LanguageMapper |
61
|
|
|
*/ |
62
|
35 |
|
public function getMapper() |
63
|
|
|
{ |
64
|
35 |
|
if (!$this->mapper) { |
65
|
35 |
|
$this->mapper = new LanguageMapper($this); |
66
|
35 |
|
} |
67
|
|
|
|
68
|
35 |
|
return $this->mapper; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Because a name is required. |
73
|
|
|
* |
74
|
|
|
* @var array |
75
|
|
|
*/ |
76
|
|
|
protected $defaultNameMapping = array( |
77
|
|
|
'ara-SA' => 'Arabic', |
78
|
|
|
'cat-ES' => 'Catalan', |
79
|
|
|
'chi-CN' => 'Simplified Chinese', |
80
|
|
|
'chi-HK' => 'Traditional Chinese (HongKong)', |
81
|
|
|
'chi-TW' => 'Traditional Chinese (Taiwan)', |
82
|
|
|
'cro-HR' => 'Croatian (Hrvatski)', |
83
|
|
|
'cze-CZ' => 'Czech', |
84
|
|
|
'dan-DK' => 'Danish', |
85
|
|
|
'dut-NL' => 'Dutch', |
86
|
|
|
'ell-GR' => 'Greek (Hellenic)', |
87
|
|
|
'eng-AU' => 'English (Australia)', |
88
|
|
|
'eng-CA' => 'English (Canada)', |
89
|
|
|
'eng-GB' => 'English (United Kingdom)', |
90
|
|
|
'eng-NZ' => 'English (New Zealand)', |
91
|
|
|
'eng-US' => 'English (American)', |
92
|
|
|
'epo-EO' => 'Esperanto', |
93
|
|
|
'esl-ES' => 'Spanish (Spain)', |
94
|
|
|
'esl-MX' => 'Spanish (Mexico)', |
95
|
|
|
'fin-FI' => 'Finnish', |
96
|
|
|
'fre-BE' => 'French (Belgium)', |
97
|
|
|
'fre-CA' => 'French (Canada)', |
98
|
|
|
'fre-FR' => 'French (France)', |
99
|
|
|
'ger-DE' => 'German', |
100
|
|
|
'heb-IL' => 'Hebrew', |
101
|
|
|
'hin-IN' => 'Hindi (India)', |
102
|
|
|
'hun-HU' => 'Hungarian', |
103
|
|
|
'ind-ID' => 'Indonesian', |
104
|
|
|
'ita-IT' => 'Italian', |
105
|
|
|
'jpn-JP' => 'Japanese', |
106
|
|
|
'kor-KR' => 'Korean', |
107
|
|
|
'nno-NO' => 'Norwegian (Nynorsk)', |
108
|
|
|
'nor-NO' => 'Norwegian (Bokmal)', |
109
|
|
|
'pol-PL' => 'Polish', |
110
|
|
|
'por-BR' => 'Portuguese (Brazil)', |
111
|
|
|
'por-MZ' => 'Portuguese (Mozambique)', |
112
|
|
|
'por-PT' => 'Portuguese (Portugal)', |
113
|
|
|
'rus-RU' => 'Russian', |
114
|
|
|
'ser-SR' => 'Serbian (Srpski)', |
115
|
|
|
'slk-SK' => 'Slovak', |
116
|
|
|
'srp-RS' => 'Serbian (Српски)', |
117
|
|
|
'swe-SE' => 'Swedish', |
118
|
|
|
'tur-TR' => 'Turkish', |
119
|
|
|
'ukr-UA' => 'Ukrainian', |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* LanguageObject constructor. |
124
|
|
|
* |
125
|
|
|
* @param array $data |
126
|
|
|
* |
127
|
|
|
* @throws LanguageNotFoundException |
128
|
|
|
*/ |
129
|
38 |
|
public function __construct($data, $properties = []) |
130
|
|
|
{ |
131
|
38 |
|
parent::__construct($data, $properties); |
132
|
38 |
|
if (!isset($this->data['name'])) { |
133
|
38 |
|
$this->data['name'] = $this->getDefaultName($this->data['code']); |
134
|
37 |
|
} |
135
|
37 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $code |
139
|
|
|
* |
140
|
|
|
* @return string |
141
|
|
|
* |
142
|
|
|
* @throws LanguageNotFoundException |
143
|
|
|
*/ |
144
|
38 |
|
public function getDefaultName($code) |
145
|
|
|
{ |
146
|
38 |
|
if (!array_key_exists($code, $this->defaultNameMapping)) { |
147
|
1 |
|
throw new LanguageNotFoundException(sprintf('Default language name for code "%s" not found.', $code)); |
148
|
|
|
} |
149
|
|
|
|
150
|
37 |
|
return $this->defaultNameMapping[$code]; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|