kwi / i18n_routing

I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !
MIT License
228 stars 48 forks source link

Rails 4.0 compatibility #43

Open lassebunk opened 11 years ago

lassebunk commented 11 years ago

Great plugin. But it doesn't work in the newly released Rails 4.0.0.beta1:

LoadError: cannot load such file -- journey
~/.rvm/gems/ruby-2.0.0-p0/gems/i18n_routing-0.6.2/lib/i18n_routing_rails32.rb:2:in `require'
~/.rvm/gems/ruby-2.0.0-p0/gems/i18n_routing-0.6.2/lib/i18n_routing_rails32.rb:2:in `<top (required)>'
~/.rvm/gems/ruby-2.0.0-p0/gems/i18n_routing-0.6.2/lib/i18n_routing.rb:7:in `require'
~/.rvm/gems/ruby-2.0.0-p0/gems/i18n_routing-0.6.2/lib/i18n_routing.rb:7:in `<top (required)>'
~/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.0/lib/bundler/runtime.rb:72:in `require'

Thanks.

xpepermint commented 11 years ago

+1, rails 4.0.0.rc1

ncri commented 11 years ago

Check out the rails4 branch in my fork here: https://github.com/ncri/i18n_routing/tree/rails4

As a starting point. No more errors, but not sure if it works properly yet.

haggen commented 11 years ago

Hey @ncri, it fixed the previous error (cannot load file -- journey) but another error popped up when starting the server:

/Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/gtg/builder.rb:7:in `<class:Builder>': uninitialized constant ActionDispatch::Journey::GTG::Builder::Nodes (NameError)
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/gtg/builder.rb:6:in `<module:GTG>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/gtg/builder.rb:5:in `<module:Journey>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/gtg/builder.rb:4:in `<module:ActionDispatch>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/gtg/builder.rb:3:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey.rb:2:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/router/utils.rb:4:in `<module:ActionDispatch>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/router/utils.rb:3:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc2/lib/action_dispatch/journey/router.rb:1:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:2:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing.rb:7:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
  from /Users/Arthur/Job/newmarykay/config/application.rb:13:in `<top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc2/lib/rails/commands.rb:78:in `require'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc2/lib/rails/commands.rb:78:in `block in <top (required)>'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc2/lib/rails/commands.rb:75:in `tap'
  from /Users/Arthur/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc2/lib/rails/commands.rb:75:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'
ncri commented 11 years ago

Just use the Rails 4 branch of my fork, it works (for me ;-)

lassebunk commented 11 years ago

Thanks @ncri :+1: – looking forward to try that out.

haggen commented 11 years ago

Actually it didn't work for me. But since I had to open up Journey's source and add an extra include line, I suspect the issue is not within your repo. :P

lassebunk commented 11 years ago

Could someone propose a solution for master?

tirsdag den 2. juli 2013 skrev Arthur Corenzan :

Actually it didn't work for me. But since I had to open up Journey's source and add an extra include line, I suspect the issue is not within your repo. :P

— Reply to this email directly or view it on GitHubhttps://github.com/kwi/i18n_routing/issues/43#issuecomment-20363252 .

ncri commented 11 years ago

I can make a pull request for master soon. until then, you can simply use my rails4 fork. @haggen: did you use the rails4 branch in my repo, or master? do you have a stacktrace for the error?

lassebunk commented 11 years ago

Thanks very much – that would be great.

ncri commented 11 years ago

Oops, @haggen, the stack trace was there already, my mistake. Did you only had to fix that one issue?

ncri commented 11 years ago

https://github.com/kwi/i18n_routing/pull/44

willywg commented 11 years ago

@haggen I have the same problem

ncri commented 11 years ago

Can you test if adding require 'action_dispatch/journey/nodes/node' on the very top of i18n_routing_rails4.rb fixes that issue?

meinac commented 11 years ago

I have a problem with i18n localized routes. here is a part of my yml file

tr: 
  named_routes_path: 
    start_a_project/: yeni-proje-baslat

and here is the route

localized(I18n.available_locales, :verbose => true) do
    match "start_a_project/" => "start_a_project#index", :as => 'start_a_project', :via => :get
end

is there any solution for this situation? I'm using ncri's i18n_routing gem. Rails 4.0 ruby 1.9.3 i18_routing gem => 'https://github.com/ncri/i18n_routing.git' :branch => 'rails4'

[I18n] > localize route     :                          start_a_project (tr) => /start_a_project(.:format)
/home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/journey/route.rb:46:in `requirements': undefined method `merge' for nil:NilClass (NoMethodError)
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:158:in `optimize_helper?'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:150:in `create'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:269:in `define_url_helper'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:135:in `define_url_helper'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:282:in `define_named_route_methods'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:124:in `add'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:445:in `add_route'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:216:in `block in match'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:212:in `each'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:212:in `match'
    from /vagrant/config/routes.rb:37:in `block (2 levels) in <top (required)>'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/i18n_routing-e905d1968a19/lib/i18n_routing_rails4.rb:162:in `localized'
    from /vagrant/config/routes.rb:36:in `block in <top (required)>'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/actionpack/lib/action_dispatch/routing/route_set.rb:319:in `draw'
    from /vagrant/config/routes.rb:1:in `<top (required)>'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:222:in `load'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:222:in `block in load'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:222:in `load'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/initializable.rb:30:in `run'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:180:in `each'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
    from /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application.rb:215:in `initialize!'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /vagrant/config/environment.rb:4:in `<top (required)>'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:228:in `require'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/activesupport/lib/active_support/dependencies.rb:228:in `require'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/application.rb:189:in `require_environment!'
    from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@rails_4_idemamacom/bundler/gems/rails-58cd859caa49/railties/lib/rails/commands.rb:61:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
