Last active
August 29, 2015 14:22
-
-
Save theareba/38700bdb70a7eb612860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>LingualSwitch</title> | |
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | |
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body> | |
<%= render 'layouts/nav' %> | |
<div class="container"> | |
<%= yield %> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
protect_from_forgery with: :exception | |
before_action :set_locale | |
def set_locale | |
I18n.locale = extract_locale_from_tld || I18n.default_locale | |
end | |
def extract_locale_from_tld | |
parsed_locale = request.host.split('.').last | |
I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
en: | |
header: "English Page" | |
page_description: "This is the English version of the multilingual application. Note the domain." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fr: | |
header: "Français page" | |
page_description: "Ceci est la version anglaise de l'application multilingue. Notez le nom de domaine." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'bootstrap-sass' | |
gem 'i18n' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="spacer"></div> | |
<div class="container text-center jumbotron"> | |
<h1><%= I18n.t('header') %></h1> | |
<p><%= I18n.t('page_description') %></p> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="spacer"></div> | |
<div class="container text-center jumbotron"> | |
<h1>English Page</h1> | |
<p>This is the English version of the multilingual application. Note the domain.</p> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127.0.0.1 lingualswitch.en | |
127.0.0.1 lingualinterrupteur.fr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
root 'static_pages#home' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment