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 user
#= require report
#= require locale-box
# not required:
# _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 jquery.guillotine
*= require sweet-alert
*= require flags
*= require_self
*/

View File

@ -6,6 +6,7 @@ body {
background-color: #fafafa;
}
@import "scss/flags";
@import "scss/variable";
@import "scss/generic";
@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
# 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-
end

View File

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

View File

@ -26,3 +26,4 @@ uk: ua
he: il
hi: in
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|
l = locale.split("/").last.split(".").first.downcase
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?
cc = locale_map[cc]
@ -15,10 +19,10 @@ I18n.with_locale("") do
begin
lang = I18n.translate("#{l}.language")
lang = '' if lang.index "translation missing"
lang = cc if lang.index "translation missing"
APP_LOCALES[l] = [lang, cc]
rescue
APP_LOCALES[l] = ['', cc]
APP_LOCALES[l] = [cc, cc]
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 {
background-image: url("/flags.png");
background-image: url("/flags/main.png");
background-repeat: no-repeat;
width: 16px;
height: 11px;
background-position: -0px 16px;
}
.flag-kz {
background-position: -0px -0px;
@ -746,3 +748,11 @@
background-position: -0px -2706px;
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;
}