/**
  * Fetch all active languages
  *
  * @return mixed
  */
 public function fetchAll()
 {
     if (static::$languages === null) {
         static::$languages = $this->driver()->fetchAll();
         static::$languages = array_map(function ($language) {
             return new Locale($language);
         }, static::$languages);
     }
     return static::$languages;
 }
Exemple #2
0
 /**
  * Create a new language instance, based on the language code provided.
  *
  * @param string $code
  * @throws UnsupportedLanguageException
  */
 public function __construct($code)
 {
     if (!isset(static::$languages)) {
         static::$languages = Config::get('shift.languages');
     }
     if (!array_key_exists($code, static::$languages)) {
         throw new UnsupportedLanguageException($code);
     }
     $this->code = $code;
     $this->language = static::$languages[$code];
 }
Exemple #3
0
 /**
  * Gets a list of the active languages that have been configured
  */
 public static function languages()
 {
     if (static::$languages !== null) {
         return static::$languages;
     }
     $languages = \CMF\Model\Language::select('item.id, item.code, item.top_level_domain, update_from.code AS update_from_code', 'item', 'item.code')->leftJoin('item.update_from', 'update_from')->orderBy('item.pos', 'ASC')->getQuery();
     // Set the query hint if multi lingual!
     if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
         $languages->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     }
     return static::$languages = $languages->getArrayResult();
 }
 /**
  * Resolve language using HTTP_ACCEPT_LANGUAGE header
  * which is used mostly by API requests
  *
  * @return array|null
  */
 private function resolveHeader()
 {
     if (null === static::$languages) {
         $httpLanguages = $this->request->server(config('localizer.request.header', 'HTTP_ACCEPT_LANGUAGE'));
         if (empty($httpLanguages)) {
             static::$languages = [];
         } else {
             $accepted = preg_split('/,\\s*/', $httpLanguages);
             static::$languages = empty($languages = $this->buildCollection($accepted, $languages = [])) ? null : array_keys($languages)[0];
         }
     }
     return static::$languages;
 }
 /**
  * Return list of all active languages
  *
  * @return array
  */
 protected function getActiveLanguages()
 {
     $list = static::$languages;
     if (null === $list) {
         $list = array();
         foreach (\XLite\Core\Database::getRepo('\\XLite\\Model\\Language')->findActiveLanguages() as $language) {
             if ($this->isActiveLanguage($language)) {
                 $list[] = $language;
             }
         }
         static::$languages = $list;
     }
     return $list;
 }
Exemple #6
0
 /**
  * Gets a list of the active languages that have been configured
  */
 public static function languages()
 {
     if (static::$languages !== null) {
         return static::$languages;
     }
     if (!static::$lang_enabled) {
         return static::$languages = array(\Lang::get_lang());
     }
     try {
         return static::$languages = \DB::query("SELECT id, code, top_level_domain FROM languages WHERE visible = 1 ORDER BY pos ASC")->execute()->as_array();
     } catch (\Exception $e) {
         return array(array('id' => 0, 'code' => \Lang::get_lang(), 'top_level_domain' => ''));
     }
 }
 /**
  * Load all languages from the language directory.
  */
 public static function load()
 {
     // Get all language files
     $files = static::getLanguageFiles();
     // Define a list to put the loaded languages in
     $languages = array();
     // Load each language and add it to the list
     foreach ($files as $file) {
         $languages[] = new Language($file);
     }
     // Set the list of loaded languages
     static::$languages = $languages;
 }
 public function __construct()
 {
     if (!isset(static::$languages)) {
         static::$languages = $this->hydrateCollection(Config::get('shift.languages', []));
     }
 }
Exemple #9
0
 /**
  * Set the accepted languages
  *
  * @access	protected
  * @return	void
  */
 protected static function _set_languages()
 {
     if (empty(static::$languages) and $language = \Input::server('http_accept_language')) {
         $languages = preg_replace('/(;q=[0-9\\.]+)/i', '', strtolower(trim($language)));
         static::$languages = explode(',', $languages);
     }
     empty(static::$languages) and static::$languages = array('Undefined');
 }