With
config.i18n.fallbacks = { :fr => :en }
and
class Thing < ActiveRecord::Base
translates :name
end
and
I18n.local = :en
and
Thing.create! :name => 'broken'
is there anyway of preventing Globalize3 from returning 'broken' for name when the locale is set to :fr?
I want fallbacks, but I don't want my French form to be prepopulated with the English translation.
I don't want a multi-locale form. I don't want to prefix every attribute name with _en. I just want to tell globalize to return a blank translation.
I'd hoped
thing(:fr)
or something similar would exist.
I've tried all sorts of hackery - trying to temporarily disable fallbacks whilst the form is populated etc. I could write the form myself (I'm using Formtastic) or nest the translation but it feels like I'm missing something.
Forgive me if I've failed to convey but it 5:30am.
Anyone have any pointers?
Update
It looks like Globalize3 automatically builds a translation for the current locale if it doesn't exist. As the values for each are nil they fallback. If I loop through them and set them all to an empty string before my form accesses them I get the desired affect.
I'm using inherited resources hence my model instance is called resource. I put this in a helper and run it before the form is populated:
if resource.respond_to?(:translations) && request[:action] == 'edit'
resource.translated_attribute_names.each do |attribute_name|
resource[attribute_name] = '' unless resource.translation[attribute_name].present?
end
end
Feels like I'm fighting the gem or missing a trick.