Merge pull request #15916 from civicrm/5.20
[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 * $Id$
17 *
18 */
19 class CRM_Core_I18n_PseudoConstant {
20
21 /**
22 * @param $short
23 *
24 * @return mixed
25 */
26 public static function longForShort($short) {
27 $longForShortMapping = self::longForShortMapping();
28 return $longForShortMapping[$short];
29 }
30
31 /**
32 * @return array
33 */
34 public static function &longForShortMapping() {
35 static $longForShortMapping = NULL;
36 if ($longForShortMapping === NULL) {
37 $rows = [];
38 CRM_Core_OptionValue::getValues(['name' => 'languages'], $rows);
39
40 $longForShortMapping = [];
41 foreach ($rows as $row) {
42 $longForShortMapping[$row['value']] = $row['name'];
43 }
44 // hand-crafted enforced overrides for language variants
45 // NB: when adding support for a regional override for a new language below, update
46 // relevant comments in templates/CRM/common/civicrm.settings.php.template as well
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
56 /**
57 * @param $long
58 *
59 * @return string
60 */
61 public static function shortForLong($long) {
62 return substr($long, 0, 2);
63 }
64
65 /**
66 * Returns a list of ISO 639-1 "right-to-left" language codes.
67 *
68 * @return array
69 */
70 public static function getRTLlanguages() {
71 $rtl = [
72 'ar',
73 'fa',
74 'he',
75 'ur',
76 ];
77
78 return $rtl;
79 }
80
81 }