Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added pt-br Locale

  • Loading branch information...
commit 27490278a6ff425fc90d101cfee0c849e220c343 1 parent 92b88e1
@iobridge authored
View
20 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
View
2  config/application.rb
@@ -28,7 +28,7 @@ class Application < Rails::Application
# 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)
View
5 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
+GET_SUPPORT = true
+
+# allow only these additional locales (use downcase, easier to parse)
+ALLOWED_LOCALES = ['pt-br']
View
1  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?"
Please sign in to comment.
Something went wrong with that request. Please try again.