i18n-active_record
i18n-active_record copied to clipboard
Missing translations with default values as option
Hi there, I am using Missing Module, everything works well without default option, like this
I18n.t('hi')
however I need to save as well in translations table, missing translations although exists default values as option, for example in the following line codes, records are not created
I18n.t('hello', default: 'Hello')
I18n.t('hello', locale: 'es', default: 'Hello')
I18n.t('hello', locale: 'ja', default: 'Hello')
How do I achieve this? This is my configuration:
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
I18n.available_locales = [:en, :es, :ko, :ja]
I18n.default_locale = :en
I18n::Backend::ActiveRecord.configure do |config|
config.cache_translations = Rails.env.production?
end
if Translation.table_exists?
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Cache)
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
I18n::Backend::Chain.send(:include, I18n::Backend::ActiveRecord::Missing)
I18n.backend = I18n::Backend::Chain.new(I18n.backend, I18n::Backend::Simple.new)
end
Unfortunately, the current implementation of the Missing
module doesn't allow saving default values.
So I am afraid there is no way to achieve this without changing the implementation.
The idea of the Missing
module is to create blank records for missing translations so translators can review them, so I am not entirely sure that saving default values by default would be right.
But this can be an optional behaviour configured with the I18n::Backend::ActiveRecord.configure
Feel free to send a pull request, otherwise, I will try to look at it when I have some time