From 028887f1a25e226b7aa9b5a3cbdd51ae3b68fb23 Mon Sep 17 00:00:00 2001 From: Meutel Date: Tue, 4 Aug 2015 19:57:48 +0200 Subject: [PATCH] i18n WIP --- app/controllers/application_controller.rb | 6 ++++++ app/views/static_pages/home.html.erb | 4 ++-- config/locales/en.yml | 2 ++ config/locales/fr.yml | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 config/locales/fr.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..cdc2f59 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,10 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + before_action :set_locale + + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end end diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 00df61b..11a091b 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -1,6 +1,6 @@
-

Library

-

Browse <%= @books_count %> books

+

<%= t :library %>

+

<%= t :welcome_count, count: @books_count %>

<%= link_to "Books", books_path, class: "btn btn-lg btn-primary", remote: true %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0653957..30f3f0f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,3 +21,5 @@ en: hello: "Hello world" + library: "Library" + welcome_count: "Browse %{count} books" diff --git a/config/locales/fr.yml b/config/locales/fr.yml new file mode 100644 index 0000000..a836b2a --- /dev/null +++ b/config/locales/fr.yml @@ -0,0 +1,4 @@ +fr: + hello: "Bonjour" + library: "Bibliothèque" + welcome_count: "Parcourir les %{count} livres"