Beispiel #1
0
 /**
  * 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 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();
 }
Beispiel #3
0
 /**
  * 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;
     }
 }
Beispiel #4
0
    $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 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();
 }