enriclluelles/route_translator — pull request #37 by Narnach (2013-11-11 14:29:38+00:00)
Title: Force locales, but with a fallback for the untranslated url

For an app I'm working on, I wanted the following behaviour:

* Have localised urls for all languages *with* named routes:

root_en_path # => "/en"
root_es_path # => "/es"

GET /en # => 200 OK, locale=en
GET /es # => 200 OK, locale=es

This can be achieved by setting `force_locale`.

* Have a fallback url *without* translation

GET / # => 200 OK, no locale

This can be achieved by setting `generate_unlocalized_routes`.

* Have the "old" named route dispatch dynamically, as if `force_locale` were set:

I18n.locale = :en
root_path # => "/en"

I18n.locale = :es
root_path # => "/es"

This can be achieved by setting `force_locale`, but it does *not* work when `generate_unlocalized_routes` is also set. Setting both would give this result:

I18n.locale = :en
root_path # => "/?locale=en"

I18n.locale = :es
root_path # => "/?locale=es"

To achieve this result, I've added a new config option `generate_unnamed_unlocalized_routes`. The name can be better, so suggestions are welcome ;-)

There are tests and they passed for ruby 2.0. I've added my fork as a dependency in my app and there the behavior also works as expected.

Would this be a useful addition to the official gem op route_translator?