本文整理汇总了PHP中JLanguage::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP JLanguage::getMetadata方法的具体用法?PHP JLanguage::getMetadata怎么用?PHP JLanguage::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JLanguage
的用法示例。
在下文中一共展示了JLanguage::getMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* Gets a list of available languages
*
* @param \Joomla\Registry\Registry &$params module params
*
* @return array
*/
public static function getList(&$params)
{
$user = JFactory::getUser();
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages();
$app = JFactory::getApplication();
$menu = $app->getMenu();
// Get menu home items
$homes = array();
$homes['*'] = $menu->getDefault('*');
foreach ($languages as $item) {
$default = $menu->getDefault($item->lang_code);
if ($default && $default->language == $item->lang_code) {
$homes[$item->lang_code] = $default;
}
}
// Load associations
$assoc = JLanguageAssociations::isEnabled();
if ($assoc) {
$active = $menu->getActive();
if ($active) {
$associations = MenusHelper::getAssociations($active->id);
}
// Load component associations
$class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation';
JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php');
if (class_exists($class) && is_callable(array($class, 'getAssociations'))) {
$cassociations = call_user_func(array($class, 'getAssociations'));
}
}
$levels = $user->getAuthorisedViewLevels();
$sitelangs = MultilangstatusHelper::getSitelangs();
$multilang = JLanguageMultilang::isEnabled();
// Filter allowed languages
foreach ($languages as $i => &$language) {
// Do not display language without frontend UI
if (!array_key_exists($language->lang_code, $sitelangs)) {
unset($languages[$i]);
} elseif (!isset($homes[$language->lang_code])) {
unset($languages[$i]);
} elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
unset($languages[$i]);
} else {
$language->active = $language->lang_code == $lang->getTag();
// Fetch language rtl
// If loaded language get from current JLanguage metadata
if ($language->active) {
$language->rtl = $lang->isRtl();
} else {
$languageMetadata = JLanguage::getMetadata($language->lang_code);
$language->rtl = $languageMetadata['rtl'];
}
if ($multilang) {
if (isset($cassociations[$language->lang_code])) {
$language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
} elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
$itemid = $associations[$language->lang_code];
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
if ($language->active) {
$language->link = JUri::getInstance()->toString(array('path', 'query'));
} else {
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
}
}
} else {
$language->link = JRoute::_('&Itemid=' . $homes['*']->id);
}
}
}
return $languages;
}
示例2: testGetMetadata
/**
* @todo Implement testGetMetadata().
*/
public function testGetMetadata()
{
// This method get language metadata
$l1 = 'en-GB';
$l2 = 'es-ES';
// In this case, returns array with default language
// - same operation of get method with metadata property
$option1 = array('name' => 'English (United Kingdom)', 'tag' => 'en-GB', 'rtl' => 0, 'locale' => 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, uk, united kingdom, united-kingdom', 'firstDay' => 0);
$option2 = array('name' => 'XXTestLang', 'tag' => 'xx-XX', 'rtl' => 0, 'locale' => 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, uk, united kingdom, united-kingdom', 'firstDay' => 0);
$lang = new JLanguage('');
// language exists, returns array with values
$this->assertThat($option1, $this->equalTo($lang->getMetadata($l1)), 'Line: ' . __LINE__);
// language doesn't exist, retun NULL
$this->assertNull($lang->getMetadata($l2));
}