Giter VIP home page Giter VIP logo

rails-translate-routes's People

Contributors

francesc avatar gyllen avatar nicoarbogast avatar stephanvane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rails-translate-routes's Issues

Routes inside scopes with conditional variables are not translated

With this i18n-routes.yml:

da:
  routes:
    foo: julemand
    too: nissepige

There is a problem with scopes that include conditional variables:

namespace :myspace do
  scope "/:user_id" do
    get 'foo' => 'foo#bar' # Is translated correctly
    # myspace_julemand_da GET  /da/myspace/:user_id/julemand(.:format)
  end
  scope "/(:user_id)" do
    get 'too' => 'too#bar' # Is not translated :(
    # myspace_too_da GET  /da/myspace(/:user_id)/too(.:format)
  end
end

Which surely must be a bug?

I wanted to add a failing test, but there isn't any :-)

Can routes without controllers be translated?

Consider this configuration:

#config/routes.rb
resources :simple
resources :simple_alias, :path => '/simple-alias', :controller => :simple

... plus this one:

#config/locales/routes.yml
pt:
  routes:
    simple: simples
    simple_alias: altalho

This does make /simple, /simples and /simple-alias work. But /atalho won't work with that.
The only difference I can read, is that the first resource has a real dedicated controller for itself, the second doesn't.

Could this be a bug?

link_to with default_url_options generates wrong URL

With rails 3.2 some links are not properly generated.

To reproduce :

use the rails-translate-routes gem :
in Gemfile

gem 'rails-translate-routes'

in app/views/welcome/index.html.erb

<%= link_to 'working', { :controller => "welcome", :action => "index", :locale => "en" } %>
<%= link_to 'not working', { :controller => "welcome", :action => "index" } %>
<%= link_to 'working', welcome_index_path %>

in app/controllers/application_controller.rb

def self.default_url_options
  { :locale => I18n.locale }
end

this renders

<a href="/welcome/index">working</a>
<a href="/assets?controller=welcome&locale=en">not working</a>
<a href="/welcome/index">working</a>

Namespaced translations stopped working after update to 0.1.x

In my application (Rails 3.2.6, i18n 0.6.0):

config/routes.rb:

Centrum::Application.routes.draw do
  namespace :store do
    resources :products, :path => 'books'
    root :to => 'products#index'
  end
end

ActionDispatch::Routing::Translator.translate_from_file('config/routes.yml')

config/routes.yml:

pl:
  store: sklep
  books: ksiazki
  new: dodaj
  edit: edytuj

The controller is namespaced:

app/
  |- controllers/
    |- store/
      products_controller.rb

rake routes when on 0.0.5:

  store_products_pl GET        /sklep/ksiazki(.:format)                store/products#index {:locale=>"pl"}
                       POST       /sklep/ksiazki(.:format)                store/products#create {:locale=>"pl"}
  new_store_product_pl GET        /sklep/ksiazki/dodaj(.:format)          store/products#new {:locale=>"pl"}
 edit_store_product_pl GET        /sklep/ksiazki/:id/edytuj(.:format)     store/products#edit {:locale=>"pl"}
      store_product_pl GET        /sklep/ksiazki/:id(.:format)            store/products#show {:locale=>"pl"}
                       PUT        /sklep/ksiazki/:id(.:format)            store/products#update {:locale=>"pl"}
                       DELETE     /sklep/ksiazki/:id(.:format)            store/products#destroy {:locale=>"pl"}
         store_root_pl            /sklep(.:format)                        store/products#index {:locale=>"pl"}

rake routes when on 0.1.1:

     store_products_pl GET        /store/books(.:format)                  store/products#index {:locale=>"pl"}
                       POST       /store/books(.:format)                  store/products#create {:locale=>"pl"}
  new_store_product_pl GET        /store/books/new(.:format)              store/products#new {:locale=>"pl"}
 edit_store_product_pl GET        /store/books/:id/edit(.:format)         store/products#edit {:locale=>"pl"}
      store_product_pl GET        /store/books/:id(.:format)              store/products#show {:locale=>"pl"}
                       PUT        /store/books/:id(.:format)              store/products#update {:locale=>"pl"}
                       DELETE     /store/books/:id(.:format)              store/products#destroy {:locale=>"pl"}
         store_root_pl            /store(.:format)                        store/products#index {:locale=>"pl"}

