开发者

how to get joomla languages list

i need to get languages list to all languages installed in my joomla site to use the list in drop down list.

$lg = &JFactory::getLanguage();开发者_运维百科
foreach ($lg->getKnownLanguages() as $l)
echo $l->getName() . ', ';

what shall i do?


As you can see in ContentLanguage field type documentation:

http://docs.joomla.org/ContentLanguage_form_field_type

$languages = JLanguage::getKnownLanguages();

More info here:

https://stackoverflow.com/a/26977901/634177


Firsty DB Query:

$db =& JFactory::getDbo();
$db->setQuery(
    'SELECT sef, title_native' .
    ' FROM #__languages' .
    ' ORDER BY sef ASC'
);
$options = $db->loadObjectList();
$selected = "en_GB"

Secondly in your layout:

echo JHtml::_('select.options', $options, 'sef', 'title_native', $selected);

This will output HTML <select> tag with "English" selected by default

EDIT: Should you want to use it in JForm (Joomla > 1.6) there is a field type called "contentlanguage"

<field name="languages" type="contentlanguage" />


You also can use appropriate class of com_languages

JLoader::register('LanguagesModelInstalled', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_languages'.DS.'models'.DS.'installed.php');
$lang = new LanguagesModelInstalled();
$current_languages = $lang ->getData();

And then create the select list from retrieved data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