diff --git a/Gemfile b/Gemfile index bc5cfeda..fedd1690 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 1280452e..8037d0ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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: @@ -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) diff --git a/config/application.rb b/config/application.rb index 8654c9af..27c578f5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/initializers/route_translator.rb b/config/initializers/route_translator.rb new file mode 100644 index 00000000..7d9e3dc2 --- /dev/null +++ b/config/initializers/route_translator.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +RouteTranslator.config do |config| + config.force_locale = true + config.disable_fallback = true +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 63b9e605..a9051f4f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -35,3 +35,6 @@ en: shared: navbar: toggle_navigation: "Toggle Navigation" + routes: + newsletter_subscription: 'newsletter' + support_contact: 'contact' diff --git a/config/locales/it.yml b/config/locales/it.yml new file mode 100644 index 00000000..eb4997fe --- /dev/null +++ b/config/locales/it.yml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 1954bf42..7d2bc9b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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