Am I missing something in configuration or there is another reason?

Matching regex

I defined my routes as follows:

Redu::Application.routes.draw do
  namespace 'api' do
    match '*anything', :to => 'api#routing_error'
  end
end
ActionDispatch::Routing::Translator.translate_from_file('lang/i18n-routes.yml')

When I try to run rake routes I get this error:

(in /Users/guiocavalcanti/workspace/work/redu)
** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
can't convert Array into String
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `compile'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:31:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:25:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rack-mount-0.6.14/lib/rack/mount/regexp_with_named_groups.rb:25:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:25:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:186:in `inject'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `inject'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route.rb:24:in `initialize'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:299:in `new'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.0.10/lib/action_dispatch/routing/route_set.rb:299:in `add_route'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:195:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:194:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:194:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:193:in `each'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:193:in `translate'
/Users/guiocavalcanti/.rvm/gems/ruby-1.8.7-p352/gems/rails-translate-routes-0.0.4/lib/rails-translate-routes.rb:347:in `translate_from_file'
/Users/guiocavalcanti/workspace/work/redu/config/routes.rb:6

I'm trying to make a catch all route (inside api namespace) to rescue from RoutingError (see this reference for details).

can't convert Array into String

Hello,

i want to use this gem instead of "translate_routes" - my project is rails 3.0.1.

try:
rake 0.8.7 routes
returns:
rake aborted!
can't convert Array into String

try:
server start - same problem.

i delete all lines from my routes.rb, only these lines:

Test::Application.routes.draw do
resources :contacts
end

ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml', { :prefix_on_default_locale => true })

nothing helps.

thanks.

url_for() acts as crazy when doing a "redirect" conditions in Routes

Hello,

I've been using translate_routes gem on Rails 2 without any problems and since we are migrating to Rails 3 i decided to use yours, thanks for making it !

In Rails 3 it's now possible to add redirect() routes, like this :
match "/home" => redirect("/totot")

My problem is that if i do that and use your plugin, the "url_for" method act as crazy, every url created then display a link to that redirect with the correct action and controller as parameters,

for example :
url_for(:controller=>"user", :action=>"create") then display :
"/toto?controller=user&action=create

Are you aware of that ?

Thanks a lot.

root_path takes always application default locale

I have translated my app in two languages using Rails 3.2.6, de and en. Setting the locale in Application Controller:

before_filter :set_locale

def set_locale
I18n.locale = params[:locale] || I18n.default_locale ##for root_path params[:locale]=de(default locale) always
end

add in the routes.rb
ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml',{:no_prefixes => true })

Everything working fine except on the root_path the locale is not setting. Take always application default locale.

Please let me know any solution for this.

Thanks.

Rails 3.2 support

Just checked out Rails 3.2 it seems the routing recognition is replaced by Journey engine (https://github.com/rails/journey/tree/master/lib/journey) and have many differences with the current one, so probably I'll have to make two branches rails 3.0-3.1 as 0.x releases and a new one for >3.2 as 1.x release.

Haven't looked deeply on it but it seems it will take a while as a major rewrite will be needed :(

Wrong generated links when models are translated

links are not properly translated if we use both rails-translate-models and rails-translate-routes.

If I use a route including a custom parameter (not the id), then it is not taken into account when linking to another locale than the current one.

let's say I have a model Post, the associated controller PostController and the action show.

I add in my routes.rb the following line :
match "post/:url" => "post#show"

I define my model with has_translations :url and the proper translations to have urls /post/english_message and /post/espanol_mensaje defined and replying to GET requests as expected.

then, if my locale is 'es', the helper <%= link_to url_for( :locale => 'es' ) %>, if I'm in an english page, will generate a link to "www.mysite.com/es/post/english_message/" instead of "www.mysite.com/es/espagnol_mensaje"

Conflict with RailsAdmin

I had this :

mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

near the top of my routes.rb file and everything went just fine until I installed rails-translate-routes.

Then after installing the gem some of my articles#show links turned into "/admin?action=show&controller=articles&id=XX"

An easy workaround was to move the mount RailsAdmin line to the end of the routes.draw do end block.

I don't know if the issue is really an issue, but maybe this will save some time to the next guy encoutering this :)

Translating routes which are defined in Rails engines

I have a Rails engine/gem with routes which is required by main Rails app. When I type "bundle exec rake routes" while I'm in the main app's directory, I don't see the translated urls/routes(widgets) which are defined in the Rails engine. In the main app's routes.rb file, routes for "posts" are defined.

Here is the output of "rake routes" command:

    posts_en GET    /en/posts(.:format)          {:action=>"index", :controller=>"posts"}
    posts_tr GET    /tr/posts(.:format)          {:action=>"index", :controller=>"posts"}
    posts_es GET    /es/posts(.:format)          {:action=>"index", :controller=>"posts"}
             POST   /en/posts(.:format)          {:action=>"create", :controller=>"posts"}
             POST   /tr/posts(.:format)          {:action=>"create", :controller=>"posts"}
             POST   /es/posts(.:format)          {:action=>"create", :controller=>"posts"}
 new_post_en GET    /en/posts/new(.:format)      {:action=>"new", :controller=>"posts"}
 new_post_tr GET    /tr/posts/new(.:format)      {:action=>"new", :controller=>"posts"}
 new_post_es GET    /es/posts/new(.:format)      {:action=>"new", :controller=>"posts"}
edit_post_en GET    /en/posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
edit_post_tr GET    /tr/posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
edit_post_es GET    /es/posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
     post_en GET    /en/posts/:id(.:format)      {:action=>"show", :controller=>"posts"}
     post_tr GET    /tr/posts/:id(.:format)      {:action=>"show", :controller=>"posts"}
     post_es GET    /es/posts/:id(.:format)      {:action=>"show", :controller=>"posts"}
             PUT    /en/posts/:id(.:format)      {:action=>"update", :controller=>"posts"}
             PUT    /tr/posts/:id(.:format)      {:action=>"update", :controller=>"posts"}
             PUT    /es/posts/:id(.:format)      {:action=>"update", :controller=>"posts"}
             DELETE /en/posts/:id(.:format)      {:action=>"destroy", :controller=>"posts"}
             DELETE /tr/posts/:id(.:format)      {:action=>"destroy", :controller=>"posts"}
             DELETE /es/posts/:id(.:format)      {:action=>"destroy", :controller=>"posts"}
     widgets GET    /widgets(.:format)           {:action=>"index", :controller=>"widgets"}
             POST   /widgets(.:format)           {:action=>"create", :controller=>"widgets"}
  new_widget GET    /widgets/new(.:format)       {:action=>"new", :controller=>"widgets"}
 edit_widget GET    /widgets/:id/edit(.:format)  {:action=>"edit", :controller=>"widgets"}
      widget GET    /widgets/:id(.:format)       {:action=>"show", :controller=>"widgets"}
             PUT    /widgets/:id(.:format)       {:action=>"update", :controller=>"widgets"}
             DELETE /widgets/:id(.:format)       {:action=>"destroy", :controller=>"widgets"}

Rails 4 compatibility

Looks like the gem doesnt work. Routes were translated but _path helpers doesnt work.

'host' constraint not working

Hello, I tried using constraints host: 'example.com' in my routes.rb. I think this problem is closely related to #12. Adding conditions[:host] = route.constraints[:host] if route.constraints would work.

I guess that since there could be more constraints a more general solution is in it's place. Replacing the #12 fix with:

if route.constraints
  route.constraints.each do |k,v|
    conditions[k] = v unless k == :request_method
  end
end

works for me. (request_method is left out since it resulted in an error).

I'm not sure if my method introduces new problems. If it does, then a simple conditions[:host] = route.constraints[:host] if route.constraints instead would to the trick.

Is it possible to translate routes but keep (some) original ones?

Hi,

I'm using your gem to translate "front" routes only.
I'm using carrierwave to upload some files in my admin. Here's an uploader:

class CheatsheetUploader < CarrierWave::Uploader::Base
  [...]
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  [...]
end

As you see, the path is using the name of the model and the name of the field.

When I try to get the file:

link_to "my file", download.cheatsheet.url

The path is the default one:

http://localhost:3000/uploads/download/cheatsheet/1/a_really_nice_file.pdf

And Rails give me a nice Routing error:

No route matches [GET] "/uploads/download/cheatsheet/1/a_really_nice_file.pdf"

Any way to handle this?

Gem breaks Rails.application.routes.url_helpers

In some models i'm using

Rails.application.routes.url_helpers.articles_path

But after installing the gem I had this error :

undefined method `articles_path' for #<Module:0x7f744fbaaa70>

