예제 #1
0
 /**
  * Get language options for in desired language. Useful to build a Select widget.
  *
  * @param array|string|int $selected - An array of language codes to mark as selected
  * @param array            $pool     (optional) - An array of language codes to be displayed. Leave null to show all.
  * @param string           $lang     (optional) - Get language names for this language.
  *
  * @return array
  */
 public static function findOptions($selected = array(), $pool = null, $lang = null)
 {
     if (!is_array($selected)) {
         $selected = array($selected);
     }
     $native = Languages::all()->listAll('name');
     if (is_array($pool)) {
         $native = array_intersect_key($native, array_flip($pool));
     }
     if ($lang === null) {
         $lang = Lang::get();
     }
     // try to get languages in author language
     $local = Languages::local()->listAll($lang);
     // if languages not found, use english ones
     if ($local === false) {
         $local = Languages::local()->listAll();
     }
     $options = array();
     foreach ($native as $code => $info) {
         $options[] = array($code, in_array($code, $selected), sprintf("[%s] %s%s", strtoupper($code), isset($local[$code]) ? $local[$code] . ' || ' : '', $info['name']));
     }
     return $options;
 }
 public static function getAllLangs($lc = null)
 {
     if ($lc === null) {
         $lc = self::getLangCode();
     }
     if (!($languages = Languages::local()->listAll($lc))) {
         $languages = Languages::local()->listAll();
     }
     return $languages;
 }