活动管理 +国际化
我已将 active_admin 更新到版本 0.3.0 以实现国际化。但我有问题。
我用 activeadmin 部分更新了我的 pl.yml 文件,如下所示:
pl:
active_admin:
blank_slate:
content: "Nie ma jeszcze rekordów."
link: "Nowy"
dashboard: "Dashboard2"
view: "Podgląd"
这不起作用,所以我尝试将此代码添加到我的 application.rb:
config.before_configuration do
I18n.locale = :pl
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '.{rb,yml}')]
I18n.reload!
end
现在国际化似乎可以在开发环境中工作,但我在其他环境中仍然存在问题环境。我的仪表板有问题:键。简而言之,通常情况下,当 I18n 找不到密钥时,它会输入 key: 大写字母,在本例中它将是“Dashboard”。但就我而言,我有这样的事情:
开发:
制作:
有人遇到同样的问题吗?我是做错了什么,还是这是一个 activeadmin 错误?有什么解决办法吗?
I've updated active_admin to version 0.3.0 to get internationalization working. But I have problems with it.
I have my pl.yml file updated with activeadmin section which looks like this:
pl:
active_admin:
blank_slate:
content: "Nie ma jeszcze rekordów."
link: "Nowy"
dashboard: "Dashboard2"
view: "Podgląd"
This didn't work, so I tried adding this code to my application.rb:
config.before_configuration do
I18n.locale = :pl
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '.{rb,yml}')]
I18n.reload!
end
Now internationalization seems to work in development environment, but I still have problems in other environments. I have problem with dashboard: key. Normally, in short, when I18n doesn't find the key it puts key: with capital letter, in this example it would be "Dashboard". But in my case i have something like this:
Develoment:
Production:
Is there anyone who had the same problem? I'm I doing something wrong, or is this an activeadmin bug? Any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也有同样的问题。我需要这样做才能使其在生产和开发中都能工作:
不是很漂亮,但可能是由 Rails 中的错误引起的。
I had the same problem. I needed to do this to be able to get it to work in both production and development:
Not very pretty, but probably caused by a bug in Rails.
在应用程序.rb中
in application.rb
关键原因可能是:Rails 从最终用户的浏览器中选择了区域设置,而不是您的配置文件。例如,一个日本人正在使用 English 浏览器访问您的网站,那么您的 Rails 应用程序将向他显示“英语”文本,但不会显示您希望显示的日语。
根据Rails i18n文档:http://guides.rubyonrails.org/i18n.html,你首先必须:
编辑 config/application.rb 以设置 default_locale
编辑您的 app/controllers/application_controller.rb,添加 before_filter
在这种情况下,你应该将“cn”作为默认区域设置。
通过将这些代码行添加到您的任何页面来检查您的视图页面。例如
输出结果应如下所示:
并且您的 Rails 应用程序应该按您的预期运行。
The key reason maybe caused by : Rails chose the locale from enduser's browser, but not your config file. e.g. a Japanese is visiting your website with his browser using English , then your Rails app will show him the "English" text, but not Japanese that you want it to show.
According to Rails i18n document: http://guides.rubyonrails.org/i18n.html, you have to first of all:
edit config/application.rb to set the default_locale
edit your app/controllers/application_controller.rb, to add a before_filter
in this case, you should have the "cn" as the default locale.
check your view page, by adding these line of code to any of your page. e.g.
the output result should look like:
and your Rails application should work as you expect.
似乎可行的另一种方法是使用以下内容创建初始化程序:
An alternative that seems to work is creating an initializer with the following: