views:

10

answers:

1

Hi , How to add translations in .js file

I am having a line like

$(display_charsleft_id).innerHTML = var1 + " characters left!";

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!"

A: 

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.

Paweł Dyda