[TASK] Post travis notification to #typo3-cms-coredev channel
[Packages/TYPO3.CMS.git] / t3lib / l10n / class.t3lib_l10n_locales.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Xavier Perseguers <typo3@perseguers.ch>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Locales.
30 *
31 * Defining backend system languages
32 * When adding new keys, remember to:
33 * - Add character encoding for lang. key in t3lib/class.t3lib_cs.php (default for new languages is "utf-8")
34 * - Add mappings for language in t3lib/class.t3lib_cs.php (TYPO3/ISO, language/script, script/charset)
35 * - Update 'setup' extension labels (sysext/setup/mod/locallang.xlf)
36 * That's it!
37 *
38 * @package Core
39 * @subpackage t3lib
40 * @author Xavier Perseguers <typo3@perseguers.ch>
41 */
42 class t3lib_l10n_Locales implements t3lib_Singleton {
43
44 /**
45 * Supported TYPO3 languages with locales
46 * @var array
47 */
48 protected $languages = array(
49 'default' => 'English',
50 'af' => 'Afrikaans',
51 'ar' => 'Arabic',
52 'bs' => 'Bosnian',
53 'bg' => 'Bulgarian',
54 'ca' => 'Catalan',
55 'ch' => 'Chinese (Simpl.)',
56 'cs' => 'Czech',
57 'da' => 'Danish',
58 'de' => 'German',
59 'el' => 'Greek',
60 'eo' => 'Esperanto',
61 'es' => 'Spanish',
62 'et' => 'Estonian',
63 'eu' => 'Basque',
64 'fa' => 'Persian',
65 'fi' => 'Finnish',
66 'fo' => 'Faroese',
67 'fr' => 'French',
68 'fr_CA' => 'French (Canada)',
69 'gl' => 'Galician',
70 'he' => 'Hebrew',
71 'hi' => 'Hindi',
72 'hr' => 'Croatian',
73 'hu' => 'Hungarian',
74 'is' => 'Icelandic',
75 'it' => 'Italian',
76 'ja' => 'Japanese',
77 'ka' => 'Georgian',
78 'kl' => 'Greenlandic',
79 'km' => 'Khmer',
80 'ko' => 'Korean',
81 'lt' => 'Lithuanian',
82 'lv' => 'Latvian',
83 'ms' => 'Malay',
84 'nl' => 'Dutch',
85 'no' => 'Norwegian',
86 'pl' => 'Polish',
87 'pt' => 'Portuguese',
88 'pt_BR' => 'Brazilian Portuguese',
89 'ro' => 'Romanian',
90 'ru' => 'Russian',
91 'sk' => 'Slovak',
92 'sl' => 'Slovenian',
93 'sq' => 'Albanian',
94 'sr' => 'Serbian',
95 'sv' => 'Swedish',
96 'th' => 'Thai',
97 'tr' => 'Turkish',
98 'uk' => 'Ukrainian',
99 'vi' => 'Vietnamese',
100 'zh' => 'Chinese (Trad.)',
101 );
102
103 /**
104 * Supported TYPO3 locales
105 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
106 * @var array
107 */
108 protected $locales = array();
109
110 /**
111 * Mapping with codes used by TYPO3 4.5 and below
112 * @var array
113 */
114 protected $isoReverseMapping = array(
115 'bs' => 'ba', // Bosnian
116 'cs' => 'cz', // Czech
117 'da' => 'dk', // Danish
118 'el' => 'gr', // Greek
119 'fr_CA' => 'qc', // French (Canada)
120 'gl' => 'ga', // Galician
121 'ja' => 'jp', // Japanese
122 'ka' => 'ge', // Georgian
123 'kl' => 'gl', // Greenlandic
124 'ko' => 'kr', // Korean
125 'ms' => 'my', // Malay
126 'pt_BR' => 'br', // Portuguese (Brazil)
127 'sl' => 'si', // Slovenian
128 'sv' => 'se', // Swedish
129 'uk' => 'ua', // Ukrainian
130 'vi' => 'vn', // Vietnamese
131 'zh' => 'hk', // Chinese (China)
132 'zh_CN' => 'ch', // Chinese (Simplified)
133 'zh_HK' => 'hk', // Chinese (China)
134 );
135
136 /**
137 * @var array
138 */
139 protected $isoMapping;
140
141 /**
142 * Dependencies for locales
143 * @var array
144 */
145 protected $localeDependencies;
146
147 /**
148 * Initializes the languages.
149 *
150 * @static
151 * @return void
152 */
153 public static function initialize() {
154 /** @var $instance t3lib_l10n_Locales */
155 $instance = t3lib_div::makeInstance('t3lib_l10n_Locales');
156 $instance->isoMapping = array_flip($instance->isoReverseMapping);
157
158 // Allow user-defined locales
159 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'])) {
160 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'] as $locale => $name) {
161 if (!isset($instance->languages[$locale])) {
162 $instance->languages[$locale] = $name;
163 }
164 }
165 }
166
167 // Initializes the locale dependencies with TYPO3 supported locales
168 $instance->localeDependencies = array();
169 foreach ($instance->languages as $locale => $name) {
170 if (strlen($locale) == 5) {
171 $instance->localeDependencies[$locale] = array(substr($locale, 0, 2));
172 }
173 }
174 // Merge user-provided locale dependencies
175 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) {
176 $instance->localeDependencies = t3lib_div::array_merge_recursive_overrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
177 }
178
179 /**
180 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
181 */
182 $instance->locales = array_keys($instance->languages);
183
184 /**
185 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
186 */
187 define('TYPO3_languages', implode('|', $instance->getLocales()));
188 }
189
190 /**
191 * Returns the locales.
192 *
193 * @return array
194 */
195 public function getLocales() {
196 return array_keys($this->languages);
197 }
198
199 /**
200 * Returns the supported languages indexed by their corresponding locale.
201 *
202 * @return array
203 */
204 public function getLanguages() {
205 return $this->languages;
206 }
207
208 /**
209 * Returns the mapping between TYPO3 (old) language codes and ISO codes.
210 *
211 * @return array
212 */
213 public function getIsoMapping() {
214 return $this->isoMapping;
215 }
216
217 /**
218 * Returns the locales as referenced by the TER and TYPO3 localization files.
219 *
220 * @return array
221 * @deprecated since TYPO3 4.6
222 */
223 public function getTerLocales() {
224 return $this->convertToTerLocales(array_keys($this->languages));
225 }
226
227 /**
228 * Returns the dependencies of a given locale, if any.
229 *
230 * @param string $locale
231 * @return array
232 */
233 public function getLocaleDependencies($locale) {
234 $dependencies = array();
235 if (isset($this->localeDependencies[$locale])) {
236 $dependencies = $this->localeDependencies[$locale];
237
238 // Search for dependencies recursively
239 $localeDependencies = $dependencies;
240 foreach ($localeDependencies as $dependency) {
241 if (isset($this->localeDependencies[$dependency])) {
242 $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
243 }
244 }
245 }
246 return $dependencies;
247 }
248
249 /**
250 * Returns the dependencies of a given locale using TER compatible locale codes.
251 *
252 * @param string $locale
253 * @return array
254 * @deprecated since TYPO3 4.6
255 */
256 public function getTerLocaleDependencies($locale) {
257 $terLocale = isset($this->isoMapping[$locale])
258 ? $this->isoMapping[$locale]
259 : $locale;
260 return $this->convertToTerLocales($this->getLocaleDependencies($terLocale));
261 }
262
263 /**
264 * Converts an array of ISO locale codes into their TER equivalent.
265 *
266 * @param array $locales
267 * @return array
268 * @deprecated since TYPO3 4.6
269 */
270 protected function convertToTerLocales(array $locales) {
271 $terLocales = array();
272 foreach ($locales as $locale) {
273 $terLocales[] = isset($this->isoReverseMapping[$locale]) ? $this->isoReverseMapping[$locale] : $locale;
274 }
275 return $terLocales;
276 }
277
278 }
279
280
281 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/l10n/class.t3lib_l10n_locales.php'])) {
282 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/l10n/class.t3lib_l10n_locales.php']);
283 }
284
285 ?>