Skip to content

Commit

Permalink
i18n in all pages n links
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloschiavon committed May 23, 2014
1 parent d238332 commit 6575d33
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ 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 do
I18n.locale = params[:locale] || I18n.default_locale
end

def default_url_options
{ locale: I18n.locale }
end
end
8 changes: 6 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<header>
<div id="header-wrap">
<h1><%= link_to "colcho.net", root_path %> </h1>
<h1><%= link_to "colcho.net", root_path %></h1>
<nav>
<ul>
<li><%= link_to t('layout.rooms'), rooms_path %> </li>
Expand All @@ -38,6 +38,10 @@
<%= yield %>
</div>

<br /><br /><br />
<div id="content">
<%= link_to_unless I18n.locale == :en, "en", locale: :en %> |
<%= link_to_unless I18n.locale == :de, "pt", locale: :pt %>
</div>
</body>
</html>
29 changes: 28 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,31 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
rooms:
new:
title: New account
edit:
title: Edit room
show:
title: "Room: %{room_title}"
edit: Edit Room
location: "Location: %{location}"
description: "Description: %{description}"
users:
new:
title: Account
edit:
title: Edit account
show:
title: "Account: %{user_name}"
edit: Edit account
location: "Location: %{location}"
bio: "Bio: %{bio}"
links:
back: Back
layout:
rooms: Rooms
signup: New Account
general:
form_error: "There are errors on the form, please check"

4 changes: 2 additions & 2 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pt:
title: "Quarto: %{room_title}"
edit: Ediar quarto
location: "Localização: %{location}"
description: "Description: %{description}"
description: "Descrição: %{description}"
users:
new:
title: Cadastro
Expand All @@ -25,7 +25,7 @@ pt:
rooms: Quartos
signup: Cadastro
general:
form_error: "Há erros no formilário, favor verificar"
form_error: "Há erros no formulário, favor verificar"
activerecord:
models:
room: Quarto
Expand Down
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Rails.application.routes.draw do
resources :rooms
resources :users
scope "(:locale)", locale: /en|pt/ do
resources :rooms
resources :users
end

get '/:locale' => 'home#index', locale: /en|pt/
root 'home#index'

# The priority is based upon order of creation: first created -> highest priority.
Expand Down

0 comments on commit 6575d33

Please sign in to comment.