Pregunta

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.

¿Fue útil?

Solución

$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
}

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top