From 818b423609098a2b4adf1040e08ed73d5b378390 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Tue, 22 Oct 2024 10:39:21 +0200 Subject: [PATCH] Adds translations to the dummy app --- app/views/home/index.html.erb | 12 +++++ .../app/controllers/application_controller.rb | 6 +++ test/dummy/app/controllers/home_controller.rb | 8 ++++ .../app/views/layouts/application.html.erb | 30 ++++++++----- test/dummy/config/application.rb | 2 + test/dummy/config/environments/development.rb | 2 +- test/dummy/config/locales/de.yml | 13 ++++++ test/dummy/config/locales/en.yml | 44 +++++-------------- test/dummy/config/locales/it.yml | 13 ++++++ test/dummy/config/routes.rb | 2 + 10 files changed, 89 insertions(+), 43 deletions(-) create mode 100644 app/views/home/index.html.erb create mode 100644 test/dummy/app/controllers/home_controller.rb create mode 100644 test/dummy/config/locales/de.yml create mode 100644 test/dummy/config/locales/it.yml diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..f2b90db --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,12 @@ +

+ <%= t('first_paragraph') %> +

+ + + +

<%= t('second_paragraph') %>

+ + + + + diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index 7944f9f..442d5e9 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,4 +1,10 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base + around_action :switch_locale + + def switch_locale(&action) + locale = params[:locale] || I18n.default_locale + I18n.with_locale(locale, &action) + end end diff --git a/test/dummy/app/controllers/home_controller.rb b/test/dummy/app/controllers/home_controller.rb new file mode 100644 index 0000000..967f83d --- /dev/null +++ b/test/dummy/app/controllers/home_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class HomeController < ApplicationController + layout "layouts/application" + + def index + end +end diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index f72b4ef..160478e 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -1,15 +1,25 @@ - - Dummy - - <%= csrf_meta_tags %> - <%= csp_meta_tag %> + + Dummy + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> - <%= stylesheet_link_tag "application" %> - + + - - <%= yield %> - + + +
+ +
+
+ <%= yield %> +
+ diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 85e2fad..d0e3e62 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -23,5 +23,7 @@ class Application < Rails::Application # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + config.i18n.default_locale = :en + config.i18n.fallbacks = true end end diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 02fd2cf..418ba18 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -63,7 +63,7 @@ # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true - + config.action_view.debug_missing_translation = false # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/test/dummy/config/locales/de.yml b/test/dummy/config/locales/de.yml new file mode 100644 index 0000000..efdf31f --- /dev/null +++ b/test/dummy/config/locales/de.yml @@ -0,0 +1,13 @@ +de: + locales: + german: Deutsch + italian: Italienisch + english: Englisch + first_paragraph: Dies ist eine Dummy-App von moirai zum Testen. Wechseln Sie die Sprache über die Navigationsleiste. + second_paragraph: Fallback-Sprache ist Englisch. Die folgenden Schaltflächen wurden nur in einer Sprache definiert + buttons: + very: + much: + nested: + value: Klick mich + only_german: Nur Deutsch diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml index 8ca56fc..6f04cfc 100644 --- a/test/dummy/config/locales/en.yml +++ b/test/dummy/config/locales/en.yml @@ -1,33 +1,13 @@ -# 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: - hello: "Hello world" + locales: + german: German + italian: Italian + english: English + first_paragraph: This is moirai dummy app for testing. Switch language from the navbar. + second_paragraph: Fallback language is English. The following buttons have been defined only in one language + buttons: + very: + much: + nested: + value: Click me + only_english: Only English diff --git a/test/dummy/config/locales/it.yml b/test/dummy/config/locales/it.yml new file mode 100644 index 0000000..0cacbad --- /dev/null +++ b/test/dummy/config/locales/it.yml @@ -0,0 +1,13 @@ +it: + locales: + german: Tedesco + italian: Italiano + english: Inglese + first_paragraph: Questa è l'applicazione moirai dummy per i test. Cambi la lingua dalla barra di navigazione. + second_paragraph: La lingua di riserva è l'inglese. I seguenti pulsanti sono stati definiti solo in una lingua + buttons: + very: + much: + nested: + value: Cliccami + only_italian: Solo italiano diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 84ac9d7..026f7cc 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -2,4 +2,6 @@ Rails.application.routes.draw do mount Moirai::Engine => "/moirai" + + root to: "home#index" end