Merge pull request #16484 from yashodha/dev_1580
[civicrm-core.git] / CRM / Core / I18n / PseudoConstant.php
CommitLineData
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 */
17class 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';
50 }
51 return $longForShortMapping;
52 }
53
a0ee3941
EM
54 /**
55 * @param $long
56 *
57 * @return string
58 */
00be9182 59 public static function shortForLong($long) {
6a488035
TO
60 return substr($long, 0, 2);
61 }
96025800 62
3a55aa6b
ML
63 /**
64 * Returns a list of ISO 639-1 "right-to-left" language codes.
65 *
66 * @return array
67 */
68 public static function getRTLlanguages() {
be2fb01f 69 $rtl = [
3a55aa6b
ML
70 'ar',
71 'fa',
72 'he',
73 'ur',
be2fb01f 74 ];
3a55aa6b
ML
75
76 return $rtl;
77 }
78
6a488035 79}