willywg commented 11 years ago

require 'action_dispatch/journey/nodes/node' don't fix the problem :S

ncri commented 11 years ago

@mehmetemininac: I'm only using i18n routing for resource routes, not for named routes, as i had many issues with those. So I didn't test my branch with named routes.

@willywg: so you still get exactly the same error? can you make a minimla testapp available on github that reproduces the issue?

willywg commented 11 years ago

@ncri I put require 'action_dispatch/journey' on the top of i18n_routing_rails4.rb and fix my problem.

tilsammans commented 11 years ago

Everyone: for me the gem 'route_translator' works out of the box with the same configuration of i18n_routing.

It seems better supported too.

lassebunk commented 11 years ago

@tilsammans Does the route_translator gem also work without having the locale in the URL?

tilsammans commented 11 years ago

Yes.

I had to set the available locales to just the one I want to support, because otherwise there were many routes generated with unused locales.

Example, in config/initializers/i18n.rb:

# Limit available locales to the ones actually in use.
# Mostly limits the number of routes generated.
I18n.available_locales = [:nl]

Also the translations are under a different namespace, they are now all under "routes".

lassebunk commented 11 years ago

Okay, what happens if you have more than one, e.g. four?

tilsammans commented 11 years ago

I don't know, try it out yourself. :cat:

lassebunk commented 11 years ago

@willywg's require 'action_dispatch/journey' is also needed in my app to get it to work. Could you add this to your pull request? Thanks in advance.

lassebunk commented 11 years ago

(cc @ncri)

ncri commented 11 years ago

Added

lassebunk commented 11 years ago

Thanks :blush:

nicolasgarnil commented 11 years ago

Does it works on Rails 4? If so, the README should be updated.

lassebunk commented 11 years ago

@negarnil Check out https://github.com/kwi/i18n_routing/issues/43#issuecomment-19933983 for details. It's not in master yet. It works ok, but not optimal – for me anyway.

ncri commented 11 years ago

Yes, i believe my fork still needs some work, but for us it does all we need so far...

A bit off topic: To be honest the codebase of this gem is well, slightly messy. :) Huge methods that are hard to debug and maintain... No offence to the creator, it is an incredibly useful gem and there are not many alternatives out there, so thanks for making it! In my opinion we need route translation in the rails core though...

lassebunk commented 11 years ago

@ncri, I agree. I think your fork is fine – the problem is the base, IMO.

I'd really like to make a replacement for it, but I just don't know anything about the router internals. But there must be a better solution – none of the current ones work great.

Yeah, I don't understand why it's not in Rails core – @dhh, do you have a comment?

erikostling commented 11 years ago

Hello!

I'm getting this error:

/Users/erikostling/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-4.0.0/lib/action_dispatch/journey/route.rb:38:in `requirements': undefined method `merge' for nil:NilClass (NoMethodError)

on this route:

localized do  
    get "forbehall", to: "pages#disclaimer", as: "disclaimer"
end

Anyone else having the same problem? Using @ncri's fork.

ncri commented 11 years ago

mehmetemininac has the same error. I haven't looked into making the rails 4 fork work with named routes as I even had troubles getting those working correctly with the rails 3 branch. So, only resource routes work for now.

erikostling commented 11 years ago

Ah, I understand! Thanks for the quick reply.

prusswan commented 10 years ago

@ncri I have resolved the path.requirements.merge error, how can I tag on to your pull request?

ncri commented 10 years ago

You could either create a new pull request and copy my code over or, maybe easier, just fork my fork and create a pull request there: https://github.com/ncri/i18n_routing/tree/master