我想做的是:
在 config/routes.rb 中
resources :posts
在 config/locale/en.yml 中
en:
resources:
posts: "posts"
new: "new"
edit: "edit"
在 config/locale/tr.yml
tr:
resources:
posts: "yazilar"
new: "yeni"
edit: "duzenle"
得到
I18n.locale = :en
edit_post_path(3) #=> /posts/3/edit
I18n.locale = :tr
edit_post_path(3) #=> /yazilar/3/duzenle
我还希望 Rails 随时匹配这些路由中的任何一个,并在 params 哈希中传递相关的语言环境,这样当我导航到 /yazilar
时,请求应该被路由到 posts#index
操作,在 params 哈希中带有 :tr
语言环境。
有什么简单或复杂的方法吗?
最佳答案
还有 Guillaume Luccisano 的 i18n_routing 插件,位于
http://github.com/kwi/i18n_routing解决了大部分问题
但是,它目前缺少对 ../new
和 ../edit
等 Action 名称的翻译。不过,Guillaume 说他会“很快”实现。
更新:i18n_routing 中已实现 Action 名称翻译。谢谢纪尧姆。 :)
关于ruby-on-rails - 如何使 Rails 3 路由器使用本地化文件本地化 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601283/