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