Skip to content

Instantly share code, notes, and snippets.

@theareba
Last active August 29, 2015 14:22
Show Gist options
  • Save theareba/38700bdb70a7eb612860 to your computer and use it in GitHub Desktop.
Save theareba/38700bdb70a7eb612860 to your computer and use it in GitHub Desktop.
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<%= I18n.locale.eql?(:en) ? link_to("French", 'http://lingualinterrupteur.fr:3000')
: link_to("English", 'http://lingualswitch.en:3000') %>
</button>
<%= link_to "LingualSwitch", root_path, class: "navbar-brand" %>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<%= I18n.locale.eql?(:en) ? link_to(image_tag('fr.jpg', class: "navbar-brand"), 'http://lingualinterrupteur.fr:3000')
: link_to(image_tag('eng.png', class: "navbar-brand"), 'http://lingualswitch.en:3000') %>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<!-- Switching menu comes here -->
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<!-- Switching menu comes here -->
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!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>
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
en:
header: "English Page"
page_description: "This is the English version of the multilingual application. Note the domain."
fr:
header: "Français page"
page_description: "Ceci est la version anglaise de l'application multilingue. Notez le nom de domaine."
gem 'bootstrap-sass'
gem 'i18n'
<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>
<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>
127.0.0.1 lingualswitch.en
127.0.0.1 lingualinterrupteur.fr
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