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 | * $Id$ |
17 | * | |
18 | */ | |
19 | class CRM_Core_I18n_PseudoConstant { | |
6a488035 | 20 | |
a0ee3941 EM |
21 | /** |
22 | * @param $short | |
23 | * | |
24 | * @return mixed | |
25 | */ | |
00be9182 | 26 | public static function longForShort($short) { |
6a488035 TO |
27 | $longForShortMapping = self::longForShortMapping(); |
28 | return $longForShortMapping[$short]; | |
29 | } | |
30 | ||
a0ee3941 EM |
31 | /** |
32 | * @return array | |
33 | */ | |
00be9182 | 34 | public static function &longForShortMapping() { |
6a488035 TO |
35 | static $longForShortMapping = NULL; |
36 | if ($longForShortMapping === NULL) { | |
be2fb01f CW |
37 | $rows = []; |
38 | CRM_Core_OptionValue::getValues(['name' => 'languages'], $rows); | |
6a488035 | 39 | |
be2fb01f | 40 | $longForShortMapping = []; |
6a488035 TO |
41 | foreach ($rows as $row) { |
42 | $longForShortMapping[$row['value']] = $row['name']; | |
43 | } | |
44 | // hand-crafted enforced overrides for language variants | |
8ef12e64 | 45 | // NB: when adding support for a regional override for a new language below, update |
befcb21d | 46 | // relevant comments in templates/CRM/common/civicrm.settings.php.template as well |
6a488035 TO |
47 | $longForShortMapping['zh'] = defined("CIVICRM_LANGUAGE_MAPPING_ZH") ? CIVICRM_LANGUAGE_MAPPING_ZH : 'zh_CN'; |
48 | $longForShortMapping['en'] = defined("CIVICRM_LANGUAGE_MAPPING_EN") ? CIVICRM_LANGUAGE_MAPPING_EN : 'en_US'; | |
49 | $longForShortMapping['fr'] = defined("CIVICRM_LANGUAGE_MAPPING_FR") ? CIVICRM_LANGUAGE_MAPPING_FR : 'fr_FR'; | |
50 | $longForShortMapping['pt'] = defined("CIVICRM_LANGUAGE_MAPPING_PT") ? CIVICRM_LANGUAGE_MAPPING_PT : 'pt_PT'; | |
51 | $longForShortMapping['es'] = defined("CIVICRM_LANGUAGE_MAPPING_ES") ? CIVICRM_LANGUAGE_MAPPING_ES : 'es_ES'; | |
52 | } | |
53 | return $longForShortMapping; | |
54 | } | |
55 | ||
a0ee3941 EM |
56 | /** |
57 | * @param $long | |
58 | * | |
59 | * @return string | |
60 | */ | |
00be9182 | 61 | public static function shortForLong($long) { |
6a488035 TO |
62 | return substr($long, 0, 2); |
63 | } | |
96025800 | 64 | |
3a55aa6b ML |
65 | /** |
66 | * Returns a list of ISO 639-1 "right-to-left" language codes. | |
67 | * | |
68 | * @return array | |
69 | */ | |
70 | public static function getRTLlanguages() { | |
be2fb01f | 71 | $rtl = [ |
3a55aa6b ML |
72 | 'ar', |
73 | 'fa', | |
74 | 'he', | |
75 | 'ur', | |
be2fb01f | 76 | ]; |
3a55aa6b ML |
77 | |
78 | return $rtl; | |
79 | } | |
80 | ||
6a488035 | 81 | } |