MDL-35669 gravatar Provide default image URL to Gravatar
[moodle.git] / lib / typo3 / class.t3lib_l10n_locales.php
blob535bc5ccad2b67d521562ec7cdba484d2e96095e
1 <?php
2 /***************************************************************
3 * Copyright notice
5 * (c) 2011 Xavier Perseguers <typo3@perseguers.ch>
6 * All rights reserved
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 /**
29 * Locales.
31 * Defining backend system languages
32 * When adding new keys, remember to:
33 * - Add character encoding for lang. key in t3lib/class.t3lib_cs.php (default for new languages is "utf-8")
34 * - Add mappings for language in t3lib/class.t3lib_cs.php (TYPO3/ISO, language/script, script/charset)
35 * - Update 'setup' extension labels (sysext/setup/mod/locallang.xlf)
36 * That's it!
38 * @package Core
39 * @subpackage t3lib
40 * @author Xavier Perseguers <typo3@perseguers.ch>
42 class t3lib_l10n_Locales implements t3lib_Singleton {
44 /**
45 * Supported TYPO3 languages with locales
46 * @var array
48 protected $languages = array(
49 'default' => 'English',
50 'af' => 'Afrikaans',
51 'ar' => 'Arabic',
52 'bs' => 'Bosnian',
53 'bg' => 'Bulgarian',
54 'ca' => 'Catalan',
55 'ch' => 'Chinese (Simpl.)',
56 'cs' => 'Czech',
57 'da' => 'Danish',
58 'de' => 'German',
59 'el' => 'Greek',
60 'eo' => 'Esperanto',
61 'es' => 'Spanish',
62 'et' => 'Estonian',
63 'eu' => 'Basque',
64 'fa' => 'Persian',
65 'fi' => 'Finnish',
66 'fo' => 'Faroese',
67 'fr' => 'French',
68 'fr_CA' => 'French (Canada)',
69 'gl' => 'Galician',
70 'he' => 'Hebrew',
71 'hi' => 'Hindi',
72 'hr' => 'Croatian',
73 'hu' => 'Hungarian',
74 'is' => 'Icelandic',
75 'it' => 'Italian',
76 'ja' => 'Japanese',
77 'ka' => 'Georgian',
78 'kl' => 'Greenlandic',
79 'km' => 'Khmer',
80 'ko' => 'Korean',
81 'lt' => 'Lithuanian',
82 'lv' => 'Latvian',
83 'ms' => 'Malay',
84 'nl' => 'Dutch',
85 'no' => 'Norwegian',
86 'pl' => 'Polish',
87 'pt' => 'Portuguese',
88 'pt_BR' => 'Brazilian Portuguese',
89 'ro' => 'Romanian',
90 'ru' => 'Russian',
91 'sk' => 'Slovak',
92 'sl' => 'Slovenian',
93 'sq' => 'Albanian',
94 'sr' => 'Serbian',
95 'sv' => 'Swedish',
96 'th' => 'Thai',
97 'tr' => 'Turkish',
98 'uk' => 'Ukrainian',
99 'vi' => 'Vietnamese',
100 'zh' => 'Chinese (Trad.)',
104 * Supported TYPO3 locales
105 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
106 * @var array
108 protected $locales = array();
111 * Mapping with codes used by TYPO3 4.5 and below
112 * @var array
114 protected $isoReverseMapping = array(
115 'bs' => 'ba', // Bosnian
116 'cs' => 'cz', // Czech
117 'da' => 'dk', // Danish
118 'el' => 'gr', // Greek
119 'fr_CA' => 'qc', // French (Canada)
120 'gl' => 'ga', // Galician
121 'ja' => 'jp', // Japanese
122 'ka' => 'ge', // Georgian
123 'kl' => 'gl', // Greenlandic
124 'ko' => 'kr', // Korean
125 'ms' => 'my', // Malay
126 'pt_BR' => 'br', // Portuguese (Brazil)
127 'sl' => 'si', // Slovenian
128 'sv' => 'se', // Swedish
129 'uk' => 'ua', // Ukrainian
130 'vi' => 'vn', // Vietnamese
131 'zh' => 'hk', // Chinese (China)
132 'zh_CN' => 'ch', // Chinese (Simplified)
133 'zh_HK' => 'hk', // Chinese (China)
137 * @var array
139 protected $isoMapping;
142 * Dependencies for locales
143 * @var array
145 protected $localeDependencies;
148 * Initializes the languages.
150 * @static
151 * @return void
153 public static function initialize() {
154 /** @var $instance t3lib_l10n_Locales */
155 $instance = t3lib_div::makeInstance('t3lib_l10n_Locales');
156 $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;
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));
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 $instance->localeDependencies = t3lib_div::array_merge_recursive_overrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
180 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
182 $instance->locales = array_keys($instance->languages);
185 * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0
187 define('TYPO3_languages', implode('|', $instance->getLocales()));
191 * Returns the locales.
193 * @return array
195 public function getLocales() {
196 return array_keys($this->languages);
200 * Returns the supported languages indexed by their corresponding locale.
202 * @return array
204 public function getLanguages() {
205 return $this->languages;
209 * Returns the mapping between TYPO3 (old) language codes and ISO codes.
211 * @return array
213 public function getIsoMapping() {
214 return $this->isoMapping;
218 * Returns the locales as referenced by the TER and TYPO3 localization files.
220 * @return array
221 * @deprecated since TYPO3 4.6
223 public function getTerLocales() {
224 return $this->convertToTerLocales(array_keys($this->languages));
228 * Returns the dependencies of a given locale, if any.
230 * @param string $locale
231 * @return array
233 public function getLocaleDependencies($locale) {
234 $dependencies = array();
235 if (isset($this->localeDependencies[$locale])) {
236 $dependencies = $this->localeDependencies[$locale];
238 // Search for dependencies recursively
239 $localeDependencies = $dependencies;
240 foreach ($localeDependencies as $dependency) {
241 if (isset($this->localeDependencies[$dependency])) {
242 $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
246 return $dependencies;
250 * Returns the dependencies of a given locale using TER compatible locale codes.
252 * @param string $locale
253 * @return array
254 * @deprecated since TYPO3 4.6
256 public function getTerLocaleDependencies($locale) {
257 $terLocale = isset($this->isoMapping[$locale])
258 ? $this->isoMapping[$locale]
259 : $locale;
260 return $this->convertToTerLocales($this->getLocaleDependencies($terLocale));
264 * Converts an array of ISO locale codes into their TER equivalent.
266 * @param array $locales
267 * @return array
268 * @deprecated since TYPO3 4.6
270 protected function convertToTerLocales(array $locales) {
271 $terLocales = array();
272 foreach ($locales as $locale) {
273 $terLocales[] = isset($this->isoReverseMapping[$locale]) ? $this->isoReverseMapping[$locale] : $locale;
275 return $terLocales;
281 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/l10n/class.t3lib_l10n_locales.php'])) {
282 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/l10n/class.t3lib_l10n_locales.php']);