I have a few tables that contain translations. In order to simplify access to all translations and have them cached, I managed, after the initialization of Rails to read the table and inject their content in the translation store.
#store translations in the I18n store
I18n.available_locales.each do |lang|
storage_hash = {:text => {}, :permalink => {}}
Translation.where(:translatable_type => self.name, :language=> lang).each do |c|
storage_hash[:text][c.translatable_id.to_s] = c.text
storage_hash[:permalink][c.translatable_id.to_s] = c.permalink
end
I18n.backend.store_translations(lang, self.name.downcase => storage_hash)
end
It works great, but in dev, sometimes the translation store is reset and I loose the translations I previously added.
Does it happen in production? Is there a callback I could use to repopulate my translation? Or is there a better way to do what I want?