How to force a view to load other modules languages into SUGAR.language?

SugarCRMAs you should know each SugarCRM view extends SugarView class which has a nifty method called _displayJavascript()  who is responsible for including all needed JavaScript files.

When it comes to labels, by default, this function only loads current module labels into SUGAR.language.

These labels are acessible through the following command:

SUGAR.language.get('<ModuleName>', 'LBL_<LabelName>');

In order to add support to other module labels to be included, you should override _displayJavascript() method in your modules view, and specify which other modules labels should be included.

// modules/<ModuleName>/views/view.edit.php

require_once 'include/MVC/View/views/view.edit.php';

class <ModuleName>ViewEdit extends ViewEdit
    protected function _displayJavascript()

        if (!$this->_getOption('show_javascript')) {

        $modules = array(

        foreach ($modules as $module) {
            if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $module . '/' . $GLOBALS['current_language'] . '.js')) {
                require_once 'include/language/jsLanguage.php';
                jsLanguage::createModuleStringsCache($module, $GLOBALS['current_language']);
            echo '<script type="text/javascript" src="' . $GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $module . '/' . $GLOBALS['current_language'] . '.js?s=' . $GLOBALS['js_version_key'] . '&c=' . $GLOBALS['sugar_config']['js_custom_version'] . '&j=' . $GLOBALS['sugar_config']['js_lang_version'] . '"></script>';
Facebook Twitter Linkedin Plusone