Javascript Translation
Permalink
When we build blocks we use <?php echo t('Text")?> to translate it to the local language.
What about when we are generating things in javascript, how do we return translated strings instead of hard coded language specific strings?
What about when we are generating things in javascript, how do we return translated strings instead of hard coded language specific strings?
I don't know if this addresses your question, but I've managed to sneak a few things past the PRB by using t() in view.php to populate a JS object. An example from
https://www.concrete5.org/marketplace/addons/read-more-trial...
<script> if (typeof(gond_read_more) === "undefined") { var gond_read_more = { errPrefix: "<?php echo $btName.t(' block with id=') ?>", errCrossColumn: "<?php echo t(': attempting to find Top block across layout columns.') ?>", errLevelMismatch: "<?php echo t(': matching Top block is at a different level within the DOM.') ?>", errNoMatch: "<?php echo t(': matching Top block not found.') ?>", errNotInAncestor: "<?php echo t(': couldn\'t locate block within ancestor.') ?>" } } </script>The .js file can access this object and hence its translated members.
This isn't 'generating things in javascript' so may not help you.