Permalink
Browse files

Adding rails-translate-routes support

  • Loading branch information...
1 parent f10f62e commit d997162d09014531b8ebc3030b52dd197ce94da5 @akitaonrails committed Jul 13, 2012
Showing with 36 additions and 59 deletions.
  1. +1 −0 Gemfile
  2. +3 −0 Gemfile.lock
  3. +12 −0 app/controllers/application_controller.rb
  4. +1 −0 config/locales/pt-BR.yml
  5. +12 −0 config/locales/routes.yml
  6. +7 −59 config/routes.rb
View
@@ -21,6 +21,7 @@ group :assets do
end
gem 'jquery-rails'
+gem 'rails-translate-routes'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
@@ -85,6 +85,8 @@ GEM
activesupport (= 3.2.6)
bundler (~> 1.0)
railties (= 3.2.6)
+ rails-translate-routes (0.1.2)
+ activesupport (>= 3.1)
railties (3.2.6)
actionpack (= 3.2.6)
activesupport (= 3.2.6)
@@ -140,6 +142,7 @@ DEPENDENCIES
jquery-rails
pry-rails
rails (= 3.2.6)
+ rails-translate-routes
rspec-rails
sass-rails (~> 3.2.3)
sqlite3
@@ -1,3 +1,15 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ before_filter :set_locale
+ before_filter :set_locale_from_url
+
+ private
+
+ def set_locale
+ lang = request.env['HTTP_ACCEPT_LANGUAGE']
+ lang = lang[/^[a-z]{2}/]
+ lang = :"pt-BR" if lang == "pt"
+ I18n.locale = params[:locale] || lang
+ end
end
@@ -1,2 +1,3 @@
pt-BR:
hello: Olá Mundo
+
@@ -0,0 +1,12 @@
+en:
+ routes:
+pt-BR:
+ routes:
+ welcome: bemvindo
+ new: novo
+ edit: editar
+ destroy: destruir
+ password: senha
+ sign_in: login
+ users: usuarios
+ cancel: cancelar
View
@@ -1,62 +1,10 @@
I18nDemo::Application.routes.draw do
- get "welcome/index"
-
devise_for :users
-
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id))(.:format)'
+ get "welcome/index", as: "welcome"
+ root to: 'welcome#index'
end
+
+ActionDispatch::Routing::Translator.translate_from_file(
+ 'config/locales/routes.yml', {
+ prefix_on_default_locale: true,
+ keep_untranslated_routes: true })

0 comments on commit d997162

Please sign in to comment.