/** * Return languages available in this instance of CiviCRM. * * @param $justEnabled boolean whether to return all languages or just the enabled ones * @return array of code/language name mappings */ static function languages($justEnabled = false) { static $all = null; static $enabled = null; if (!$all) { require_once 'CRM/Core/I18n/PseudoConstant.php'; $all =& CRM_Core_I18n_PseudoConstant::languages(); // check which ones are available; add them to $all if not there already $config = CRM_Core_Config::singleton(); $codes = array(); if (is_dir($config->gettextResourceDir)) { $dir = opendir($config->gettextResourceDir); while ($filename = readdir($dir)) { if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) { $codes[] = $filename; if (!isset($all[$filename])) { $all[$filename] = $filename; } } } closedir($dir); } // drop the unavailable languages (except en_US) foreach (array_keys($all) as $code) { if ($code == 'en_US') { continue; } if (!in_array($code, $codes)) { unset($all[$code]); } } } if ($enabled === null) { $config = CRM_Core_Config::singleton(); $enabled = array(); if (isset($config->languageLimit) and $config->languageLimit) { foreach ($all as $code => $name) { if (in_array($code, array_keys($config->languageLimit))) { $enabled[$code] = $name; } } } } return $justEnabled ? $enabled : $all; }
/** * Get the locale set in the hosting CMS * * @return string with the locale or null for none */ function getUFLocale() { // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx // sometimes for CLI based on order called, this might not be set and/or empty global $language; if (empty($language)) { return NULL; } if ($language->language == 'zh-hans') { return 'zh_CN'; } if ($language->language == 'zh-hant') { return 'zh_TW'; } if (preg_match('/^.._..$/', $language->language)) { return $language->language; } return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); }
$tsLocale = 'en_US'; $seedLanguage = 'en_US'; // CRM-16801 This validates that seedLanguage is valid by looking in $langs. // NB: the variable is initial a $_REQUEST for the initial page reload, // then becomes a $_POST when the installation form is submitted. if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) { $seedLanguage = $_REQUEST['seedLanguage']; $tsLocale = $_REQUEST['seedLanguage']; } $config = CRM_Core_Config::singleton(FALSE); $GLOBALS['civicrm_default_error_scope'] = NULL; // The translation files are in the parent directory (l10n) $i18n = CRM_Core_I18n::singleton(); // Support for Arabic, Hebrew, Farsi, etc. // Used in the template.html $short_lang_code = CRM_Core_I18n_PseudoConstant::shortForLong($tsLocale); $text_direction = CRM_Core_I18n::isLanguageRTL($tsLocale) ? 'rtl' : 'ltr'; global $cmsPath; if ($installType == 'drupal') { //CRM-6840 -don't force to install in sites/all/modules/ $object = new CRM_Utils_System_Drupal(); $cmsPath = $object->cmsRootPath(); $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR . 'sites' . CIVICRM_DIRECTORY_SEPARATOR . $siteDir . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm.settings.php'); } elseif ($installType == 'wordpress') { $cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm'; $upload_dir = wp_upload_dir(); $files_dirname = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm'; $wp_civi_settings = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; $wp_civi_settings_deprectated = CIVICRM_PLUGIN_DIR . 'civicrm.settings.php'; if (file_exists($wp_civi_settings_deprectated)) {
/** * @inheritDoc */ public function getUFLocale() { // WPML plugin if (defined('ICL_LANGUAGE_CODE')) { $language = ICL_LANGUAGE_CODE; } // TODO: set language variable for others WordPress plugin if (isset($language)) { return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2)); } else { return NULL; } }
/** * Get the locale set in the hosting CMS * * @return string with the locale or null for none */ function getUFLocale() { // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx global $language; switch (TRUE) { case $language->language == 'zh-hans': return 'zh_CN'; case $language->language == 'zh-hant': return 'zh_TW'; case preg_match('/^.._..$/', $language->language): return $language->language; default: return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); } }
/** * Get all the Languages from database. * * @access public * @static * * @return array self::languages - array reference of all languages * */ public static function &languages() { require_once 'CRM/Core/I18n/PseudoConstant.php'; return CRM_Core_I18n_PseudoConstant::languages(); }
/** * Is the language written "right-to-left"? * * @param $language * Language (for example 'en_US', or 'fr_CA'). * * @return Bool * True if it is an RTL language. */ public static function isLanguageRTL($language) { $rtl = CRM_Core_I18n_PseudoConstant::getRTLlanguages(); $short = CRM_Core_I18n_PseudoConstant::shortForLong($language); return in_array($short, $rtl); }
$databaseConfig = array("server" => "localhost", "username" => "civicrm", "password" => "", "database" => "civicrm"); } if ($installType == 'drupal') { // Load drupal database config if (isset($_REQUEST['drupal'])) { $drupalConfig = $_REQUEST['drupal']; } else { $drupalConfig = array("server" => "localhost", "username" => "drupal", "password" => "", "database" => "drupal"); } } $loadGenerated = 0; if (isset($_REQUEST['loadGenerated'])) { $loadGenerated = 1; } require_once "{$crmPath}/CRM/Core/I18n/PseudoConstant.php"; $langs =& CRM_Core_I18n_PseudoConstant::languages(); foreach ($langs as $locale => $_) { if ($locale == 'en_US') { continue; } if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, array($crmPath, 'sql', "civicrm_data.{$locale}.mysql")))) { unset($langs[$locale]); } } $seedLanguage = 'en_US'; if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) { $seedLanguage = $_REQUEST['seedLanguage']; } if ($installType == 'drupal') { global $cmsPath; $cmsPath = dirname(dirname(dirname(dirname($crmPath))));
/** * Get the locale set in the hosting CMS * @return string with the locale or null for none */ static function getUFLocale() { // an array of xx_YY locales static $locales = null; if ($locales === null) { require_once 'CRM/Core/I18n/PseudoConstant.php'; $locales = array_keys(CRM_Core_I18n_PseudoConstant::languages()); sort($locales); } // an array of xx → xx_YY mappings (naïve, as pt_PT will trump pt_BR // and en_US will trump other English entries, but works in our case) static $prefixes = null; if ($prefixes === null) { foreach ($locales as $locale) { $prefixes[substr($locale, 0, 2)] = $locale; } } // return CiviCRM locale that either matches Drupal’s xx_YY // or begins with Drupal’s xx (so Drupal’s pt_BR will return // CiviCRM’s pt_BR, while Drupal’s pt will return CiviCRM’s pt_PT) global $language; if (in_array($language->language, $locales)) { return $language->language; } elseif (in_array($language->language, array_keys($prefixes))) { return $prefixes[$language->language]; } else { return null; } }
/** * Get all the Languages from database. * * @access public * @static * * @return array self::languages - array reference of all languages * */ public static function &languages() { return CRM_Core_I18n_PseudoConstant::languages(); }