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