Using with RSpec 2

How can I use it with RSpec 2. Controller test like

get :index
response.should be_success

return errors 'No route matches'

In routing test I'm able to test only route helpers like contact_us_en_path, but not contact_us_path

Thank you.

Translation within controller

Hi guys!

First thanks for the awesome gem!

Translation within the controller is failing for me:

file routes.rb

resources :rec_products do
  get 'add', :on => :member
end

on view this works fine:

add_rec_product_url(rec_product)

where rec_product is an instance variable

On the controller, when calling

Rails.application.routes.url_helpers.add_rec_product_url(rec_product)

I get

"NoMethodError: undefined method `add_rec_product_pt_url' for #<ActionView::Base:0xcbd039c>" 

Sorry, I know this is no support group, but is there any way to get the translated url_helpers to work on controllers.

Note I tried these:

Thanks, best,

Can't switch languages anymore

Hey there guys,

I believe this is something that I'm simply doing wrong: I have an app that uses the following configuration:

ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml', { no_prefixes: true, keep_untranslated_routes: true })

ApplicationController:

  before_filter :set_locale
  before_filter :set_locale_from_url

  def set_locale
    I18n.locale = params[:locale] || ((lang = request.env['HTTP_ACCEPT_LANGUAGE']) && lang[/^[a-z]{2}/])
  end

