Translation function in Javascript files


(sergio samoilovich) #1

I am using a *.js file with an Alert, but I cannot include the Translate function inside, because it gives error without any message. I tried:

alert(xl("Please choose bed"));
alert(xls("Please choose bed"));

Any suggestion?


(Jerry P) #2

Your’re trying to call a PHP function (xl) inside a JS function. echo the text with:

let alertMsg = <?php echo xlj("my message"); ?>

(Brady Miller) #3

hi @sergiors ,

Two options:

  1. Create a js variable before you import the js with the translation(s). Example here:
    openemr/main.php at master · openemr/openemr · GitHub

  2. Include the js file as a php file instead (and place a .php at end of it), which then means can include php in it. Example here:
    openemr/jquery-datetimepicker-2-5-4.js.php at master · openemr/openemr · GitHub

-brady