TYPO3 CMS  TYPO3_7-6
Locales.php
Go to the documentation of this file.
1 <?php
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 
19 
33 {
39  protected $languages = [
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 
99  protected $isoReverseMapping = [
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 
126  protected $isoMapping;
127 
134 
140  public static function initialize()
141  {
143  $instance = GeneralUtility::makeInstance(self::class);
144  $instance->isoMapping = array_flip($instance->isoReverseMapping);
145  // Allow user-defined locales
146  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'])) {
147  foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'] as $locale => $name) {
148  if (!isset($instance->languages[$locale])) {
149  $instance->languages[$locale] = $name;
150  }
151  }
152  }
153  // Initializes the locale dependencies with TYPO3 supported locales
154  $instance->localeDependencies = [];
155  foreach ($instance->languages as $locale => $name) {
156  if (strlen($locale) === 5) {
157  $instance->localeDependencies[$locale] = [substr($locale, 0, 2)];
158  }
159  }
160  // Merge user-provided locale dependencies
161  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) {
162  ArrayUtility::mergeRecursiveWithOverrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
163  }
164  }
165 
171  public function getLocales()
172  {
173  return array_keys($this->languages);
174  }
175 
181  public function getLanguages()
182  {
183  return $this->languages;
184  }
185 
191  public function getIsoMapping()
192  {
193  return $this->isoMapping;
194  }
195 
202  public function getLocaleDependencies($locale)
203  {
204  $dependencies = [];
205  if (isset($this->localeDependencies[$locale])) {
206  $dependencies = $this->localeDependencies[$locale];
207  // Search for dependencies recursively
208  $localeDependencies = $dependencies;
209  foreach ($localeDependencies as $dependency) {
210  if (isset($this->localeDependencies[$dependency])) {
211  $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
212  }
213  }
214  }
215  return $dependencies;
216  }
217 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']