Translations in the Js file RAILS
How to add translations in .js file
I am having a line like
$(display_charsleft_id).innerHTML = var1 + " characters l开发者_运维百科eft!";
I amtrying to add translations by (display_charsleft_id).innerHTML = var1 + <%=t :str_chars_left%>;
but this shows only the translation value and not appending the value of var1 str_chars_left: "characters left!"
I have no experience with Rails, but from your question, I think
<%=t :str_chars_left%>
should be <%= t:str_chars_left%>
. However it may not change anything.
How we usually do JS i18n here, is we create some Array populated on the server and then assign translations to correct variable:
Translations = new Array();
Translation['chars_left'] = 'something written by server side';
.
.
.
(display_charsleft_id).innerHTML = var1 + Translation['chars_left'];
But unfortunately I cannot give you exact example.
You can also think of better support for Localization by providing placeholders like in this question.
精彩评论