Now I wanted to have a language-switcher and added this:

    <p>
    <%= link_to_unless I18n.locale == :en, "English", locale: :en %>
    |
    <%= link_to_unless I18n.locale == :de, "Deutsch", locale: :de %>
    </p>

However: The language-switcher will not work. The only thing that currently succesfully switches the language in my app is by willfully accessing a route in the target-language.

What I have already done:

  • Checking params[:locale] - it always hold the path's locale, even if ?locale= is given.
  • Removing before_filter :set_locale_from_url. Doesn't help.

How do I do this correctly with "rails-translate-routes"?

Thx for your help!

Double locale in url when not in default locale

When using this: url_for({:action => "section", :slug => @section.slug, :save => 1, :locale => I18n.locale}) and having prefix_on_default_locale: true and no_prefixes: false, I get a double locale (default locale + new_locale) in the url if active locale is not the default: (Here fr is the default)

Example:
/fr/en/questionnaire/section/profile?save=1
when I need:
/en/questionnaire/section/profile?save=1
(Here questionnaire is the controller, section the action and profil/profile the slug in fr and en respectively)

When active locale is the default locale, there is no problem:

/fr/questionnaire/section/profil?save=1

In my routes.rb, I have this:

scope "(:locale)" do
match '/:controller/:action(/:slug)', :controller => "questionnaire"
end

If I remove the scope, all the other routes fail.
Any idea how to fix this?
Thanks!

Does the gem work with subdomains?

If I create two identical routes on two subdomains, only the first route is taken into account.
It works as if the subdomain constraint didn't exist.

ex :

  constraints(:subdomain => 'foo') do
    match '/' => 'home#foo', :as => :root
  end

  constraints(:subdomain => 'bar') do
    match '/' => 'home#bar', :as => :bar_home
  end

bar.website.com/ points to home#foo.

Conflict with Refinery CMS

Since refinery has this:

mount Refinery::Core::Engine, :at => '/'

I had to declare the front routes before that like this:

App::Application.routes.draw do
  # Frontend routes
  namespace :refinery, :path => "" do
    namespace :success_stories do
      resources :success_stories, :path => '', :only => [:index, :show]
    end
  end  
