Skip to content

Commit

Permalink
Add flags to I18n #7
Browse files Browse the repository at this point in the history
The flags indicate the  current language and offers link to inverse
language.

- Add pry for Ruby Debug;
- Create methods to list links;
- Create logic with JavaScript to style of flags.
  • Loading branch information
fernahh committed Oct 17, 2015
1 parent 0bff007 commit d058a93
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem "pry-meta", require: false
gem "middleman", "~>3.3.10"
gem "redcarpet", "~> 3.2.3"
gem "middleman-syntax", "~> 2.0.0"
Expand Down
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
awesome_print (1.6.1)
byebug (5.0.0)
columnize (= 0.9.0)
celluloid (0.16.0)
timers (~> 4.0.0)
chunky_png (1.3.4)
coderay (1.1.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
columnize (0.9.0)
compass (1.0.3)
chunky_png (~> 1.2)
compass-core (~> 1.0.2)
Expand Down Expand Up @@ -47,6 +52,7 @@ GEM
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
method_source (0.8.2)
middleman (3.3.12)
coffee-script (~> 2.2)
compass (>= 1.0.0, < 2.0.0)
Expand Down Expand Up @@ -93,6 +99,21 @@ GEM
tilt (~> 1.4.1)
padrino-support (0.12.5)
activesupport (>= 3.1)
pry (0.10.2)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.2.0)
byebug (~> 5.0)
pry (~> 0.10)
pry-meta (0.0.10)
awesome_print
pry
pry-byebug
pry-remote
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
rack (1.6.4)
rack-livereload (0.3.16)
rack
Expand All @@ -105,6 +126,7 @@ GEM
redcarpet (3.2.3)
rouge (1.9.1)
sass (3.4.16)
slop (3.6.0)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -135,4 +157,5 @@ DEPENDENCIES
middleman-gh-pages (~> 0.0.3)
middleman-livereload (~> 3.1.0)
middleman-syntax (~> 2.0.0)
pry-meta
redcarpet (~> 3.2.3)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Without these references, no doubt the guide could not be possible. Thanks to al
+ High Perfomance JavaScript, *by Nicholas Zakas*.
+ Secrets of JavaScript Ninja, *by John Resig and Bear Bibeault*.
Resources:
- Flag Icons by [Muharrem Şenyıl on Dribble](https://dribbble.com/shots/1211759-Free-195-Flat-Flags)
## Maintainer
Luiz Fernando Rodrigues - http://blog.fernahh.com.br
Expand Down
39 changes: 39 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,45 @@ def chapters(post)
end.select { |x| x }
end

def pt_url(url)
current_url = url

if current_url.include?("semantics")
result_url = "/guia/a-semantica.html"
elsif current_url.include?("accessibility")
result_url = "/guia/a-acessibilidade.html"
elsif current_url.include?("the-css")
result_url = "/guia/o-css.html"
elsif current_url.include?("the-javascript")
result_url = "/guia/o-javascript.html"
else
result_url = "/"
end

result_url
end

def english_url(url)
current_url = url

if current_url == "/" || current_url.include?("guia")
if current_url.include?("semantica")
result_url = "/guide/the-semantics.html"
elsif current_url.include?("acessibilidade")
result_url = "/guide/the-accessibility.html"
elsif current_url.include?("o-css")
result_url = "/guide/the-css.html"
elsif current_url.include?("o-javascript")
result_url = "/guide/the-javascript.html"
else
result_url = "/en"
end
else
result_url = current_url
end

result_url
end
end

# Sintax
Expand Down
Binary file added source/assets/images/brazil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/assets/images/united-kingdom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions source/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
//= require 'smooth-scroll.js/dist/js/smooth-scroll.min'
//= require 'vendor/i18n'
//= require 'vendor/page_scroll_indicator'
//= require 'smooth-scroll.js/dist/js/smooth-scroll.min'
//= require 'lib/langs'
//= require 'lib/smooth'
//= require 'lib/scroll_indicator'

var app = app || {};

app.run = function() {
this.scrollIndicator();
this.smooth();
this.langs();

if (!document.getElementsByTagName("body")[0].className.match(/index/)) {
this.scrollIndicator();
}
}

window.onload = function() {
Expand Down
5 changes: 5 additions & 0 deletions source/assets/javascripts/lib/langs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var app = app || {};

app.langs = function() {
I18n.init();
}
35 changes: 35 additions & 0 deletions source/assets/javascripts/vendor/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var I18n = I18n || {};

I18n.init = function() {
var langs = new Array("/en", "guide", "guia"),
pathname = window.location.pathname;

for (var i = 0; i < langs.length; i++) {
if (pathname.indexOf(langs[i]) > -1) {
if (langs[i] === "/en" || langs[i] === "guide") {
this.setEnglish();
} else {
this.setPortuguese();
}
}
};

if (pathname === "/") {
this.setPortuguese();
}
}

I18n.setEnglish = function() {
this.addDisableClassLang("lang-pt");
document.documentElement.lang = "en";
}

I18n.setPortuguese = function() {
this.addDisableClassLang("lang-en");
document.documentElement.lang = "pt-BR";
}

I18n.addDisableClassLang = function(el) {
this.el = document.getElementById(el);
this.el.className += " lang--is-disable";
}
1 change: 1 addition & 0 deletions source/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import "modules/home";
@import "modules/button";
@import "modules/progress_bar";
@import "modules/lang";

// Guide
@import "guide/navigation";
Expand Down
20 changes: 20 additions & 0 deletions source/assets/stylesheets/guide/_navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
border-right: 4px solid darken($semantics-color, 3%);
}

.guide_the-semantics & {
background-color: $semantics-color;
border-right: 4px solid darken($semantics-color, 3%);
}

@include attention() {
background-color: $semantics-color;
border-color: darken($semantics-color, 3%);
Expand All @@ -86,6 +91,11 @@
border-right: 4px solid darken($accessibility-color, 5%);
}

.guide_the-accessibility & {
background-color: $accessibility-color;
border-right: 4px solid darken($accessibility-color, 5%);
}

@include attention() {
background-color: $accessibility-color;
border-right: 4px solid darken($accessibility-color, 5%);
Expand All @@ -95,6 +105,11 @@
.css-link {
@include svg("css3-logo");

.guide_the-css & {
background-color: $css3-color;
border-right: 4px solid darken($css3-color, 5%);
}

.guia_o-css & {
background-color: $css3-color;
border-right: 4px solid darken($css3-color, 5%);
Expand All @@ -121,6 +136,11 @@
border-right: 4px solid darken($js-color, 5%)
}

.guide_the-javascript & {
background-color: $js-color;
border-right: 4px solid darken($js-color, 5%)
}

@include respond-to(em($bp-medium)) {
background-size: 50px;
}
Expand Down
47 changes: 47 additions & 0 deletions source/assets/stylesheets/modules/_lang.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.langs {
position: fixed;
top: $base-whitespace;
right: $base-whitespace;
z-index: 2;

margin-top: 0;
padding-left: 0;

list-style-type: none;
text-align: center;
}

.langs-item {
display: inline-block;
}

.lang {
display: block;
width: 36px;
height: 25px;

background-repeat: no-repeat;
@include background-size(contain);
@include hide-text();
pointer-events: none;
}

.lang--en {
background-image: image-url("united-kingdom.png");
}

.lang--pt-br {
background-image: image-url("brazil.png");
}

.lang--is-disable {
@include opacity(.5);
@include filter(grayscale(1));
@include transition(all 300ms ease-in-out);
pointer-events: initial;

@include attention() {
@include opacity(1);
@include filter(grayscale(0));
}
}
9 changes: 9 additions & 0 deletions source/layouts/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
</head>

<body class="<%= page_classes %>">
<ul class="langs">
<li class="langs-item">
<a href="<%= pt_url(current_page.url) %>" title="Leia a versão em Português" id="lang-pt" class="lang lang--pt-br">Versão em Português.</a>
</li>
<li class="langs-item">
<a href="<%= english_url(current_page.url) %>" title="Read in English" id="lang-en" class="lang lang--en">English version.</a>
</li>
</ul>

<main id="main">
<%= yield %>
</main>
Expand Down

0 comments on commit d058a93

Please sign in to comment.