Flag switcher

This commit is contained in:
Yuki 2015-06-21 12:33:29 +05:30
parent a452cc36de
commit 409c82b5ed
15 changed files with 83 additions and 6 deletions

View File

@ -27,6 +27,7 @@
#= require settings #= require settings
#= require user #= require user
#= require report #= require report
#= require locale-box
# not required: # not required:
# _tree ./moderation # _tree ./moderation

View File

@ -0,0 +1,3 @@
$(document).on 'click', '#locale-switch', (event) ->
event.preventDefault()
$('#locales-panel').slideToggle()

View File

@ -3,6 +3,7 @@
*= require growl *= require growl
*= require jquery.guillotine *= require jquery.guillotine
*= require sweet-alert *= require sweet-alert
*= require flags
*= require_self *= require_self
*/ */

View File

@ -6,6 +6,7 @@ body {
background-color: #fafafa; background-color: #fafafa;
} }
@import "scss/flags";
@import "scss/variable"; @import "scss/variable";
@import "scss/generic"; @import "scss/generic";
@import "scss/answerbox"; @import "scss/answerbox";

View File

@ -0,0 +1,33 @@
.locales {
text-align: center;
#locales-panel {
position: relative;
display: none;
padding: 5px;
ul {
border-top: 1px solid #aaa;
margin: 0;
padding: 0;
padding-top: 5px;
width: 100%;
list-style: none;
display: inline-flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: center;
li {
margin: 5px 10px;
margin-top: 0;
flex: 0 0 auto;
* {
display: inline-block;
vertical-align: middle;
}
}
}
}
}

View File

@ -27,6 +27,15 @@ class ApplicationController < ActionController::Base
end end
end end
# Pirate English is not Puerto Rican English, you've doomed Puerto Rican English, Pixel.
if I18n.locale == 'en_pr'
I18n.locale = 'en_pirate'
if current_user.present?
current_user.locale = I18n.locale
current_user.save!
end
end
cookies[:lang] = I18n.locale #unless cookies[:allow_cookies].nil? # some EU cookie bullsh- cookies[:lang] = I18n.locale #unless cookies[:allow_cookies].nil? # some EU cookie bullsh-
end end

View File

@ -23,6 +23,7 @@
%body %body
= render 'layouts/header' = render 'layouts/header'
= yield = yield
= render 'shared/locales'
- if Rails.env.development? - if Rails.env.development?
%hr %hr
.container .container
@ -34,7 +35,6 @@
= `git rev-parse --short HEAD`.strip = `git rev-parse --short HEAD`.strip
%p.text-danger Debug params: %p.text-danger Debug params:
= debug params = debug params
- if Rails.env.production? - if Rails.env.production?
%noscript %noscript
%p %p

View File

@ -0,0 +1,12 @@
.container
.locales
%span
%a{href: '#', id: 'locale-switch'}
%i.fa.fa-globe
= t('views.locale.languages')
#locales-panel
%ul
- APP_LOCALES.each do |key, value|
%li
.flag{class: "flag-#{value[1]}"}
%a{href: "?hl=#{key}"}= value[0]

View File

@ -246,3 +246,5 @@
- za - za
- zm - zm
- zw - zw
- pirate
# - dizzle

View File

@ -26,3 +26,4 @@ uk: ua
he: il he: il
hi: in hi: in
vi: vn vi: vn
dizzle: us

View File

@ -7,7 +7,11 @@ I18n.with_locale("") do
Dir.glob(Rails.root.join("config/locales/*.yml")).each do |locale| Dir.glob(Rails.root.join("config/locales/*.yml")).each do |locale|
l = locale.split("/").last.split(".").first.downcase l = locale.split("/").last.split(".").first.downcase
if APP_LOCALES[l].nil? if APP_LOCALES[l].nil?
cc = l.split("-").last cc = l.split '-'
if cc.length == 1
cc = cc.first.split '_'
end
cc = cc.last
if flag_map.index(cc).nil? and not locale_map[cc].nil? if flag_map.index(cc).nil? and not locale_map[cc].nil?
cc = locale_map[cc] cc = locale_map[cc]
@ -15,10 +19,10 @@ I18n.with_locale("") do
begin begin
lang = I18n.translate("#{l}.language") lang = I18n.translate("#{l}.language")
lang = '' if lang.index "translation missing" lang = cc if lang.index "translation missing"
APP_LOCALES[l] = [lang, cc] APP_LOCALES[l] = [lang, cc]
rescue rescue
APP_LOCALES[l] = ['', cc] APP_LOCALES[l] = [cc, cc]
end end
end end
end end

@ -1 +1 @@
Subproject commit 9a8bf51754efbf00e433fc1726fb3b7aeaff2bb4 Subproject commit 678ba6ef4c1c6340a0a4802ac06bb5f050545be3

View File

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

BIN
public/flags/pirate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

View File

@ -1,7 +1,9 @@
.flag { .flag {
background-image: url("/flags.png"); background-image: url("/flags/main.png");
background-repeat: no-repeat;
width: 16px; width: 16px;
height: 11px; height: 11px;
background-position: -0px 16px;
} }
.flag-kz { .flag-kz {
background-position: -0px -0px; background-position: -0px -0px;
@ -746,3 +748,11 @@
background-position: -0px -2706px; background-position: -0px -2706px;
height: 12px; height: 12px;
} }
.flag-pirate {
background-image: url('/flags/pirate.png');
background-position: 0 0;
}
.flag-dizzle {
background-image: url('/flags/dizzle.png');
background-position: 0 0;
}