Problem with path_names on Rails 3.1

192 views
Skip to first unread message

Mikhail S. Pobolovets

unread,
Sep 19, 2011, 6:58:43 AM9/19/11
to I18n Routing
Hi,

Does anybody tried to override path_names on Rails 3.1? I've tried
with no luck (global/local).

For i.e. a part of my de.yml:

de:
path_names:
new: "neu"
edit: "edieren"
routes:
categories:
as: 'kategorien'

When app starts I see nothing about path_names in the log but see some
stuff like:

[I18n] > localize resources : categories
(de) => /kategorien

Thanks for any help!

Arnau Sanchez

unread,
Sep 19, 2011, 7:19:36 AM9/19/11
to I18n Routing
On 19 sep, 12:58, "Mikhail S. Pobolovets" <styx...@gmail.com> wrote:

> Does anybody tried to override path_names on Rails 3.1? I've tried
> with no luck (global/local).
>
> For i.e. a part of my de.yml:
>
> de:
>   path_names:
>     new:  "neu"
>     edit: "edieren"
>   routes:
>     categories:
>       as: 'kategorien'

What's your route.rb files?

Paweł Barcik

unread,
Sep 19, 2011, 4:55:54 PM9/19/11
to i18n-r...@googlegroups.com
Hi

Your configuration is wrong. Below you have part of my config which works with Rails 3.1. Don't know about the global change for all controllers but this config works on per controller basis.

pl:
  routes:
    products:
      as: "produkty"
      path_names:
        new: "nowy"
        in_category: "w_kategorii"    


--------------------------
Pawel Barcik
Gem Coders LTD

Mikhail

unread,
Sep 20, 2011, 8:45:24 AM9/20/11
to i18n-r...@googlegroups.com
Here is my routes.rb:
http://pastie.org/private/9xwzwgqpj5cjgv5fopjydq

@Paweł Barcik
I've tried your configuration too it doesn't work for me and it will
be a pain to copy paste that stuff for all the controllers.
Thanks anyway.

2011/9/19 Paweł Barcik <pawel....@gmail.com>:

--
Best regards,
Mikhail S. Pobolovets

Arnau Sanchez

unread,
Sep 20, 2011, 9:43:04 AM9/20/11
to I18n Routing
@Mikhail, I don't exactly where the problem in your code, but this
works for me in Rails 3.1.0:

# config/routes.rb
MyApp::Application.routes.draw do
localized(["es"]) do
resources :pages
end
end

# config/locales/es.yml
es:
resources:
pages: paginas

path_names:
new: nuevo

routes:
pages:
path_names:
new: nueva

And now http://localhost:3000/paginas/nueva serves
PagesController#new. Note that the specific "path_names" is used over
the global. Hope this helps.

arnau

On 20 sep, 14:45, Mikhail <styx...@gmail.com> wrote:
> Here is my routes.rb:http://pastie.org/private/9xwzwgqpj5cjgv5fopjydq
>
> @Paweł Barcik
> I've tried your configuration too it doesn't work for me and it will
> be a pain to copy paste that stuff for all the controllers.
> Thanks anyway.
>
> 2011/9/19 Paweł Barcik <pawel.bar...@gmail.com>:
>
>
>
>
>
>
>
>
>
> > Hi
> > Your configuration is wrong. Below you have part of my config which works
> > with Rails 3.1. Don't know about the global change for all controllers but
> > this config works on per controller basis.
> > pl:
> >   routes:
> >     products:
> >       as: "produkty"
> >       path_names:
> >         new: "nowy"
> >         in_category: "w_kategorii"
>
> > --------------------------
> > Pawel Barcik
> > Gem Coders LTD
> > GemCoders.com
>

Mikhail

unread,
Sep 20, 2011, 11:40:32 AM9/20/11
to i18n-r...@googlegroups.com
Thanks, will be trying to figure out what is wrong.

2011/9/20 Arnau Sanchez <tok...@gmail.com>:

Mikhail

unread,
Sep 20, 2011, 12:17:42 PM9/20/11
to i18n-r...@googlegroups.com
I found another problem. In my routes I have a global :root and :root
in namespace :admin.
In the result my global :root is overridden by namespaced one.

2011/9/20 Mikhail <sty...@gmail.com>:

Guillaume Luccisano

unread,
Sep 20, 2011, 1:02:34 PM9/20/11
to i18n-r...@googlegroups.com
Hello Mikhail, you might fix this by not translating admin routes.
It's probably useless right ?

2011/9/20 Mikhail <sty...@gmail.com>

Mikhail

unread,
Sep 20, 2011, 1:40:18 PM9/20/11
to i18n-r...@googlegroups.com
@Guillaume Luccisano
Yep, but thanks anyway!

2011/9/20 Guillaume Luccisano <guillaume...@gmail.com>:

nico

unread,
Oct 11, 2011, 5:21:22 AM10/11/11
to I18n Routing
Same issue here. Not only path names but also other route translations
are not found. I tried all combinations suggested on this page. Under
which keys do I need to put simple named routes in Rails 3.1? A
reference about where to put which translations would be really
useful. I'm puzzled why its not in the wiki. Shall we guess
translation keys? ;-) Or have I overlooked something.

Best Regards,
Nico

Jhonathas Silveira de Matos

unread,
Oct 11, 2011, 6:12:47 AM10/11/11
to i18n-r...@googlegroups.com
It does not really even know what to try.
Know any other gem?


2011/10/11 nico <nico.r...@googlemail.com>



--
Jhonathas Matos
--------------------------------------------------------
email: jhon...@gmail.com
gtalk: jhon...@gmail.com
msn: jhon...@hotmail.com

