Rails: Internationalization of Javascript Strings?

前端 未结 10 1449
你的背包
你的背包 2020-12-07 10:45

So, we have an existing Rails 2.3.5 app that does not support Internationalization at all. Now, I\'m well familiar with Rails I18n stuff, but we have a LOT of output strings

10条回答
  •  广开言路
    2020-12-07 10:56

    Why not simply this in your Javascript file:

    var a_message = "<%= I18n.t 'my_key' %>"
    

    For this to work, you must add .erb to your Javascript file's extension.

    You might also need to add the following line at the top of your Javascript file if you aren't using ruby >= 2.0.

    <%# encoding: utf-8 %>
    

    See the last comment of the accepted answer in this thread for more info: Encoding issues in javascript files using rails asset pipeline

提交回复
热议问题