[!!!][TASK] Remove deprecated code from sysext core
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Localization / Locales.php
1 <?php
2 namespace TYPO3\CMS\Core\Localization;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Locales.
18 *
19 * Defining backend system languages
20 * When adding new keys, remember to:
21 * - Add character encoding for lang. key in \TYPO3\CMS\Core\Charset\CharsetConverter
22 * (default for new languages is "utf-8")
23 * - Add mappings for language in \TYPO3\CMS\Core\Charset\CharsetConverter
24 * (TYPO3/ISO, language/script, script/charset)
25 * - Update 'setup' extension labels (sysext/setup/mod/locallang.xlf)
26 * That's it!
27 *
28 * @author Xavier Perseguers <typo3@perseguers.ch>
29 */
30 class Locales implements \TYPO3\CMS\Core\SingletonInterface {
31
32 /**
33 * Supported TYPO3 languages with locales
34 *
35 * @var array
36 */
37 protected $languages = array(
38 'default' => 'English',
39 'af' => 'Afrikaans',
40 'ar' => 'Arabic',
41 'bs' => 'Bosnian',
42 'bg' => 'Bulgarian',
43 'ca' => 'Catalan',
44 'ch' => 'Chinese (Simpl.)',
45 'cs' => 'Czech',
46 'da' => 'Danish',
47 'de' => 'German',
48 'el' => 'Greek',
49 'eo' => 'Esperanto',
50 'es' => 'Spanish',
51 'et' => 'Estonian',
52 'eu' => 'Basque',
53 'fa' => 'Persian',
54 'fi' => 'Finnish',
55 'fo' => 'Faroese',
56 'fr' => 'French',
57 'fr_CA' => 'French (Canada)',
58 'gl' => 'Galician',
59 'he' => 'Hebrew',
60 'hi' => 'Hindi',
61 'hr' => 'Croatian',
62 'hu' => 'Hungarian',
63 'is' => 'Icelandic',
64 'it' => 'Italian',
65 'ja' => 'Japanese',
66 'ka' => 'Georgian',
67 'kl' => 'Greenlandic',
68 'km' => 'Khmer',
69 'ko' => 'Korean',
70 'lt' => 'Lithuanian',
71 'lv' => 'Latvian',
72 'ms' => 'Malay',
73 'nl' => 'Dutch',
74 'no' => 'Norwegian',
75 'pl' => 'Polish',
76 'pt' => 'Portuguese',
77 'pt_BR' => 'Brazilian Portuguese',
78 'ro' => 'Romanian',
79 'ru' => 'Russian',
80 'sk' => 'Slovak',
81 'sl' => 'Slovenian',
82 'sq' => 'Albanian',
83 'sr' => 'Serbian',
84 'sv' => 'Swedish',
85 'th' => 'Thai',
86 'tr' => 'Turkish',
87 'uk' => 'Ukrainian',
88 'vi' => 'Vietnamese',
89 'zh' => 'Chinese (Trad.)'
90 );
91
92 /**
93 * Mapping with codes used by TYPO3 4.5 and below
94 *
95 * @var array
96 */
97 protected $isoReverseMapping = array(
98 'bs' => 'ba',
99 // Bosnian
100 'cs' => 'cz',
101 // Czech
102 'da' => 'dk',
103 // Danish
104 'el' => 'gr',
105 // Greek
106 'fr_CA' => 'qc',
107 // French (Canada)
108 'gl' => 'ga',
109 // Galician
110 'ja' => 'jp',
111 // Japanese
112 'ka' => 'ge',
113 // Georgian
114 'kl' => 'gl',
115 // Greenlandic
116 'ko' => 'kr',
117 // Korean
118 'ms' => 'my',
119 // Malay
120 'pt_BR' => 'br',
121 // Portuguese (Brazil)
122 'sl' => 'si',
123 // Slovenian
124 'sv' => 'se',
125 // Swedish
126 'uk' => 'ua',
127 // Ukrainian
128 'vi' => 'vn',
129 // Vietnamese
130 'zh' => 'hk',
131 // Chinese (China)
132 'zh_CN' => 'ch',
133 // Chinese (Simplified)
134 'zh_HK' => 'hk'
135 );
136
137 /**
138 * @var array
139 */
140 protected $isoMapping;
141
142 /**
143 * Dependencies for locales
144 *
145 * @var array
146 */
147 protected $localeDependencies;
148
149 /**
150 * Initializes the languages.
151 *
152 * @return void
153 */
154 static public function initialize() {
155 /** @var $instance \TYPO3\CMS\Core\Localization\Locales */
156 $instance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
157 $instance->isoMapping = array_flip($instance->isoReverseMapping);
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 // Initializes the locale dependencies with TYPO3 supported locales
167 $instance->localeDependencies = array();
168 foreach ($instance->languages as $locale => $name) {
169 if (strlen($locale) == 5) {
170 $instance->localeDependencies[$locale] = array(substr($locale, 0, 2));
171 }
172 }
173 // Merge user-provided locale dependencies
174 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) {
175 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
176 }
177 }
178
179 /**
180 * Returns the locales.
181 *
182 * @return array
183 */
184 public function getLocales() {
185 return array_keys($this->languages);
186 }
187
188 /**
189 * Returns the supported languages indexed by their corresponding locale.
190 *
191 * @return array
192 */
193 public function getLanguages() {
194 return $this->languages;
195 }
196
197 /**
198 * Returns the mapping between TYPO3 (old) language codes and ISO codes.
199 *
200 * @return array
201 */
202 public function getIsoMapping() {
203 return $this->isoMapping;
204 }
205
206 /**
207 * Returns the dependencies of a given locale, if any.
208 *
209 * @param string $locale
210 * @return array
211 */
212 public function getLocaleDependencies($locale) {
213 $dependencies = array();
214 if (isset($this->localeDependencies[$locale])) {
215 $dependencies = $this->localeDependencies[$locale];
216 // Search for dependencies recursively
217 $localeDependencies = $dependencies;
218 foreach ($localeDependencies as $dependency) {
219 if (isset($this->localeDependencies[$dependency])) {
220 $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
221 }
222 }
223 }
224 return $dependencies;
225 }
226
227 }