Exemple #1
0
 /**
  * Return languages available in this instance of CiviCRM.
  *
  * @param bool $justEnabled
  *   whether to return all languages or just the enabled ones.
  *
  * @return array
  *   Array of code/language name mappings
  */
 public static function languages($justEnabled = FALSE)
 {
     static $all = NULL;
     static $enabled = NULL;
     if (!$all) {
         $all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
         // check which ones are available; add them to $all if not there already
         $codes = array();
         if (is_dir(CRM_Core_I18n::getResourceDir()) && ($dir = opendir(CRM_Core_I18n::getResourceDir()))) {
             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;
 }
Exemple #2
0
 /**
  * @return array
  */
 public function findLocales()
 {
     require_once 'CRM/Core/Config.php';
     $config = CRM_Core_Config::singleton(FALSE);
     $locales = array();
     $localeDir = CRM_Core_I18n::getResourceDir();
     if (file_exists($localeDir)) {
         $locales = preg_grep('/^[a-z][a-z]_[A-Z][A-Z]$/', scandir($localeDir));
     }
     $localesMask = getenv('CIVICRM_LOCALES');
     if (!empty($localesMask)) {
         $mask = explode(',', $localesMask);
         $locales = array_intersect($locales, $mask);
     }
     if (!in_array('en_US', $locales)) {
         array_unshift($locales, 'en_US');
     }
     return $locales;
 }