Вопрос

I know that we can get current language in Joomla by

$lang = JFactory::getLanguage();
echo 'Current language is: ' . $lang->getName();

now I want to know "How to get direction of current language in joomla 2.5?"

I try to use

dir="<?php echo $this->direction; ?>"

but It's not work and it returns empty string.

Это было полезно?

Решение

$this->direction can only be used on templates and there is no JLanguage property to get the actual value ltr or rtl. So you could do something along the lines if this instead:

$lang = JFactory::getLanguage();
$dir = $lang->get('rtl');

if($dir == 0) {
    //do soemthing
}
else {
    //do something else
}

Другие советы

You may inspect your current language metadata and check the rtl property

$meta = JFactory::getLanguage()->getMetadata(JFactory::getLanguage()->getTag());
echo $meta['rtl'];

If $meta['rtl'] is 1 you are using a right to left language.

Pls. note that $this->direction is used on templates.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top