kwi / i18n_routing Goto Github PK
View Code? Open in Web Editor NEWI18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !
License: MIT License
I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !
License: MIT License
mainly i would use i18n_routing gem i will be happy if i will translate match 'vlk' under dashboard resource, trying everything around, and no success. Resources are translated successfully also new action...whats wrong?
routes.rb
MyApp::Application.routes.draw do
root :to => 'home#index'
localized do
resources :cars
resource :admin, :controller => :admin
resource :dashboard do
member do
match 'vlk', :as => :vlk
end
end
end
end
routes.yml
cs:
cars: 'auta'
admin: 'admincesky'
routes:
dashboard:
as: 'novy'
path_names:
new: 'cesky_member'
vlk: 'tzz_cesky'
named_routes_path:
vlk: 'tzz_cesky'
caa
I have a resource called "kits" that is the same in both english and portuguese. The plugin doesn't create the localized paths like pt_kits, new_pt_kit, etc. This is an issue because I want localized path_names, like this:
English: /kits/new and /kits/1/edit
Portuguese: /kits/criar and /kits/1/editar
Any ideas?
I have created simple test application with i18n_routing gem, added Products scaffold and translation for products resource. But i18n_routing has not generated any translated routes.
My test application is here https://github.com/Lukom/testapp
When using non default i18n backends like activerecord, it's not unusual to have translations for keys with an empty values. In my case I was using that to keep track of untranslated sentences.
However, this causes some really weird behaviour in the rails application using i18n_routing, due to empty routes generated like:
en_products /(:locale) {:action=>"products", :controller=>"static", :i18n_locale=>"en"} ca_products /(:locale) {:action=>"products", :controller=>"static", :i18n_locale=>"ca"} es_products /(:locale)/productos {:action=>"products", :controller=>"static", :i18n_locale=>"es"} products (/:locale)/products(.:format) {:action=>"products", :controller=>"static"}
May it be possible to do a check for empty translations, and avoid generte the routes in that case?
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.
When trying out this gem in a new Rails 4.2 app, I get
$ rake routes
rake aborted!
ArgumentError: wrong number of arguments (6 for 3)
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:134:in `define_url_helper'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:289:in `block (2 levels) in included'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:227:in `match'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:289:in `block (2 levels) in included'
$APPPATH/config/routes.rb:6:in `block (4 levels) in <top (required)>'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:254:in `block (2 levels) in create_globalized_resources'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:183:in `skip_localization'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:252:in `block in create_globalized_resources'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:99:in `set_localizable_route'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:251:in `create_globalized_resources'
.../ruby/2.1.0/i18n_routing-16908a366e4f/lib/i18n_routing_rails4.rb:301:in `resources_with_i18n_routing'
$APPPATH/config/routes.rb:5:in `block (3 levels) in <top (required)>'
$APPPATH/config/routes.rb:4:in `block (2 levels) in <top (required)>'
$APPPATH/config/routes.rb:3:in `block in <top (required)>'
$APPPATH/config/routes.rb:1:in `<top (required)>'
$APPPATH/config/environment.rb:5:in `<top (required)>'
Any idea what this might be?
I'm using the rails4 branch of 'ncri' (which unfortunately doesn't have an issue tracker, so I post it here).
I cannot figure out why this isn't working. Where am i wrong?
Routes.rb
localized do
root :to => 'home#index', :as => :home
end
en.yml
en:
routes:
home_path: this-is-my-homepage
When I do
scope "(:locale)", :locale => /(fr-CH)/ do
localized do
match '/inserieren' => 'site#advertise', :as => :advertise
end
end
and then go to /fr-CH/inserieren
I get this error:
NoMethodError: undefined method `locale' for #ActionDispatch::Request:0x007fc222715bb0
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:543:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call'
oa-core (0.2.6) lib/omniauth/strategy.rb:44:in `call!'
oa-core (0.2.6) lib/omniauth/strategy.rb:30:in `call'
oa-core (0.2.6) lib/omniauth/builder.rb:30:in `call'
newrelic_rpm (3.1.1) lib/new_relic/rack/browser_monitoring.rb:18:in `call'
sass (3.1.7) lib/sass/plugin/rack.rb:54:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.2) lib/rack/etag.rb:23:in `call'
rack (1.3.2) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.2) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.2) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/cookies.rb:326:in `call'
activerecord (3.1.0) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.2) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.2) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.2) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.2) lib/rack/lock.rb:15:in `call'
rack-rewrite (1.0.2) lib/rack/rewrite.rb:19:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0) lib/rails/engine.rb:455:in `call'
railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call'
thin (1.2.11) lib/thin/connection.rb:84:in `block in pre_process'
thin (1.2.11) lib/thin/connection.rb:82:in `catch'
thin (1.2.11) lib/thin/connection.rb:82:in `pre_process'
thin (1.2.11) lib/thin/connection.rb:57:in `process'
thin (1.2.11) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.2.11) lib/thin/backends/base.rb:61:in `start'
thin (1.2.11) lib/thin/server.rb:159:in `start'
rack (1.3.2) lib/rack/handler/thin.rb:13:in `run'
rack (1.3.2) lib/rack/server.rb:265:in `start'
railties (3.1.0) lib/rails/commands/server.rb:70:in `start'
railties (3.1.0) lib/rails/commands.rb:54:in `block in <top (required)>'
railties (3.1.0) lib/rails/commands.rb:49:in `tap'
railties (3.1.0) lib/rails/commands.rb:49:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
I would like to translate the name of action like new, edit etc.. At this time I could not find any posibilities how do that.
When I try something like this :
resources:
enquiries:
new: poptavky/nova
The result is newpoptavky/nova.
Thanks a lot
PS: Im using rails 2.3.5
got error when trying to run "rake routes" or "rails s"
............./config/routes.rb:1: undefined method `localized' for main:Object (NoMethodError)
rails 3.0.7, i18n_routing 0.4.7
Hi, it's possible add some new features?
If is possible generate routes like this:
/pages
/pages/1-rails
/de/seiten
/de/seiten/1-rails
I found this gist: https://gist.github.com/1229107
but I think it would be great make it as default option called scope_localized without additional settings
Hi,
I have a route that looks like this:
namespace :shop do
resources :orders
end
Is any way to translate namespace "shop" ?? I will try translate this in many ways in my locale.yml, but nothing changes.
Am I the only one who finds it extremely annoying that i18n_routing prints all the routes every time? Is there an easy way to disable that thats not mentioned on the wiki?
Otherwise I love it ;)
Hello,
when I use your plugin, both the original and the translated routes exist. This is a problem because it creates duplicate content, which is bad for SEO.
Is it possible to have only the translated routes, and remove the original routes, when the locale is set to a language other than the default?
Thanks!
Given this route:
ActionDispatch::Routing::SEPARATORS << "-" unless ActionDispatch::Routing::SEPARATORS.include?("-")
match '/product-:name-:id' => 'products#show'
i18n_routing will throw an error
compile error /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:161: syntax error, unexpected '-', expecting '\n' or ';'
I suspect this is because I am using different parameter separators than the default '/' and '.' (for SEO optimization).
How would I be able use this plugin in combination with such routes?
Thanks!
Hi,
my routes.rb
scope "(:locale)" , :locale => /pt|en/ do
localized(['en','pt'], :verbose => true) do
match 'about' => "home#about",:as => :about
end
end
my translation
pt.yml
pt:
named_routes_path:
about: "pt_about"
rake routes
[I18n] > localize route : about (pt) => /(:locale)pt-about
where is slash?
This (excellent) gem is broken with the freshly released Rails 3.2.
Due to require 'rack/mount'
in lib/i18n_routing_rails3.rb
.
Indeed, Rails 3.2 use Journey for the routing.
All of my resources are translated with no problems.
However, the named_routes_path namespace gives me no results in my app.
Here is the freaky part though. When I go to script/console it works fine:
console > app.welcome_path
=> "/welcome"
console > I18n.locale = 'es'
=> "es"
console > app.welcome_path
=> "/bienvenido"
But if I call es_welcome_path in my app its undefined, and when I rake routes I dont see it anywhere (or any named route for that matter)
Here is a look inside config/locales/es.yml:
es:
named_routes_path:
sidi: "sidi-8"
sidi_info: "sidi-8-sobre-nosotros"
sidi_contact: "sidi-8-contacto"
sidi_thanks: "sidi-8-gracias"
studio: "estudio-de-arquitectura"
studio_contact: "estudio-de-arquitectura-contacto"
studio_thanks: "estudio-de-arquitectura-gracias"
studio_team: "estudio-de-arquitectura-equipo"
tech: "tecnicas-de-rehabilitacion"
tech_contact: "tecnicas-de-rehabilitacion-contacto"
tech_thanks: "tecnicas-de-rehabilitacion-gracias"
tech_team: "tecnicas-de-rehabilitacion-equipo"
welcome: "bienvenido"
Here is how I'm setting the locale in application_controller:
before_filter :set_current_locale
private
def set_current_locale
I18n.locale = params[:locale] ? params[:locale] : :en
end
Any idea why named routes are being ignored by this gem?
FWIW I'm running on 1.8.7-head via RVM
Here is a patch I found: https://gist.github.com/Marchino/954394
I'm using ruby 1.9.2dev (2010-05-28 revision 28049) [x86_64-darwin10]
Rails is -> gem 'rails', :git => 'http://github.com/rails/rails.git'
And I have this in my Gemfile gem 'i18n_routing'
I have this in my routes.rb
localized([:en, :fi], :verbose => true) do
match 'about' => 'contents#about', :as => :about
end
and locale files are following
en:
named_routes_path:
about: 'a-propos'
fi:
named_routes_path:
about: 'fi-propos'
rake routes prints these
[I18n] > localize route : about (en) => /a-propos
[I18n] > localize route : about (fi) => /fi-propos
but when i hit localhost:3000/a-propos or fi-propos i get No route matches "/a-propos" or No route matches "/fi-propos"
Also the <%= link_to 'about', about_path %> prints out just about
Could you help me debug this, I really don't know what to do next.
Thanks.
It tries to create the method "hash_for_about_pt-BR_course_path(options = nil)".
But "-" is not a valid character in method names.
Hi,
I have the following in config/routes.rb:
match "test" => redirect("/test2"), :as => :test
This results in the following error:
/Library/Ruby/Gems/1.8/gems/i18n_routing-0.6.1/lib/i18n_routing_rails32.rb:200:in `dump': no marshal_dump is defined for class Proc (TypeError)
from /Library/Ruby/Gems/1.8/gems/i18n_routing-0.6.1/lib/i18n_routing_rails32.rb:200:in `match'
from /Users/xx/app/config/routes.rb:63
Without the redirect route it works fine, and also when using other localized routes.
Hope you can help.
/Lasse
Hi all,
i have a problem with the correct translation of some words with special characters.
Example in my routes.rb:
localized(I18n.available_locales, :verbose => false) do
...
match 'land/:id' => 'land#index', :as => :land
...
end
In my YML file for Spain the translation for "land" is "país".
named_routes_path:
'land/:id': "país/:id"
...
You see the special character "í".
So when i start my rails application and switch the language to spanish and click on a link like (país/at-austria) that leads me to this error message:
"No route matches "/pa%C3%ADs/at-austria" "
All other routes without a special character in it, works correctly.
Any suggestions or solutions?
P.S.: I'm using ruby 1.9.2p0 and Rails 3.0.3
Thanks!
Christian
Hi,
I have a route that looks like this:
match ":city_id/:venue_id/reviews(.:format)" => "reviews#index", :as => :city_venue_reviews
In my translation file (nl.yml), i've got this (short version):
nl:
named_routes_path:
":city_id/:venue_id/reviews(.:format)" : ":city_id/:venue_id/recensies(.:format)"
Output of rake routes
:
city_venue_reviews /:city_id/:venue_id/reviews(.:format) {:controller=>"reviews", :action=>"index"}
Others paths translate just fine. Examples that work:
":city_id/:venue_id/reserve" : ":city_id/:venue_id/online-reserveren"
":city_id/:venue_id/order" : ":city_id/:venue_id/online-bestellen"
Given a nested route like this:
localized do
resources :users do
resources :videos
end
end
with a path_name translation key
locale:
routes:
users:
path_names:
new: translated_new
path_names.new is wrongly recognized as belonging to videos and the
new path segment for new_user_path is not translated.
Workaround: removing the nested resource and
adding an extra block:
localized do
resources :users
end
resources :users do
localized 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.
i18n_routing_rails3.rb:149:in `[]': can't convert Pathname into String (TypeError)
i18n_routing_rails3.rb:149:in `localized'
Got this error with rails3.beta3
Any suggestion?
Hi,
thanks for this gem!
i have tried to nest inside a singleton resource (Rails 3 beta3)
resource :foo do
resources :bars
end
but the generated named_routes look like this:
de_foo_de_bars, new_de_foo_de_bar etc.
by now i couldn't solve the problem and just added 2 failing specs here:
http://github.com/mixr/i18n_routing/commit/ec0f6f60375a64d0ac974a6a8680b7eeaef4a6ca
Greetings,
Reiner
I have tried everything that wiki explain...
But doesnt work in rails3 beta : /
I`m with Ruby 1.9.2 and Rails 3 beta4
routes.rb
localized(['pt'], :verbose => true) do
namespace :user do
match 'logout' => 'user_sessions#destroy'
match 'login' => 'user_sessions#new'
resource :session, :controller => "user_sessions"
resource :account, :controller => "users"
end
end
pt.yml
pt:
path_names:
new: 'adicionar'
edit: 'editar
When using named routes in Rails 3, there's an error when initializing (translating the routes):
lib/i18n_routing_rails3.rb:281:in `initialize': wrong number of arguments (4 for 3) (ArgumentError)
In my routes.rb I have:
localized([:es, :en], :verbose => true) do
match 'home' => 'home#show', :as => :home
end
I fixed the problem (4 arguements were sent to the Parent class), you can see my solution in a note in this commit:
http://github.com/kwi/i18n_routing/commit/4ecdea43564ec7d732bab6e00e32e0139103c129#comments
Thanks!
I didn't find a way to translate scopes
in Rails 3. Something like:
scope "national" do resources :events end scope "international" do resources :events end
The "national" and "international" parts in the url don't get translated.
en: /national/events pt: /national/eventos en: /international/events pt: /international/eventos
Is there anything I'm missing, or the gem can't handle it yet?
Hello,
i would like make links to change language of website
But currently i can't have url translated by language in these links
all links are in the same language (the current of course
how force to use a other language than current
I18n.available_locales.each do |locale|
new_params = params.merge(:locale => locale)
content += content_tag(:li, link_to(locale.to_s.upcase, new_params))
end
tx
This is a weird one, translated routes work (when I look at rake routes), however in case I start server they fail to translate. Then, when I edit the gemfile while server is on, routes start working. If I restart it again they stop until gemfile is edited.
My route looks like:
localized do
resources :nepremicnines do
collection do
get :obcino
end
end
end
And en.yml:
en:
resources:
nepremicnines: "real_estates"
path_names:
obcino: "municipality"
Since my production is on Heroku, with it's read-only fs, this is a bit of a problem for me.
According to the documentation, this should work. In config/routes.rb:
localized do
resources :films do
collection do
get :all
end
end
end
The 'all' collection is not localized when I use this YAML:
nl:
routes:
films:
as: "bios"
path_names:
all: "allemaal"
i18n_routing version 0.6.2 with Rails 3.2.9. The 'films' collection itself is localized properly.
How can I localize the collection path?
It seems many of the functions died in 3.1.1. I could make work only the basics. Only "routes:" translations works for me. And the url helpers url generation gives back the normal default rails url, witch is just not good.
I am not absolutely sure about the problems - can you check the overall rails 3.1 compatibility? It would be great! It is a really cool project!
Hello, I have a "Invalid route name: 'en_/'" after updated the plugin today. Can you help me please ?, I don't want to clarify a
:as => 'home'
localized I18n.available_locales do
scope '/:i18n_locale', :constraints => { :i18n_locale => /en|fr/ } do
match "/", :to => "home#index"
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.