Merge pull request #18544 from magnolia61/participant_status_notification_default
[civicrm-core.git] / CRM / Core / I18n / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Core_I18n_PseudoConstant {
18
19 /**
20 * @param $short
21 *
22 * @return mixed
23 */
24 public static function longForShort($short) {
25 $longForShortMapping = self::longForShortMapping();
26 return $longForShortMapping[$short];
27 }
28
29 /**
30 * @return array
31 */
32 public static function &longForShortMapping() {
33 static $longForShortMapping = NULL;
34 if ($longForShortMapping === NULL) {
35 $rows = [];
36 CRM_Core_OptionValue::getValues(['name' => 'languages'], $rows);
37
38 $longForShortMapping = [];
39 foreach ($rows as $row) {
40 $longForShortMapping[$row['value']] = $row['name'];
41 }
42 // hand-crafted enforced overrides for language variants
43 // NB: when adding support for a regional override for a new language below, update
44 // relevant comments in templates/CRM/common/civicrm.settings.php.template as well
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';
50 }
51 return $longForShortMapping;
52 }
53
54 /**
55 * @param $long
56 *
57 * @return string
58 */
59 public static function shortForLong($long) {
60 return substr($long, 0, 2);
61 }
62
63 /**
64 * Returns a list of ISO 639-1 "right-to-left" language codes.
65 *
66 * @return array
67 */
68 public static function getRTLlanguages() {
69 $rtl = [
70 'ar',
71 'fa',
72 'he',
73 'ur',
74 ];
75
76 return $rtl;
77 }
78
79 }