Getting I18n :: InvalidLocale (: ru is not a valid language): as requested by rails ajax

When I load the page it doesn't show any locale error, but when I make an ajax request, I get

I18n::InvalidLocale (:en is not a valid locale):
  i18n (0.7.0) lib/i18n.rb:284:in `enforce_available_locales!'
  i18n (0.7.0) lib/i18n.rb:151:in `translate'
  i18n (0.7.0) lib/i18n.rb:168:in `translate!'

      

// ajax request

$.ajax({
  url: "/unlock_company",
  type: "GET",
  dataType: 'json',
  success: function(data) {
    console.log(data);
  }
});

      

In the controller

def unlock_company
 respond_to do |format|
  format.json {render json: { :result => '@result'}}
 end
end

      

In the application.rb file

config.i18n.enforce_available_locales = true
I18n.config.enforce_available_locales = true
config.i18n.available_locales = [:"en-US"]

      

+3


source to share


3 answers


Try using String instead of character for long locale name:



config.i18n.available_locales = ["en-US"]

      

+1


source


I'm not sure if this is a solution, but it might be worth looking into. A simple test. You don't specify which version of Rails you are using, but as of Rails 4-ish they are deprecated:

config.i18n.enforce_available_locales = true
I18n.config.enforce_available_locales = true

      



I18n had an error in the past causing the same error you are seeing. The error / bug was caused by using .enforce_available_locales. More details here .

Since .enforce_available_locales is set to true by default, you should remove it from application.rb, and as a side effect, it may resolve the error.

+1


source


I have the same problem, I add these lines to my application.rb file and it solved the problem:

config.i18n.fallbacks = true
config.i18n.enforce_available_locales = false

      

0


source







All Articles