How do you handle translations in JavaScript?

I’m curious how others have dealt with JavaScript-generated text on multilingual sites. This may not be explicitly a Yii question but my most recent experience with this was with Yii, so here we are! :)

As we know, one can use the Yii::t() method to translate text in PHP on a multilingual website, provided the text’s translation is stored of course. My question would be, is there a ‘correct’ or ‘standard’ way to translate text for JavaScript? Since JavaScript obviously doesn’t have access to Yii’s Yii::t() method. What I’ve been doing is in the occasional cases where the text needs to be set directly in JavaScript, I’ll echo a hidden input to the page with the translated text as the value.

This doesn’t really present any issues, so this post is mainly just for curiosity’s sake - how do others handle translated strings for JavaScript?

That depends on what kind of javascript you are using.

That right there, is why you ask questions! :) May have just found a better way to handle translations!