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