TYPO3 CMS  TYPO3_6-2
Locales.php
Go to the documentation of this file.
1 <?php
3 
31 
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 
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 
140  protected $isoMapping;
141 
148 
154  static public function initialize() {
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 
184  public function getLocales() {
185  return array_keys($this->languages);
186  }
187 
193  public function getLanguages() {
194  return $this->languages;
195  }
196 
202  public function getIsoMapping() {
203  return $this->isoMapping;
204  }
205 
212  public function getTerLocales() {
213  return $this->convertToTerLocales(array_keys($this->languages));
214  }
215 
222  public function getLocaleDependencies($locale) {
223  $dependencies = array();
224  if (isset($this->localeDependencies[$locale])) {
225  $dependencies = $this->localeDependencies[$locale];
226  // Search for dependencies recursively
227  $localeDependencies = $dependencies;
228  foreach ($localeDependencies as $dependency) {
229  if (isset($this->localeDependencies[$dependency])) {
230  $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
231  }
232  }
233  }
234  return $dependencies;
235  }
236 
244  public function getTerLocaleDependencies($locale) {
245  $terLocale = isset($this->isoMapping[$locale]) ? $this->isoMapping[$locale] : $locale;
246  return $this->convertToTerLocales($this->getLocaleDependencies($terLocale));
247  }
248 
256  protected function convertToTerLocales(array $locales) {
257  $terLocales = array();
258  foreach ($locales as $locale) {
259  $terLocales[] = isset($this->isoReverseMapping[$locale]) ? $this->isoReverseMapping[$locale] : $locale;
260  }
261  return $terLocales;
262  }
263 
264 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
convertToTerLocales(array $locales)
Definition: Locales.php:256
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
$locales
Definition: be_users.php:6