0

Hy all. I have a question: I added a file-upload plugin to my site (this one:http://danholloran.me/WPMultiFileUploader/) and it works great. I want to translate the upload button's text, (I'm using for translation Polylang) and for that I need to add the following code to make the plugin translate the string from the .mo file:

<?php echo __('Upload File(s)'); ?>

to the plugins minified .js file

text:{uploadButton:"Upload File(s)"}

I searched on the net and found out that in a .js file the php script wont run, so how can i replace the text from the .js file with my php code to make it work?

The .js file: http://we.tl/HDT0yiVSq1

(its a minified file unfortunately, but the text we search for is on the end of the file)

elodpal
  • 47
  • 1
  • 1
  • 5
  • Possible duplicate of [How to embed php in javascript?](http://stackoverflow.com/questions/3352576/how-to-embed-php-in-javascript) – Naruto Nov 09 '15 at 10:57

1 Answers1

0

You can use $.get().

So:

$.get("phpfile.php", function(data){
    // initialize your upload and then use instead of "Upload File(s)" the variable data.
    // so uploadButton: data
});
L Ja
  • 1,384
  • 1
  • 11
  • 22
  • First of all thanks for the answer; I have created a file (in the same folder where the .js file is) called buttontitle.php and created a function inside like this: `function buttontitle() { } ` Now i went back in the .js file and added the line like this: `uploadButton:$get("buttontitle.php, function buttontitle(); )` I'm not sure if i did it correctly, but its not working :( – elodpal Nov 09 '15 at 11:21
  • You don't need to create a function. You just have to echo the value you want on your button. What you are doing now is calling a PHP function in JavaScript which doesn't work (PHP is server sided and JavaScript is client sided). In JavaScript, you can use function(){} to let it do stuff without actually creating a function. It basically just executes whatever is inbetween the function() tags. Could you add the whole fileuploader script to your opening-post (the one where you basically create and initialize it)? – L Ja Nov 09 '15 at 11:27