From 27490278a6ff425fc90d101cfee0c849e220c343 Mon Sep 17 00:00:00 2001 From: iobridge Date: Sun, 16 Oct 2011 02:54:31 -0400 Subject: [PATCH] Added pt-br Locale --- app/controllers/application_controller.rb | 20 ++++++++++++++------ config/application.rb | 2 +- config/initializers/constants.rb | 5 ++++- config/locales/en.yml | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3265385..d9e5a00 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,12 +7,20 @@ class ApplicationController < ActionController::Base before_filter :set_variables # set up some variables across the entire application - def set_variables - # hard code locale as english - I18n.locale = 'en' - # sets timezone for current user, all DateTime outputs will be automatically formatted - Time.zone = current_user.time_zone if current_user - end + def set_variables + @locale ||= get_locale + I18n.locale = ALLOWED_LOCALES.include?(@locale) ? @locale : I18n.default_locale + # sets timezone for current user, all DateTime outputs will be automatically formatted + Time.zone = current_user.time_zone if current_user + end + + # get the locale, but don't fail if header value doesn't exist + def get_locale + locale = get_header_value('HTTP_ACCEPT_LANGUAGE') + # only look for 'pt-br' as first 5 letters, can make more robust in future if other languages are needed + locale = locale[0..4].downcase if locale + return locale + end private diff --git a/config/application.rb b/config/application.rb index 684b22d..ae2d478 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,7 +28,7 @@ module Thingspeak # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + config.i18n.default_locale = :en # JavaScript files you want as :defaults (application.js is always included). # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 627a987..b3f9493 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,3 +1,6 @@ # allow updates via HTTP GET by setting this to true; # set to false to only allow updates via HTTP POST -GET_SUPPORT = true \ No newline at end of file +GET_SUPPORT = true + +# allow only these additional locales (use downcase, easier to parse) +ALLOWED_LOCALES = ['pt-br'] \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index ac07253..d31ccf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -123,6 +123,7 @@ en: email: "Email" email_form_add: "Add Email" featured_channels: "Featured Channels" + features: "Features" field: "Field" footer: "This is the footer message." forgot: "Forgot your password?"