0

I'm trying to persist the URLs with the specific language (i.e. en, pt, etc.) but after setting it up, I keep getting 'en-US' instead of 'en'. (i.e. localhost:3000/en-us/apps instead of localhost:3000/en/apps). Not sure where I can change this setting since I figured it would default to my fallbacks.

I've prefixed my routes with the following:

scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do

    root :to => "home#index"

    get 'omniauth/:provider' => 'omniauth#localized', as: :localized_omniauth

    devise_for :users, skip: :omniauth_callbacks, :controllers => { :registrations => "registrations", :sessions => "sessions", :passwords => "passwords" }

    resources :submissions.....

ApplicationController.rb

def default_url_options(options = {})
    {locale: I18n.locale}
end

def set_locale
    I18n.locale = params[:locale] ||
                  request.env['rack.locale'] ||
                  I18n.default_locale
end

Application.rb

config.i18n.default_locale = :en
config.i18n.available_locales = [:en, :pt]
config.i18n.fallbacks = true
2fools
  • 111
  • 2
  • 10

1 Answers1

0

You're missing setting I18n.locale:

def default_url_options(options={})
  { locale: I18n.locale }
end

Detect and set locale for current request, depending on your input data:

before_filter :set_locale

def set_locale
  if defined?(params) && params[:locale]
    I18n.locale = params[:locale]
  elsif current_user && current_user.language_id.present?
    I18n.locale = current_user.language.code
  end
  I18n.locale ||= I18n.default_locale
end
blelump
  • 3,233
  • 1
  • 16
  • 20
  • I've edited my answer because I currently do have a set_locale method but not sure if I need to replace it with what you put or add in yours – 2fools Nov 11 '14 at 22:20
  • I'm getting an undefined local variabe or method 'extract_locale_from_accept_language_header" and then when I remove that I'm getting the same error for "valid_languages" – 2fools Nov 11 '14 at 22:27
  • I've slightly changed `set_locale` method. It is weird that first condition didn't match, because it should. What returns `I18n.available_locales`? – blelump Nov 11 '14 at 22:35
  • I18n.available_locales returns [:en, :pt]. – 2fools Nov 11 '14 at 23:15
  • When I tried the new set_locale method, I'm still getting the same error http://localhost:3000/en-US/apps – 2fools Nov 11 '14 at 23:15