Activeadmin 资源名称
这是一个初学者的问题,但我到处搜索过,似乎无法解决。
我正在使用 Rails 和 ActiveAdmin,并且已设置国际化以使用我的 es.yml
区域设置。
到目前为止,一切都很好。管理界面以西班牙语显示得很好,错误消息、日期等也是如此。甚至表单也能获取模型的名称和属性(因此 formattastic 可以正常翻译)。我只有一种语言环境 - 西班牙语:
config/initializers/i18n.rb
#encoding: utf-8
I18n.default_locale = :es
LANGUAGES = [
[ 'Español', 'es' ]
]
不过,我在 ActiveAdmin 界面中翻译资源名称时遇到问题。例如,在页面顶部,它显示“用户”、“估计”等,而不是“Usuarios”、“Cotizaciones”。
我可以通过注册这样的类来解决这个问题:
ActiveAdmin.register User, :as => “usuario”做 ... 结束
,但随后我得到 admin_usuarios_path
、admin_usuarios_url
、/admin/usuarios
等,我觉得这些非常丑陋。我宁愿在内部使用英语。 active_admin/resource/naming
的 ActiveAdmin 源代码表示它应该获取模型的 human_name
,它是从本地化文件中正确读取的:(
在控制台中)
User.model_name.human.titleize
=> "Usuario"
那么为什么菜单栏上不显示“Usuario”,而是显示“User”吗?我在这里有点困惑。我一定错过了一些非常简单的东西。
提前致谢!
凯尔
this is a bit of a beginner's question, but I've searched everywhere and can't seem to solve it.
I'm using Rails and ActiveAdmin, and I've set up internationalization to use my es.yml
locale.
So far so good. The admin interface shows up nicely in Spanish, as do error messages, dates, etc. Even the forms pick up the names of the models and the attributes (so formtastic is getting the translations OK). I have only one locale - Spanish:
config/initializers/i18n.rb
#encoding: utf-8
I18n.default_locale = :es
LANGUAGES = [
[ 'Español', 'es' ]
]
I have a problem with getting the resource names translated in the ActiveAdmin interface, though. At the top of the page, for example, it says "Users", "Estimates", etc. instead of "Usuarios", "Cotizaciones".
I can solve this by registering the classes like this:
ActiveAdmin.register User, :as => "usuario" do
...
end
but then I get admin_usuarios_path
, admin_usuarios_url
, /admin/usuarios
etc. which I find very very ugly. I would rather use English internally. The ActiveAdmin source for active_admin/resource/naming
says it should be picking up the model's human_name
, which is correctly being read from the localization file:
(in the console)
User.model_name.human.titleize
=> "Usuario"
So why does "Usuario" not show up on the menu bar, but "User"? I'm a bit mystified here. I must be missing something really simple.
Thanks in advance!
Kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如本期所述:https://github.com/gregbell/active_admin/issues/434
你的初始化程序应该如下所示:
config/initializers/i18n.rb
Active Admin 对 i18n 的支持目前还不是很完整也不是很稳定(v0.3.4) 但在接下来的几个版本中应该会变得更好。
As mentioned in this issue : https://github.com/gregbell/active_admin/issues/434
Your initializer should look like this:
config/initializers/i18n.rb
Active Admin's support for i18n is not very complete nor stable at present (v0.3.4) but it should get better in the next few releases.
控制器中必须有某些内容覆盖默认区域设置。如果设置了区域设置参数,那么它将成为会话的默认参数。您可以尝试清除 cookie,但不知何故,区域设置被设置为另一个值,您可以尝试通过向您的 URL 添加 GET 参数来强制将其设置为西班牙语,但其他发布参数可能会覆盖它。
您可以通过向 URL 添加参数来设置区域设置参数。尝试类似
www.myapp.com/controller/action?locale=es
或www.myapp.com/controller/action?parameters_from_active_admin=foo&locale=es
如果是查看 Rails 控制台并查看提供给应用程序的参数对您不起作用吗?是否有区域设置参数设置为 es 以外的其他值?
有关详细信息,请参阅 Rails i18n 指南。
There must be something in the controller overriding the default locale. If a locale parameter is set then it becomes the default for the session. You could try clearing your cookies, however somehow the locale was set to another value you can try forcing it to Spanish by adding a GET prarmeter to your URL however other post parameters may override it.
You can set the locale parameter by adding a parameter to the URL. Try something like
www.myapp.com/controller/action?locale=es
orwww.myapp.com/controller/action?parameters_from_active_admin=foo&locale=es
If that dosnt work for you take a look at the Rails console and look at the parameters provided to the application? Is there a locale parameter set to something other than es?
For more information see the Rails i18n guide.