Rails i18n: lack of translation problem, locale not defined

I have a problem with a Rails 2.3.8 application. I use rails i18n to make a site in different languages. Everything works fine, everywhere except in one place.

After successful registration I:

flash[:notice] = t 'path.to.locale.key' 

Just like everywhere else.

But it does the following:

 translation missing: 'locale.path.to.locale.key' not found 

It does not seem to load the current locale (otherwise it will say "en", or "es", or something else, not "locale").

Any idea that might be causing this?

thanks

+4
source share
3 answers

Perhaps you will rewrite it somewhere in this yml file. You may nest too much. This key may have subkeys.

Remove all of this locale.yml and put just this message and see if it works.

The problem you encounter happens to me from time to time, and this is always what I messed up in the yml file.

+7
source

Try setting the default locale in your ApplicationController, for example using the before_filter parameter:

 I18n.locale = params[:locale] || 'en' 
+1
source

Well, this happened to me in the mail program classes after I upgraded to Rails 4.1. It worked correctly on Rails 3, and there were no changes to the yml files. Somehow i18n did not see the default locale. So I added this line to the mailer class to fix it.

  I18n.locale = I18n.default_locale class ProviderMailer < ActionMailer::Base include Resque::Mailer default from: APP_CONFIG.mailer.from def registration_email(provider) @provider = provider I18n.locale = I18n.default_locale @provider_url = "#{APP_CONFIG.base_url}/hizmetsgl/#{provider['_id']}" @howto_url = "#{APP_CONFIG.base_url}/hizmetverenler" mail(to: provider["business_email"], subject: t('provider_mailer.registration_email.subject')) end end 
0
source

Source: https://habr.com/ru/post/1337018/


All Articles