Temporarily disable i18n backups in Rails

I18n reserve loaded:

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) 

Any idea now to temporarily disable it? I have forms where I want to edit various language versions, and with the backup, I get fields with the default language if this translation is not already presented.

+7
ruby-on-rails ruby-on-rails-3 internationalization
source share
4 answers

You can pass the fallback: true parameter to I18n.t , which will prevent I18n from looking for other locales ( see implementation here ). But this is probably not part of the public API ...

+4
source share

You can pass :fallback => 'false' to your I18n.translate calls, but this is not part of the public API.

Another way you can try is this:

 I18n.available_locales.each do |al| I18n.fallbacks.merge!({al => [al]}) end 

This will basically make a backup for each available language include only yourself. So, if the transfer is not found by itself, then there is no return to return.

However, you need to find a way to restore the default backup.

You can do this, for example, using an instruction, for example:

 I18n.available_locales.each do |al| I18n.fallbacks.merge!({al => [al, I18n.default_locale]}) end 
+2
source share

If someone is still wondering how to do this, you can change I18n.fallbacks on the fly:

 def foo I18n.fallbacks[:at] = [:at] # do stuff with I18n#t ensure I18n.fallbacks[:at] = [:at, :de] # or whatever is was before end 

Not sure how safe this is.

+1
source share

Do you use globalization?

I use I18n reserve for my system strings and globalize3 for my attribute translations. I want system strings to return back, but not attributes. I just turned off the backups for globalization with just a little monkey patch:

configurations / Initializers / i18n.rb:

 require "i18n/backend/fallbacks" I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) # monkey patch globalize3 to not use fallbacks module Globalize def self.fallbacks? false end end 
0
source share

All Articles