Merge pull request #10588 from JMAConsulting/CRM-20793
[civicrm-core.git] / CRM / Core / I18n.php
index de62c3e5cbe874f6a156122ab9249bc309c0d490..9e20536dfe3854345203734dca639356d89a4872 100644 (file)
@@ -97,7 +97,11 @@ class CRM_Core_I18n {
     return $this->_nativegettext;
   }
 
-
+  /**
+   * Set native locale for getText.
+   *
+   * @param string $locale
+   */
   protected function setNativeGettextLocale($locale) {
 
     $locale .= '.utf8';
@@ -117,6 +121,11 @@ class CRM_Core_I18n {
 
   }
 
+  /**
+   * Set getText locale.
+   *
+   * @param string $locale
+   */
   protected function setPhpGettextLocale($locale) {
 
     // we support both the old file hierarchy format and the new:
@@ -138,7 +147,6 @@ class CRM_Core_I18n {
 
   }
 
-
   /**
    * Return languages available in this instance of CiviCRM.
    *
@@ -155,6 +163,14 @@ class CRM_Core_I18n {
     if (!$all) {
       $all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
 
+      // get labels
+      $rows = array();
+      $labels = array();
+      CRM_Core_OptionValue::getValues(array('name' => 'languages'), $rows);
+      foreach ($rows as $id => $row) {
+        $labels[$row['name']] = $row['label'];
+      }
+
       // 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())) {
@@ -162,7 +178,7 @@ class CRM_Core_I18n {
           if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
             $codes[] = $filename;
             if (!isset($all[$filename])) {
-              $all[$filename] = $filename;
+              $all[$filename] = $labels[$filename];
             }
           }
         }
@@ -178,6 +194,8 @@ class CRM_Core_I18n {
           unset($all[$code]);
         }
       }
+
+      ksort($all);
     }
 
     if ($enabled === NULL) {
@@ -221,6 +239,11 @@ class CRM_Core_I18n {
     return strtr($str, $tr);
   }
 
+  /**
+   * Get the directory for l10n resources.
+   *
+   * @return string
+   */
   public static function getResourceDir() {
     static $dir = NULL;
     if ($dir === NULL) {