Redeem Now
Read More
Read now
Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Translate language Tag in external JavaScript file

    Translate language Tag in external JavaScript file: Joomla CMS is used by people from different countries with different language. Most joomla extension developer need to keep their joomla extension compatible for translation. Joomla support language files for translation string so it’s not a big deal. Again, it’s not like we always use the translation strings in xml(joomla form api xml) and php scripts but sometimes need to use them in Javascript. Adding translation in javascript in joomla is bit tricky.

    Which will give you matching translation in current language. This way you can keep JS and PHP in separate files.

    core.js is play important role to translate language constant.

    Location: YOUR_SITE/media/system/js/

    core.js defines the Joomla namespace for JavaScript functions and also defines the Joomla.JText method.
    Previously this was loaded together with the MooTools framework and it also depended on it.

    Core.js was rewritten to jQuery after 3.4 and thus we can now load it without loading MooTools. That’s what JHtmlBehavior::core() which also can load by JHml::_(‘behavior.framework’)

    As we know joomla component use MVC design pattern so all presentation part of component in view.

    We will follow 3 easy step for better understanding.

    Step 1 :

     Write the translation string in .ini language file as we do always

    Step2 :

    Declare translation string in .php script to add it in a global js object.


    Step 3 :

    In any external js file loaded from joomla you can now use the string as, make sure that you load the js after you load the translation string in step2

    Joomla.JText._(‘COM_CUSTOM_LANGUAGE_TAG’);//where you want display in js file.

    Explain With Code:

    View file

    We can write code in any files of views here I am writing view.html.php of view. I think prepareDocument it is best part of view to write this code.

    JS File

    test.js(external js)//here language tag will be prepend on webkul css class with translated language code


    For any query regarding Joomla virtuemart Extensions and add-ons you can communicate with us at:

    Please visit this link to find more extensions of joomla Webkul Joomla extensions

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again

    Table of Content

    Hide Index