Guillaume Luccisano

unread,
Oct 11, 2011, 11:19:44 AM10/11/11
to i18n-r...@googlegroups.com
You can find example here: https://github.com/kwi/i18n_routing/tree/master/spec

2011/10/11 Jhonathas Silveira de Matos <jhon...@gmail.com>

Guillaume Luccisano

unread,
Oct 11, 2011, 11:20:02 AM10/11/11
to i18n-r...@googlegroups.com
And make sure your I18n.available_locales is set.

2011/10/11 Guillaume Luccisano <guillaume...@gmail.com>

nico

unread,
Oct 11, 2011, 1:50:55 PM10/11/11
to I18n Routing
Hi Guillaume,

thanks for the link. I tried the following from the examples here:
http://www.tricksonrails.com/2010/05/i18n_routing-translate-your-rails2-rails3-routes-with-ease/comment-page-1/#comment-184

fr-CH:
resource:
video_albums: video_albums-fr-CH
named_routes_path:
advertise: advertise-fr-CH
routes:
users:
as: users-fr-CH
path_names:
new: new-fr-CH


ruby-1.9.2-p290 > I18n.locale = :'fr-CH'
=> :"fr-CH"
ruby-1.9.2-p290 > app.users_path
=> "/users-fr-CH"
ruby-1.9.2-p290 > app.video_albums_path
=> "/video_albums"
ruby-1.9.2-p290 > app.advertise_path
=> "/advertise"
ruby-1.9.2-p290 > app.new_user_path
=> "/users-fr-CH/new"
ruby-1.9.2-p290 >

Available locales is set, actually I supply explicit locales in the
localized call.

Nico



On Oct 11, 5:20 pm, Guillaume Luccisano
<guillaume.luccis...@gmail.com> wrote:
> And make sure your I18n.available_locales is set.
>
> 2011/10/11 Guillaume Luccisano <guillaume.luccis...@gmail.com>
>
>
>
>
>
>
>
> > You can find example here:
> >https://github.com/kwi/i18n_routing/tree/master/spec
>
> > 2011/10/11 Jhonathas Silveira de Matos <jhonat...@gmail.com>
>
> >> It does not really even know what to try.
> >> Know any other gem?
>
> >> 2011/10/11 nico <nico.rits...@googlemail.com>
>
> >>> Same issue here. Not only path names but also other route translations
> >>> are not found. I tried all combinations suggested on this page. Under
> >>> which keys do I need to put simple named routes in Rails 3.1? A
> >>> reference about where to put which translations would be really
> >>> useful. I'm puzzled why its not in the wiki. Shall we guess
> >>> translation keys? ;-) Or have I overlooked something.
>
> >>> Best Regards,
> >>> Nico
>
> >> --
> >> Jhonathas Matos
> >> --------------------------------------------------------
> >> email: jhonat...@gmail.com
> >> gtalk: jhonat...@gmail.com
> >> msn: jhon_...@hotmail.com

nico

unread,
Oct 11, 2011, 2:08:03 PM10/11/11
to I18n Routing
So basically only the

routes:
users:
as: users-fr-CH

works. I'm also wondering what the difference is between

resources:
users: users-fr-CH

and the above. Seem equivalent to me.

Actually I forgot the plural "s" in the resources key in my previous
post, but even when I add it the translation is not found.

Nico





On Oct 11, 7:50 pm, nico <nico.rits...@googlemail.com> wrote:
> Hi Guillaume,
>
> thanks for the link. I tried the following from the examples here:http://www.tricksonrails.com/2010/05/i18n_routing-translate-your-rail...

nico

unread,
Oct 13, 2011, 8:00:05 AM10/13/11
to I18n Routing
Any ideas what might go wrong? Basically only the

routes:
users:
as: users-fr-CH

works for me. All other translations are not found.

Guillaume Luccisano

unread,
Oct 13, 2011, 8:40:41 AM10/13/11
to i18n-r...@googlegroups.com
Hmm, right now, I have no idea, (sorry long time I haven't use the gem) but this notation should be the most usable one.
You can't do named path with it ?

2011/10/13 nico <nico.r...@googlemail.com>

nico

unread,
Oct 14, 2011, 7:23:33 AM10/14/11
to I18n Routing
Spending hours now figuring this out. It seems the gem is not really
functional beyond basic routes in rails 3.1.1

I managed now to get the named routes lookup working like this:

fr-CH:

routes:
advertise:
as: advertise-fr-CH

ruby-1.9.2-p290 > app.advertise_path
=> "/advertise-fr-CH"

However, I don't see any documentation for this. I had to look into
the source code, which isn't easy to read.

When adding a nested route to the user routes like this:

localized([:'de-CH', :'fr-CH'], :verbose => true) do
resources :users do
resources :videos
end
end

with

fr-CH:
routes:
users:
as: users-fr-CH
path_names:
new: new-fr-CH

path_names.new is wrongly recognized as belonging to videos and the
new path segment for new_user_path is not translated.

To fix this I can work around that by removing the nested resource and
adding an extra block:

resources :users do
localized([:'de-CH', :'fr-CH'], :verbose => true) do
resources :videos
end
end

However, this is not very clean and I also don't know where to store
the translations for the nested videos resource.

Is that gem actually maintained? Would be a pitty if not, as it is one
of the very few options for translating routes in rails.

On 13 Okt., 14:40, Guillaume Luccisano <guillaume.luccis...@gmail.com>
wrote:
> Hmm, right now, I have no idea, (sorry long time I haven't use the gem) but
> this notation should be the most usable one.
> You can't do named path with it ?
>
> 2011/10/13 nico <nico.rits...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages