Skip to content

Commit

Permalink
Route translator
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Nov 14, 2021
1 parent 017bc24 commit 3e30403
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ gem 'slim-rails', '~> 3.3'
# App monitoring
gem 'newrelic_rpm', '~> 8.1'

gem 'route_translator', path: '~/dev/route_translator'

group :development, :test do
gem 'byebug', '~> 11.1', platforms: %i[mri mingw x64_mingw]
gem 'factory_bot_rails', '~> 6.2'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
PATH
remote: ../route_translator
specs:
route_translator (11.0.0)
actionpack (>= 5.2, < 7.0)
activesupport (>= 5.2, < 7.0)
addressable (~> 2.7)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -304,6 +312,7 @@ DEPENDENCIES
puma (~> 5.5)
rack-timeout (~> 0.6.0)
rails (= 6.1.4.1)
route_translator!
rspec-rails (~> 5.0)
rubocop (~> 1.22)
rubocop-performance (~> 1.12)
Expand Down
5 changes: 5 additions & 0 deletions app/views/pages/home.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ ul.list-inline.lead
li.list-inline-item
| Font Awesome (SVG)
small.text-muted< 5.15.4

- I18n.with_locale(:it) do
= link_to support_contact_path
br
= link_to newsletter_subscription_path
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.i18n.available_locales = %i[en it]
config.i18n.default_locale = :en
config.i18n.fallbacks = [I18n.default_locale, {
it: :en
}]

config.generators do |g|
g.javascripts false
g.stylesheets false
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/route_translator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

RouteTranslator.config do |config|
config.force_locale = true
config.disable_fallback = true
end
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ en:
shared:
navbar:
toggle_navigation: "Toggle Navigation"
routes:
newsletter_subscription: 'newsletter'
support_contact: 'contact'
76 changes: 76 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# 'true': 'foo'
#
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.

it:
app_name: "Rails 6 Starter App"
meta_description: "An opinionated starter application based on Ruby 3.0, Rails 6.1, Webpack 4, Yarn, and Bootstrap 5"
shared:
navbar:
toggle_navigation: "Toggle Navigation"
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# 'true': 'foo'
#
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.

en:
app_name: "Rails 6 Starter App"
meta_description: "An opinionated starter application based on Ruby 3.0, Rails 6.1, Webpack 4, Yarn, and Bootstrap 5"
shared:
navbar:
toggle_navigation: "Toggle Navigation"
routes:
support_contact: 'contatti'
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@

root 'pages#home'
get :hello_world, to: 'pages#hello_world'

localized do
get 'newsletter_subscription', to: 'newsletter_subscriptions#new', as: :newsletter_subscription
post 'newsletter_subscription', to: 'newsletter_subscriptions#create', as: :create_newsletter_subscription
get 'support_contact', to: 'support_contacts#new', as: :support_contact
post 'support_contact', to: 'support_contacts#create', as: :create_support_contact
end
end

0 comments on commit 3e30403

Please sign in to comment.