Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Core_I18n_PseudoConstant { | |
6a488035 | 18 | |
a0ee3941 EM |
19 | /** |
20 | * @param $short | |
21 | * | |
22 | * @return mixed | |
23 | */ | |
00be9182 | 24 | public static function longForShort($short) { |
6a488035 TO |
25 | $longForShortMapping = self::longForShortMapping(); |
26 | return $longForShortMapping[$short]; | |
27 | } | |
28 | ||
a0ee3941 EM |
29 | /** |
30 | * @return array | |
31 | */ | |
00be9182 | 32 | public static function &longForShortMapping() { |
6a488035 TO |
33 | static $longForShortMapping = NULL; |
34 | if ($longForShortMapping === NULL) { | |
be2fb01f CW |
35 | $rows = []; |
36 | CRM_Core_OptionValue::getValues(['name' => 'languages'], $rows); | |
6a488035 | 37 | |
be2fb01f | 38 | $longForShortMapping = []; |
6a488035 TO |
39 | foreach ($rows as $row) { |
40 | $longForShortMapping[$row['value']] = $row['name']; | |
41 | } | |
42 | // hand-crafted enforced overrides for language variants | |
8ef12e64 | 43 | // NB: when adding support for a regional override for a new language below, update |
befcb21d | 44 | // relevant comments in templates/CRM/common/civicrm.settings.php.template as well |
6a488035 TO |
45 | $longForShortMapping['zh'] = defined("CIVICRM_LANGUAGE_MAPPING_ZH") ? CIVICRM_LANGUAGE_MAPPING_ZH : 'zh_CN'; |
46 | $longForShortMapping['en'] = defined("CIVICRM_LANGUAGE_MAPPING_EN") ? CIVICRM_LANGUAGE_MAPPING_EN : 'en_US'; | |
47 | $longForShortMapping['fr'] = defined("CIVICRM_LANGUAGE_MAPPING_FR") ? CIVICRM_LANGUAGE_MAPPING_FR : 'fr_FR'; | |
48 | $longForShortMapping['pt'] = defined("CIVICRM_LANGUAGE_MAPPING_PT") ? CIVICRM_LANGUAGE_MAPPING_PT : 'pt_PT'; | |
49 | $longForShortMapping['es'] = defined("CIVICRM_LANGUAGE_MAPPING_ES") ? CIVICRM_LANGUAGE_MAPPING_ES : 'es_ES'; | |
2ba6acdf | 50 | $longForShortMapping['nl'] = defined("CIVICRM_LANGUAGE_MAPPING_NL") ? CIVICRM_LANGUAGE_MAPPING_NL : 'nl_NL'; |
6a488035 TO |
51 | } |
52 | return $longForShortMapping; | |
53 | } | |
54 | ||
a0ee3941 EM |
55 | /** |
56 | * @param $long | |
57 | * | |
58 | * @return string | |
59 | */ | |
00be9182 | 60 | public static function shortForLong($long) { |
6a488035 TO |
61 | return substr($long, 0, 2); |
62 | } | |
96025800 | 63 | |
3a55aa6b ML |
64 | /** |
65 | * Returns a list of ISO 639-1 "right-to-left" language codes. | |
66 | * | |
67 | * @return array | |
68 | */ | |
69 | public static function getRTLlanguages() { | |
be2fb01f | 70 | $rtl = [ |
3a55aa6b ML |
71 | 'ar', |
72 | 'fa', | |
73 | 'he', | |
74 | 'ur', | |
be2fb01f | 75 | ]; |
3a55aa6b ML |
76 | |
77 | return $rtl; | |
78 | } | |
79 | ||
6a488035 | 80 | } |