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