Oh! Good question!
I don’t have such a good answer 🙁
The only thing I’ve seen is the suggestion to use wp_localize_script(), which is fine to a point. If your JS has extensive translation needs, passing every string through this way can get tedious. If this technique starts to appear onerous, I think a dynamic JS file could work. This is a PHP file that outputs JS instead of HTML, so you can use the familiar i18n functions to deal with translating strings. Properly setting this up is a bit tricky.
There appears to be a more formal dynamic JS framework used in core code, though I can’t find an example right now. I see it on occasion, but I don’t know anymore about it, sorry.
@bcworkz – Would you be referring to BackBoneJS which is what manages the media popups and such? I’ve yet to fully understand BackBone but from what I DO understand is it is sort of an MVC framework for JavaScript whereas most of your ‘templating’ you do in HTML and PHP.
Idk if that would fit your scenario David and it’s got a learning curve, but from my perspective, if I have a large JavaScript project BackBone would be the way to go.
If it’s not a huge project localize_script will be the way to go. Some fairly large libraries use it already, it’s just a matter of discipline to put together the array.
BackboneJS – Yes, that’s it! Thanks Jerry.
Thinking a bit more about this, if the only issue is translating JS strings, even with a large project, passing them through localize script wouldn’t be a big problem as long as you use logic to only localize strings that might actually be used on the page. Passing every possible string of a project amounting into the hundreds wouldn’t be good, but how many strings could any particular page use?
I’m now inclined to believe anyone working on a project too big for wp_localize_script() wouldn’t have much use for any of my feeble advice 🙂