Skip to content

Commit 4eae3b3

Browse files
authored
Initial support for localization (#567)
2 parents d1645f5 + 27ecdd6 commit 4eae3b3

File tree

2 files changed

+83
-77
lines changed

2 files changed

+83
-77
lines changed

app/controllers/better_together/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
88

99
protect_from_forgery with: :exception
1010
before_action :check_platform_setup
11+
before_action :set_locale
1112

1213
rescue_from ActiveRecord::RecordNotFound, with: :render_404 # rubocop:todo Naming/VariableNumber
1314
rescue_from ActionController::RoutingError, with: :render_404 # rubocop:todo Naming/VariableNumber
@@ -54,6 +55,10 @@ def handle_error(exception)
5455
end
5556
end
5657

58+
def set_locale
59+
I18n.locale = params[:locale] || I18n.default_locale
60+
end
61+
5762
protected
5863

5964
def error_reporting(exception); end

config/routes.rb

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,97 @@
11
# frozen_string_literal: true
22

33
BetterTogether::Engine.routes.draw do # rubocop:todo Metrics/BlockLength
4-
# bt base path
5-
scope path: 'bt' do # rubocop:todo Metrics/BlockLength
6-
devise_for :users,
7-
class_name: BetterTogether.user_class.to_s,
8-
module: 'devise',
9-
skip: %i[unlocks omniauth_callbacks],
10-
path: 'users',
11-
path_names: {
12-
sign_in: 'sign-in',
13-
sign_out: 'sign-out',
14-
sign_up: 'sign-up'
15-
},
16-
defaults: { format: :html }
17-
18-
scope path: 'host' do
19-
# Add route for the host dashboard
20-
get '/', to: 'host_dashboard#index', as: 'host_dashboard'
21-
22-
resources :communities do
4+
scope '(:locale)', locale: /en|fr|es/ do # rubocop:todo Metrics/BlockLength
5+
# bt base path
6+
scope path: 'bt' do # rubocop:todo Metrics/BlockLength
7+
devise_for :users,
8+
class_name: BetterTogether.user_class.to_s,
9+
module: 'devise',
10+
skip: %i[unlocks omniauth_callbacks],
11+
path: 'users',
12+
path_names: {
13+
sign_in: 'sign-in',
14+
sign_out: 'sign-out',
15+
sign_up: 'sign-up'
16+
},
17+
defaults: { format: :html }
18+
19+
scope path: 'host' do
20+
# Add route for the host dashboard
21+
get '/', to: 'host_dashboard#index', as: 'host_dashboard'
22+
23+
resources :communities do
24+
resources :person_community_memberships
25+
end
26+
27+
resources :navigation_areas do
28+
resources :navigation_items
29+
end
30+
31+
resources :resource_permissions
32+
resources :roles
33+
34+
resources :pages
35+
resources :people
2336
resources :person_community_memberships
37+
resources :platforms
38+
39+
namespace :geography do
40+
resources :continents, except: %i[new create destroy]
41+
resources :countries
42+
resources :regions
43+
resources :region_settlements
44+
resources :settlements
45+
resources :states
46+
end
2447
end
2548

26-
resources :navigation_areas do
27-
resources :navigation_items
49+
resources :people, only: %i[update show edit], path: :p do
50+
get 'me', to: 'people#show', as: 'my_profile'
51+
get 'me/edit', to: 'people#edit', as: 'edit_my_profile'
2852
end
2953

30-
resources :resource_permissions
31-
resources :roles
32-
33-
resources :pages
34-
resources :people
35-
resources :person_community_memberships
36-
resources :platforms
37-
38-
namespace :geography do
39-
resources :continents, except: %i[new create destroy]
40-
resources :countries
41-
resources :regions
42-
resources :region_settlements
43-
resources :settlements
44-
resources :states
54+
resources :wizards, only: [:show] do
55+
# Custom route for wizard steps
56+
get ':wizard_step_definition_id', to: 'wizard_steps#show', as: :step
57+
patch ':wizard_step_definition_id', to: 'wizard_steps#update'
58+
# Add other HTTP methbetter-together/community-engine-rails/app/controllers/better_together/bt
4559
end
46-
end
4760

48-
resources :people, only: %i[update show edit], path: :p do
49-
get 'me', to: 'people#show', as: 'my_profile'
50-
get 'me/edit', to: 'people#edit', as: 'edit_my_profile'
61+
scope path: :w do
62+
scope path: :setup_wizard do
63+
get '/', to: 'setup_wizard#show', defaults: { wizard_id: 'host_setup' }, as: :setup_wizard
64+
get '/platform_details', to: 'setup_wizard_steps#platform_details',
65+
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :platform_details },
66+
as: :setup_wizard_step_platform_details
67+
post 'create_host_platform', to: 'setup_wizard_steps#create_host_platform',
68+
defaults: {
69+
wizard_id: 'host_setup',
70+
wizard_step_definition_id: :platform_details
71+
},
72+
as: :setup_wizard_step_create_host_platform
73+
get 'admin_creation', to: 'setup_wizard_steps#admin_creation',
74+
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :admin_creation },
75+
as: :setup_wizard_step_admin_creation
76+
post 'create_admin', to: 'setup_wizard_steps#create_admin',
77+
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :admin_creation },
78+
as: :setup_wizard_step_create_admin
79+
end
80+
end
5181
end
5282

