In my custom component I do a lot of JavaScript validation for each view. The validation throws various error messages and those messages are configured inside the language file en-GB.com_mycomp.ini and I write the JavaScript inclusion as below inside a PHP file.
in the view.html.php
require_once JPATH_COMPONENT.'/views/send/tmpl/validation.php';
validation.php
function doValidation(){
// do some checking
alert("<?php echo JText::_( 'VALIDATION_ERROR'); ?>");
}
Doing by this way the JavaScript code is rendered along with the PHP file.
What I was thinking is to use the standard $document->addScript(...)
function so that the .js files are loaded as part of header. Since I got the inline PHP statements I'm not able to do it like that.
Note: I do not want to hard code the error messages inside the .js file because the component is language independent.
I need some direction regarding the best way of including JavaScript code that has language specific values.