Javascript and translation
Notice: This thread is very old.
- Attanon
- Member | 25
Hi. I have a javascript with hide and show function for my menu. And I want to add translation for this script.
Is there any chance use latte macro {_ } in javascript files. I know that i can use it in script tags in html file. But I don't want to have a lot of lines in latte file.
Can anyone help me with that? Suggest a solutions.
Thanks
- h4kuna
- Backer | 740
Hi,
if you have macro for translate in javascript file (*.js) does not work.
The way is save message to data attribute in html and via javascript load it.
<a n:href="delete!" data-confirm-message="{_'Do you want realy to delete this file?'}">delete file</a>
Or if you need more texts. You can use json.
<script id="dictionary" type="text/json">
{
"delete.message" = {_'Delete message'},
"color" = {_'color'}
}
</script>
and load in javascript by
var c = document.getElementById('dictionary');
var dictionary = JSON.parse(c.textContent || c.innerHTML);
console.log(dictionary);
Last edited by h4kuna (2015-07-07 08:40)