diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e630af974..a5aaf5c01 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,6 +21,7 @@ //= require d3 //= require c3 //= require c3ext +//= require qp //= require app //= require_tree . @@ -30,6 +31,7 @@ var initialize_modules = function() { App.Votes.initialize(); App.Tags.initialize(); App.Stats.initialize(); + App.LocaleSwitcher.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/locale_switcher.js.coffee b/app/assets/javascripts/locale_switcher.js.coffee new file mode 100644 index 000000000..2bd88b8ef --- /dev/null +++ b/app/assets/javascripts/locale_switcher.js.coffee @@ -0,0 +1,19 @@ +App.LocaleSwitcher = + + href_with_params: (query_params) -> + loc = window.location + + loc.protocol + "//" + loc.hostname + + (if loc.port then ':' + loc.port else '') + + loc.pathname + + loc.hash + + '?' + $.param(query_params) + + initialize: -> + $('.js-locale-switcher').on 'change', -> + query_params = window.getQueryParameters() + query_params['locale'] = $(this).val() + window.location.assign(App.LocaleSwitcher.href_with_params(query_params)) + + + diff --git a/app/assets/javascripts/qp.js b/app/assets/javascripts/qp.js new file mode 100644 index 000000000..5e2b4f02d --- /dev/null +++ b/app/assets/javascripts/qp.js @@ -0,0 +1,12 @@ +/* + * getQueryParameters.js + * Copyright (c) 2014 Nicholas Ortenzio + * The MIT License (MIT) + * + */ + +window.getQueryParameters = function(str) { + str = (str || document.location.search).replace(/(^\?)/,''); + if(!str) { return {}; } + return str.split("&").reduce(function(o,n){n=n.split('=');o[n[0]]=n[1];return o},{}); +}; diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 00028ac56..88ed47d65 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -186,7 +186,7 @@ header { } } - .language { + .locale { float: none; text-align: center; @@ -196,7 +196,7 @@ header { } .external-links { - @extend .language; + @extend .locale; @media (min-width: 480px) { float: right; diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cee6db199..11e4cae8c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,7 +14,13 @@ module ApplicationHelper home_page? ? '' : 'results' end - def available_locales_to_switch - I18n.available_locales - [I18n.locale] + def available_locale_options_for_select + options_for_select(available_locales_array, I18n.locale) end + + private + def available_locales_array + I18n.available_locales.map { |loc| [I18n.t('locale', locale: loc), loc] } + end + end diff --git a/app/views/layouts/_admin_header.html.erb b/app/views/layouts/_admin_header.html.erb index ffd7d34f4..13424e5e8 100644 --- a/app/views/layouts/_admin_header.html.erb +++ b/app/views/layouts/_admin_header.html.erb @@ -1,15 +1,7 @@
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 53899221e..b47de5f24 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,15 +1,7 @@