开发者

Translations in the Js file RAILS

开发者 https://www.devze.com 2023-01-22 05:17 出处:网络
How to add translations in .js file I am having a line like $(display_charsleft_id).innerHTML = var1 + \" characters l开发者_运维百科eft!\";

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消