Skip to content

Commit

Permalink
Adds translations to the dummy app
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse committed Oct 22, 2024
1 parent dd0cd97 commit 818b423
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 43 deletions.
12 changes: 12 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>
<%= t('first_paragraph') %>
</p>

<button><%= t('buttons.very.much.nested.value') %></button>

<p><%= t('second_paragraph') %></p>

<button><%= t('buttons.very.much.nested.only_german') %></button>
<button><%= t('buttons.very.much.nested.only_english') %></button>
<button><%= t('buttons.very.much.nested.only_italian') %></button>

6 changes: 6 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/dummy/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class HomeController < ApplicationController
layout "layouts/application"

def index
end
end
30 changes: 20 additions & 10 deletions test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<head>
<title>Dummy</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "application" %>
</head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>

<body>
<%= yield %>
</body>

<body>
<header>
<nav>
<%=link_to t('locales.german'), root_path(locale: :de) %>
<%=link_to t('locales.english'), root_path(locale: :en) %>
<%=link_to t('locales.italian'), root_path(locale: :it) %>
</nav>
</header>
<main>
<%= yield %>
</main>
</body>
</html>
2 changes: 2 additions & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/dummy/config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 12 additions & 32 deletions test/dummy/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/dummy/config/locales/it.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Rails.application.routes.draw do
mount Moirai::Engine => "/moirai"

root to: "home#index"
end

0 comments on commit 818b423

Please sign in to comment.