53-
resources :wizards, only: [:show] do
54-
# Custom route for wizard steps
55-
get ':wizard_step_definition_id', to: 'wizard_steps#show', as: :step
56-
patch ':wizard_step_definition_id', to: 'wizard_steps#update'
57-
# Add other HTTP methbetter-together/community-engine-rails/app/controllers/better_together/bt
83+
if Rails.env.development?
84+
get '/404', to: 'application#render_404'
85+
get '/500', to: 'application#render_500'
5886
end
5987

60-
scope path: :w do
61-
scope path: :setup_wizard do
62-
get '/', to: 'setup_wizard#show', defaults: { wizard_id: 'host_setup' }, as: :setup_wizard
63-
get '/platform_details', to: 'setup_wizard_steps#platform_details',
64-
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :platform_details },
65-
as: :setup_wizard_step_platform_details
66-
post 'create_host_platform', to: 'setup_wizard_steps#create_host_platform',
67-
defaults: {
68-
wizard_id: 'host_setup',
69-
wizard_step_definition_id: :platform_details
70-
},
71-
as: :setup_wizard_step_create_host_platform
72-
get 'admin_creation', to: 'setup_wizard_steps#admin_creation',
73-
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :admin_creation },
74-
as: :setup_wizard_step_admin_creation
75-
post 'create_admin', to: 'setup_wizard_steps#create_admin',
76-
defaults: { wizard_id: 'host_setup', wizard_step_definition_id: :admin_creation },
77-
as: :setup_wizard_step_create_admin
78-
end
79-
end
80-
end
88+
# Catch-all route
89+
get '*path', to: 'pages#show', as: 'render_page', constraints: lambda { |req|
90+
!req.xhr? && req.format.html?
91+
}
8192

82-
if Rails.env.development?
83-
get '/404', to: 'application#render_404'
84-
get '/500', to: 'application#render_500'
93+
get '/bt' => 'static_pages#community_engine'
8594
end
86-
87-
# Catch-all route
88-
get '*path', to: 'pages#show', as: 'render_page', constraints: lambda { |req|
89-
!req.xhr? && req.format.html?
90-
}
91-
92-
get '/bt' => 'static_pages#community_engine'
93-
9495
# TODO: Re-enable the API routes when the API is in full use and actively being maintained to prevent security issues.
9596
# namespace :bt do
9697
# namespace :api, defaults: { format: :json } do

0 commit comments

Comments
 (0)