0

I have a Highcharts graph and there's text inside. How can I change this text according to the language selected ? Here is my code :

var chart;
chart = new Highcharts.Chart({
(...)
    subtitle: {
        text: document.ontouchstart === undefined ?
        'Click and drag in the plot area to zoom in' :
        'Drag your finger over the plot to zoom in'
        }
(...)

My en.yml file looks like :

en:
   actions:
      zoom: "Click and drag in the plot area to zoom in"

I have tried

t("actions.zoom")

and

<% t "actions.zoom" %>

But they are not working inside the Ajax. How should I do ?

4

2 回答 2

0

无论您的文件被称为什么,只需添加erb扩展名:

my_file.js.erb

    subtitle: {
    text: document.ontouchstart === undefined ?
      <%= t "actions.zoom" %> : 'something something'
    }

另请注意,<%=打印结果,<%不会。

编辑:这假设您正在使用 rails 资产管道,如果您不是,它将更加复杂。

于 2013-03-19T20:47:51.617 回答
0

尝试使用i18n-js gem 将 Rails 传递I18n.locale到您的 javascript 文件中。

于 2013-03-20T12:57:30.330 回答