Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.30% |
26 / 27 |
|
90.00% |
9 / 10 |
CRAP | |
0.00% |
0 / 1 |
Language | |
96.30% |
26 / 27 |
|
90.00% |
9 / 10 |
20 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
setLatin | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLatin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLangId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLangId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setEastAsia | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getEastAsia | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setBidirectional | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getBidirectional | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateLocale | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
8.09 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Style; |
19 | |
20 | use InvalidArgumentException; |
21 | |
22 | /** |
23 | * Language |
24 | * A couple of predefined values are defined here, see the websites below for more values. |
25 | * |
26 | * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html |
27 | * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx |
28 | */ |
29 | final class Language extends AbstractStyle |
30 | { |
31 | const EN_US = 'en-US'; |
32 | const EN_US_ID = 1033; |
33 | |
34 | const EN_GB = 'en-GB'; |
35 | const EN_GB_ID = 2057; |
36 | |
37 | const FR_FR = 'fr-FR'; |
38 | const FR_FR_ID = 1036; |
39 | |
40 | const FR_BE = 'fr-BE'; |
41 | const FR_BE_ID = 2060; |
42 | |
43 | const FR_CH = 'fr-CH'; |
44 | const FR_CH_ID = 4108; |
45 | |
46 | const ES_ES = 'es-ES'; |
47 | const ES_ES_ID = 3082; |
48 | |
49 | const DE_DE = 'de-DE'; |
50 | const DE_DE_ID = 1031; |
51 | |
52 | const DE_CH = 'de-CH'; |
53 | const DE_CH_ID = 2055; |
54 | |
55 | const HE_IL = 'he-IL'; |
56 | const HE_IL_ID = 1037; |
57 | |
58 | const IT_IT = 'it-IT'; |
59 | const IT_IT_ID = 1040; |
60 | |
61 | const IT_CH = 'it-CH'; |
62 | const IT_CH_ID = 2064; |
63 | |
64 | const JA_JP = 'ja-JP'; |
65 | const JA_JP_ID = 1041; |
66 | |
67 | const KO_KR = 'ko-KR'; |
68 | const KO_KR_ID = 1042; |
69 | |
70 | const ZH_CN = 'zh-CN'; |
71 | const ZH_CN_ID = 2052; |
72 | |
73 | const HI_IN = 'hi-IN'; |
74 | const HI_IN_ID = 1081; |
75 | |
76 | const PT_BR = 'pt-BR'; |
77 | const PT_BR_ID = 1046; |
78 | |
79 | const NL_NL = 'nl-NL'; |
80 | const NL_NL_ID = 1043; |
81 | |
82 | const SV_SE = 'sv-SE'; |
83 | const SV_SE_ID = 1053; |
84 | |
85 | const UK_UA = 'uk-UA'; |
86 | const UK_UA_ID = 1058; |
87 | |
88 | const RU_RU = 'ru-RU'; |
89 | const RU_RU_ID = 1049; |
90 | |
91 | /** |
92 | * Language ID, used for RTF document generation. |
93 | * |
94 | * @var int |
95 | * |
96 | * @see https://technet.microsoft.com/en-us/library/cc179219.aspx |
97 | */ |
98 | private $langId; |
99 | |
100 | /** |
101 | * Latin Language. |
102 | * |
103 | * @var string |
104 | */ |
105 | private $latin; |
106 | |
107 | /** |
108 | * East Asian Language. |
109 | * |
110 | * @var string |
111 | */ |
112 | private $eastAsia; |
113 | |
114 | /** |
115 | * Complex Script Language. |
116 | * |
117 | * @var string |
118 | */ |
119 | private $bidirectional; |
120 | |
121 | /** |
122 | * Constructor. |
123 | * |
124 | * @param null|string $latin |
125 | * @param null|string $eastAsia |
126 | * @param null|string $bidirectional |
127 | */ |
128 | public function __construct($latin = null, $eastAsia = null, $bidirectional = null) |
129 | { |
130 | if (!empty($latin)) { |
131 | $this->setLatin($latin); |
132 | } |
133 | if (!empty($eastAsia)) { |
134 | $this->setEastAsia($eastAsia); |
135 | } |
136 | if (!empty($bidirectional)) { |
137 | $this->setBidirectional($bidirectional); |
138 | } |
139 | } |
140 | |
141 | /** |
142 | * Set the Latin Language. |
143 | * |
144 | * @param string $latin |
145 | * The value for the latin language |
146 | * |
147 | * @return self |
148 | */ |
149 | public function setLatin($latin) |
150 | { |
151 | $this->latin = $this->validateLocale($latin); |
152 | |
153 | return $this; |
154 | } |
155 | |
156 | /** |
157 | * Get the Latin Language. |
158 | * |
159 | * @return null|string |
160 | */ |
161 | public function getLatin() |
162 | { |
163 | return $this->latin; |
164 | } |
165 | |
166 | /** |
167 | * Set the Language ID. |
168 | * |
169 | * @param int $langId |
170 | * The value for the language ID |
171 | * |
172 | * @return self |
173 | * |
174 | * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx |
175 | */ |
176 | public function setLangId($langId) |
177 | { |
178 | $this->langId = $langId; |
179 | |
180 | return $this; |
181 | } |
182 | |
183 | /** |
184 | * Get the Language ID. |
185 | * |
186 | * @return int |
187 | */ |
188 | public function getLangId() |
189 | { |
190 | return $this->langId; |
191 | } |
192 | |
193 | /** |
194 | * Set the East Asian Language. |
195 | * |
196 | * @param string $eastAsia |
197 | * The value for the east asian language |
198 | * |
199 | * @return self |
200 | */ |
201 | public function setEastAsia($eastAsia) |
202 | { |
203 | $this->eastAsia = $this->validateLocale($eastAsia); |
204 | |
205 | return $this; |
206 | } |
207 | |
208 | /** |
209 | * Get the East Asian Language. |
210 | * |
211 | * @return null|string |
212 | */ |
213 | public function getEastAsia() |
214 | { |
215 | return $this->eastAsia; |
216 | } |
217 | |
218 | /** |
219 | * Set the Complex Script Language. |
220 | * |
221 | * @param string $bidirectional |
222 | * The value for the complex script language |
223 | * |
224 | * @return self |
225 | */ |
226 | public function setBidirectional($bidirectional) |
227 | { |
228 | $this->bidirectional = $this->validateLocale($bidirectional); |
229 | |
230 | return $this; |
231 | } |
232 | |
233 | /** |
234 | * Get the Complex Script Language. |
235 | * |
236 | * @return null|string |
237 | */ |
238 | public function getBidirectional() |
239 | { |
240 | return $this->bidirectional; |
241 | } |
242 | |
243 | /** |
244 | * Validates that the language passed is in the format xx-xx. |
245 | * |
246 | * @param string $locale |
247 | * |
248 | * @return string |
249 | */ |
250 | private function validateLocale($locale) |
251 | { |
252 | if ($locale !== null) { |
253 | $locale = str_replace('_', '-', $locale); |
254 | } |
255 | |
256 | if ($locale !== null && strlen($locale) === 2) { |
257 | return strtolower($locale) . '-' . strtoupper($locale); |
258 | } |
259 | if ($locale === 'und') { |
260 | return 'en-EN'; |
261 | } |
262 | if ($locale !== null && $locale !== 'zxx' && strstr($locale, '-') === false) { |
263 | throw new InvalidArgumentException($locale . ' is not a valid language code'); |
264 | } |
265 | |
266 | return $locale; |
267 | } |
268 | } |