How can I make a Rails 3 router localize URLs using localization files?

What I would like to do is:

in config / routes.rb

resources :posts

in config / locale / en.yml

en:
  resources:
    posts: "posts"
    new: "new"
    edit: "edit"

in config / locale / tr.yml

tr:
  resources:
    posts: "yazilar"
    new: "yeni"
    edit: "duzenle"

and get

I18n.locale = :en
edit_post_path(3) #=> /posts/3/edit

I18n.locale = :tr
edit_post_path(3) #=> /yazilar/3/duzenle

I would also like Rails to match any of these routes at any time and pass the associated locale in the params hash, so when I go to /yazilar, the request should be redirected to the action posts#indexusing :trlocale in the params hash.

Any simple or complicated way to do this?

+3
source share
3 answers

i18n_routing Guillaume Luccisano : http://github.com/kwi/i18n_routing, , ../new ../edit. , "", .

: i18n_routing. .:)

+7

translate_routes Raul Murciano , :

http://github.com/raul/translate_routes

It only works for Rails 2.3.x, as far as I know. But at least you can either get some ideas, or even unlock the plugin and make it work on Rails 3 yourself.

0
source

Source: https://habr.com/ru/post/1740341/


All Articles