end

ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml')

App::Application.routes.draw do
  mount Refinery::Core::Engine, :at => '/'
end

And it works perfect, I can access model with the translations and everything. The problem is that the url methods aren't working at all:

undefined method `refinery_clients_client_es_url' for #<#<Class:0x0000010a260d80>:0x0000010b101088>

But rake routes show me that link like it's ok:

 refinery_clients_client_es GET    /clientes/:id(.:format)                                                 refinery/clients/clients#show {:locale=>"es"}

I guess it's not reaching the translation from the Refinery engine, but I don't know how to make it work.

Thanks!

assert_recognizes needs locale param even with controller_test_helper included.

Hi, great Gem! Thanks a lot!
This is more like a feature request.
I've required the controller_test_helper so I don't need set the :locale param on my tests (like get :show, etc). That works great. But the assert_recognizes still needs the locale param or it would fail:

    assert_recognizes({:controller => "pages", :action => "brand"}, "brand")

to:

    assert_recognizes({:controller => "pages", :action => "brand", :locale => "en"}, "brand")

or this error occurs:

Failure:
  The recognized options <{"action"=>"brand", "controller"=>"pages", "locale"=>"en"}> did not match <{"action"=>"brand", "controller"=>"pages"}>, difference: <{"locale"=>"en"}>.
  <{"action"=>"brand", "controller"=>"pages"}> expected but was
  <{"action"=>"brand", "controller"=>"pages", "locale"=>"en"}>.

  diff:
  - {"action"=>"brand", "controller"=>"pages"}
  + {"action"=>"brand", "controller"=>"pages", "locale"=>"en"}
  ?                                          ++++++++++++++++
test_should_route_to_brand_actions(PagesControllerTest)

It would be nice if you don't have to.

Translating current url into another language

Hi Francesc,

I'm looking into your plugin as replacement from Raul's translate_routes in my Rails3.1 app. I'm struggling with the following use case, maybe this can be done easily. If not, this might me an interesting feature to add :)

I want to have a language switcher in the header, used across the site, with the different available languages. I'd like the switcher to link or redirect to the page the user is at, localized with the selected language. I was looking for some helper or method to translate current_url. I ended up using some ugly javascript, but it good be great if I could use translate-routes.

Any ideas?

Thanks!

NoMethodError: undefined method `mymodel_zh_url' for #<MymodelsController:0x0000080aa205a0>

It seems that under certain circumstances an inexistant URL is called.

The line in the controller looks like this:

redirect_to mymodel_url(@mymodel_instance), :status => 301

Somehow it seems, rails-translate-routes is translating that to mymodel_zh_url which is unavailable.

The full backtrace:

