10 defined(
'JPATH_PLATFORM') or die;
33 public static function createLanguageList($actualLanguage, $basePath = JPATH_BASE, $caching =
false, $installed =
false)
43 $query = $db->getQuery(
true)
45 ->from(
'#__extensions')
46 ->where(
'type=' . $db->quote(
'language'))
49 ->where(
'client_id=' . ($basePath == JPATH_ADMINISTRATOR ? 1 : 0));
50 $db->setQuery($query);
51 $installed_languages = $db->loadObjectList(
'element');
54 foreach ($langs as $lang => $metadata)
56 if (!$installed || array_key_exists($lang, $installed_languages))
60 $option[
'text'] = $metadata[
'name'];
61 $option[
'value'] = $lang;
63 if ($lang == $actualLanguage)
65 $option[
'selected'] =
'selected="selected"';
82 public static function detectLanguage()
84 if (isset($_SERVER[
'HTTP_ACCEPT_LANGUAGE']))
86 $browserLangs = explode(
',', $_SERVER[
'HTTP_ACCEPT_LANGUAGE']);
87 $systemLangs = self::getLanguages();
89 foreach ($browserLangs as $browserLang)
92 $browserLang = substr($browserLang, 0, strcspn($browserLang,
';'));
93 $primary_browserLang = substr($browserLang, 0, 2);
95 foreach ($systemLangs as $systemLang)
98 $Jinstall_lang = $systemLang->lang_code;
100 if (strlen($Jinstall_lang) < 6)
102 if (strtolower($browserLang) == strtolower(substr($systemLang->lang_code, 0, strlen($browserLang))))
104 return $systemLang->lang_code;
106 elseif ($primary_browserLang == substr($systemLang->lang_code, 0, 2))
108 $primaryDetectedLang = $systemLang->lang_code;
113 if (isset($primaryDetectedLang))
115 return $primaryDetectedLang;
132 public static function getLanguages($key =
'default')
136 if (empty($languages))
141 $languages[$key] = array();
144 foreach ($knownLangs as $metadata)
148 $obj->lang_code = $metadata[
'tag'];
149 $languages[$key][] = $obj;
156 if (!$languages = $cache->get(
'languages'))
159 $query = $db->getQuery(
true)
161 ->from(
'#__languages')
162 ->where(
'published=1')
163 ->order(
'ordering ASC');
164 $db->setQuery($query);
166 $languages[
'default'] = $db->loadObjectList();
167 $languages[
'sef'] = array();
168 $languages[
'lang_code'] = array();
170 if (isset($languages[
'default'][0]))
172 foreach ($languages[
'default'] as $lang)
174 $languages[
'sef'][$lang->sef] = $lang;
175 $languages[
'lang_code'][$lang->lang_code] = $lang;
179 $cache->store($languages,
'languages');
184 return $languages[$key];