1

How to detect the current language of a multilanguage *joomla* website using javascript?

1
  • is there a response object or some sort you can access...I am not sure about joomla...so just thinking if there was a global joomla object on the page..see page source if it can help Commented Mar 6, 2013 at 19:08

3 Answers 3

3

Try such way

<script>
    window.addEvent('domready',function(){
        var lang = document.getElement('html').getProperty('lang');
        console.log(lang)
    })
</script>
Sign up to request clarification or add additional context in comments.

Comments

3

Try this

<?php

            $lang = JFactory::getLanguage();
            $lang_code = $lang->getTag();
            $lang_name = $lang->getName(); 

?>

In Js

<script type="text/javascript">
var language_code = "<?php echo $lang_code;?>";
var language_name = "<?php echo $lang_name ;?>";
console.log("Lang Code"+language_code+"Lang Name"+language_name);
</script>

Hope this may help you..

Comments

2
var lang = document.getElement('html').getProperty('lang');

this code won't work on ie depending on your template, you may have some

<!--[if IE 9 ]> <html prefix="og: http://ogp.me/ns#" lang="en" class="ie9"> <![endif]-->

tags specifying the lang to en.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.