summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-15 17:14:26 -0700
committerelijah <elijah@riseup.net>2015-06-15 17:14:26 -0700
commit83a9cadbb13bd2292c7d064d40721fa5f64119fb (patch)
tree294c13678a0514634a6817428d2c656738c14e52 /app
parent12ab515ecd448f98ff006e30a93e43626183b6d0 (diff)
added CommonLanguages gem
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/leap.scss12
-rw-r--r--app/controllers/application_controller.rb36
-rw-r--r--app/controllers/pages_controller.rb2
-rw-r--r--app/helpers/core_helper.rb12
-rw-r--r--app/views/layouts/_footer.html.haml3
5 files changed, 47 insertions, 18 deletions
diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss
index 13560c0..35f0ed4 100644
--- a/app/assets/stylesheets/leap.scss
+++ b/app/assets/stylesheets/leap.scss
@@ -269,6 +269,18 @@ html, body {
#footer {
padding-top: $footer-gutter;
height: $footer-height - $footer-border-width;
+ .locales {
+ text-align: center;
+ margin-bottom: 15px;
+ a {
+ padding: 4px;
+ &.active {
+ font-weight: bold;
+ background-color: #eee;
+ border-radius: 4px;
+ }
+ }
+ }
.full-height {
text-align: center;
line-height: $footer-height - $footer-border-width;
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index ff291f2..58e6f83 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -38,41 +38,30 @@ class ApplicationController < ActionController::Base
##
#
- # URL paths for which we don't enforce the locale as the prefix of the path.
- #
- NON_LOCALE_PATHS = /^\/(assets|webfinger|.well-known|rails|key|[0-9]+)($|\/)/
-
- #
# Before filter to set the current locale. Possible outcomes:
#
# (a) do nothing for certain routes and requests.
# (b) if path already starts with locale, set I18n.locale and default_url_options.
# (c) otherwise, redirect so that path starts with locale.
#
- # If the locale happens to be the default local, no paths are prefixed with the locale.
- #
def set_locale
- if request.method == "GET" && request.format == 'text/html' && request.path !~ NON_LOCALE_PATHS
- if params[:locale] && LOCALES_STRING.include?(params[:locale])
+ if request_may_have_locale?(request)
+ if CommonLanguages::available_code?(params[:locale])
I18n.locale = params[:locale]
- update_default_url_options
else
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
- update_default_url_options
if I18n.locale != I18n.default_locale
redirect_to url_for(params.merge(:locale => I18n.locale))
end
end
- else
- update_default_url_options
end
end
- def update_default_url_options
- if I18n.locale != I18n.default_locale
- self.default_url_options[:locale] = I18n.locale
+ def default_url_options(options={})
+ if request_may_have_locale?(request)
+ { :locale => I18n.locale }
else
- self.default_url_options[:locale] = nil
+ { :locale => nil }
end
end
@@ -104,4 +93,17 @@ class ApplicationController < ActionController::Base
response.headers["Expires"] = "0"
end
+ private
+
+ #
+ # URL paths for which we don't enforce the locale as the prefix of the path.
+ #
+ NON_LOCALE_PATHS = /^\/(assets|webfinger|.well-known|rails|key|[0-9]+)($|\/)/
+
+ #
+ # For some requests, we ignore locale determination.
+ #
+ def request_may_have_locale?(request)
+ request.method == "GET" && request.format == 'text/html' && request.path !~ NON_LOCALE_PATHS
+ end
end
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index c477b7c..e0f39e3 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -12,7 +12,7 @@ class PagesController < ApplicationController
private
def page_name
- request.path.sub(/^\/(#{MATCH_LOCALE}\/)?/, '')
+ request.path.sub(/^\/(#{CommonLanguages.match_available}\/)?/, '')
end
end
diff --git a/app/helpers/core_helper.rb b/app/helpers/core_helper.rb
index 46e8fa4..f34d2f2 100644
--- a/app/helpers/core_helper.rb
+++ b/app/helpers/core_helper.rb
@@ -17,4 +17,16 @@ module CoreHelper
APP_CONFIG[:service_levels].present? && APP_CONFIG[:service_levels].detect{|k,v| v['rate'].present?}
end
+ #
+ # a bunch of links to the different languages that are available.
+ #
+ def locales_links
+ CommonLanguages.available.collect { |lang|
+ link_to(lang.name,
+ {:action => params[:action], :controller => params[:controller], :locale => lang.code},
+ {:class => (lang.code == I18n.locale ? 'locale active' : 'locale')}
+ )
+ }.join(" ").html_safe
+ end
+
end
diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml
index de53667..f502ddb 100644
--- a/app/views/layouts/_footer.html.haml
+++ b/app/views/layouts/_footer.html.haml
@@ -1,3 +1,6 @@
+- if CommonLanguages.available.size > 1
+ .locales
+ = locales_links
.full-height
= link_to icon('home') + t(:home), home_path
= link_to icon('eye-close') + t(:privacy_policy), privacy_policy_path