[GEM_ROOT]/gems/rails-translate-routes-0.1.3/lib/rails-translate-routes.rb:259:in block (3 levels) in add_untranslated_helpers_to_controllers_and_views
[PROJECT_ROOT]/app/controllers/mymodels_controller.rb:80:in redirect
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/implicit_render.rb:4:in send_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/abstract_controller/base.rb:167:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/rendering.rb:10:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/abstract_controller/callbacks.rb:18:in block in process_action
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:480:in _run__4034545293613287212__process_action__1314415123970547437__callbacks
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in __run_callback
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in _run_process_action_callbacks
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in run_callbacks
[GEM_ROOT]/gems/actionpack-3.2.6/lib/abstract_controller/callbacks.rb:17:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/rescue.rb:29:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/instrumentation.rb:30:in block in process_action
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in block in instrument
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in instrument
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in instrument
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/instrumentation.rb:29:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/params_wrapper.rb:206:in process_action
[GEM_ROOT]/gems/activerecord-3.2.6/lib/active_record/railties/controller_runtime.rb:18:in process_action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/abstract_controller/base.rb:121:in process
[GEM_ROOT]/gems/actionpack-3.2.6/lib/abstract_controller/rendering.rb:45:in process
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal.rb:203:in dispatch
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal/rack_delegation.rb:14:in dispatch
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_controller/metal.rb:246:in block in action
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:73:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:73:in dispatch
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:36:in call
[GEM_ROOT]/gems/journey-1.0.3/lib/journey/router.rb:68:in block in call
[GEM_ROOT]/gems/journey-1.0.3/lib/journey/router.rb:56:in each
[GEM_ROOT]/gems/journey-1.0.3/lib/journey/router.rb:56:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:600:in call
[GEM_ROOT]/bundler/gems/rack-piwik-4d426315c034/lib/rack/piwik.rb:18:in _call
[GEM_ROOT]/bundler/gems/rack-piwik-4d426315c034/lib/rack/piwik.rb:15:in call
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:35:in block in call
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in catch
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/best_standards_support.rb:17:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/etag.rb:23:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/head.rb:14:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/params_parser.rb:21:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/flash.rb:242:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in context
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/cookies.rb:338:in call
[GEM_ROOT]/gems/activerecord-3.2.6/lib/active_record/query_cache.rb:64:in call
[GEM_ROOT]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/callbacks.rb:28:in block in call
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in _run__3147508345656361752__call__1650080518533853104__callbacks
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in __run_callback
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in _run_call_callbacks
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in run_callbacks
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/callbacks.rb:27:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/remote_ip.rb:31:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/debug_exceptions.rb:16:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/show_exceptions.rb:56:in call
[GEM_ROOT]/gems/railties-3.2.6/lib/rails/rack/logger.rb:26:in call_app
[GEM_ROOT]/gems/railties-3.2.6/lib/rails/rack/logger.rb:16:in call
[GEM_ROOT]/gems/actionpack-3.2.6/lib/action_dispatch/middleware/request_id.rb:22:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/runtime.rb:17:in call
[GEM_ROOT]/gems/activesupport-3.2.6/lib/active_support/cache/strategy/local_cache.rb:72:in call
[GEM_ROOT]/gems/rack-1.4.1/lib/rack/lock.rb:15:in call
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in forward
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in fetch
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in lookup
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in call!
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in call
[GEM_ROOT]/gems/railties-3.2.6/lib/rails/engine.rb:479:in call
[GEM_ROOT]/gems/railties-3.2.6/lib/rails/application.rb:220:in call
[GEM_ROOT]/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in method_missing
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/request_handler.rb:96:in process_request
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_request_handler.rb:513:in accept_and_process_next_request
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_request_handler.rb:274:in main_loop
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:206:in start_request_handler
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:171:in block in handle_spawn_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/utils.rb:479:in safe_fork
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:166:in handle_spawn_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:357:in server_main_loop
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:206:in start_synchronously
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:180:in start
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:129:in start
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:253:in block (2 levels) in spawn_rack_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:132:in lookup_or_add
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:246:in block in spawn_rack_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:82:in block in synchronize
::in 
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:79:in synchronize
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:244:in spawn_rack_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:137:in spawn_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:275:in handle_spawn_application
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:357:in server_main_loop
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:206:in start_synchronously
/s/usr-local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/helper-scripts/passenger-spawn-server:99:in <main>

Integration with Rails 3.1 default I18n API

I have translated my app in two languages using Rails 3.1, pt-Br and es-MX. I define which one to use by adding the following to ApplicationController:

before_filter :set_locale

def set_locale
I18n.locale = extract_locale_from_tld || I18n.default_locale
end

def extract_locale_from_tld
parsed_locale = request.host.split('.').last
parsed_locale == "br" ? "pt-BR" : "es-MX"
end

It works fine, but after append this line on routes.rb:
ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml')

It doesn't work anymore, it is giving me always the default locale(that is defined in application.rb as pt-BR), as if something after the before_filter is changing it to default locale. Any idea?

When translations are enabled url_for generates different URLs

I'm using high_voltage gem that provides the following route:

match "/pages/:id", to: "high_voltage#show", as: "pages"

I also have my own routes to make some URLs prettier:

get "/faq", to: "high_voltage#show", id: "faq"

Without route translations, when I'm on page /faq, url_for(locale: :de) generates /faq?locale=de. When I enable route translations it generates /pages/faq?locale=de instead.

Any idea why translating routes changes result of url_for?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.