diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index 5ac8d33c..d74d372f 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -27,6 +27,7 @@ #= require settings #= require user #= require report +#= require locale-box # not required: # _tree ./moderation diff --git a/app/assets/javascripts/locale-box.coffee b/app/assets/javascripts/locale-box.coffee new file mode 100644 index 00000000..47ec3e39 --- /dev/null +++ b/app/assets/javascripts/locale-box.coffee @@ -0,0 +1,3 @@ +$(document).on 'click', '#locale-switch', (event) -> + event.preventDefault() + $('#locales-panel').slideToggle() diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index dff05d54..90fe114c 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -3,6 +3,7 @@ *= require growl *= require jquery.guillotine *= require sweet-alert + *= require flags *= require_self */ diff --git a/app/assets/stylesheets/base.css.scss b/app/assets/stylesheets/base.css.scss index 66320f71..a3c3a2e1 100644 --- a/app/assets/stylesheets/base.css.scss +++ b/app/assets/stylesheets/base.css.scss @@ -6,6 +6,7 @@ body { background-color: #fafafa; } +@import "scss/flags"; @import "scss/variable"; @import "scss/generic"; @import "scss/answerbox"; diff --git a/app/assets/stylesheets/scss/flags.scss b/app/assets/stylesheets/scss/flags.scss new file mode 100644 index 00000000..cee8e6e2 --- /dev/null +++ b/app/assets/stylesheets/scss/flags.scss @@ -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; + } + } + } + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 906d992b..2ccca445 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d381ce8f..bb116be0 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/shared/_locales.haml b/app/views/shared/_locales.haml new file mode 100644 index 00000000..70a187f5 --- /dev/null +++ b/app/views/shared/_locales.haml @@ -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] diff --git a/config/flags.yml b/config/flags.yml index 487f1475..d66e0366 100644 --- a/config/flags.yml +++ b/config/flags.yml @@ -246,3 +246,5 @@ - za - zm - zw +- pirate +# - dizzle diff --git a/config/hl_to_cc.yml b/config/hl_to_cc.yml index b7d6ff9a..348f8c94 100644 --- a/config/hl_to_cc.yml +++ b/config/hl_to_cc.yml @@ -26,3 +26,4 @@ uk: ua he: il hi: in vi: vn +dizzle: us diff --git a/config/late_initializers/flags.rb b/config/late_initializers/flags.rb index 7f189858..1e7dd934 100644 --- a/config/late_initializers/flags.rb +++ b/config/late_initializers/flags.rb @@ -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 diff --git a/config/locales b/config/locales index 9a8bf517..678ba6ef 160000 --- a/config/locales +++ b/config/locales @@ -1 +1 @@ -Subproject commit 9a8bf51754efbf00e433fc1726fb3b7aeaff2bb4 +Subproject commit 678ba6ef4c1c6340a0a4802ac06bb5f050545be3 diff --git a/public/flags.png b/public/flags/main.png similarity index 100% rename from public/flags.png rename to public/flags/main.png diff --git a/public/flags/pirate.png b/public/flags/pirate.png new file mode 100644 index 00000000..0d7f4c90 Binary files /dev/null and b/public/flags/pirate.png differ diff --git a/vendor/assets/stylesheets/flags.css b/vendor/assets/stylesheets/flags.css index e69d0dfc..766ae6b1 100644 --- a/vendor/assets/stylesheets/flags.css +++ b/vendor/assets/stylesheets/flags.css @@ -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; +}