Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing translations with default values as option #139

Open
nitxal opened this issue Oct 5, 2022 · 1 comment
Open

Missing translations with default values as option #139

nitxal opened this issue Oct 5, 2022 · 1 comment

Comments

@nitxal
Copy link

nitxal commented Oct 5, 2022

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
@timfjord
Copy link
Collaborator

timfjord commented Oct 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants