Module: SolidusAdmin::BaseComponent::InheritableTranslations

Included in:
SolidusAdmin::BaseComponent
Defined in:
app/components/solidus_admin/base_component.rb

Instance Method Summary collapse

Instance Method Details

#build_i18n_backendObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/solidus_admin/base_component.rb', line 17

def build_i18n_backend
  return if compiled?

  # We need to load the translations files from the ancestors so a component
  # can inherit translations from its parent and is able to overwrite them.
  translation_files = ancestors.reverse_each.with_object([]) do |ancestor, files|
    if ancestor.is_a?(Class) && ancestor < ViewComponent::Base
      files.concat(ancestor.sidecar_files(%w[yml yaml].freeze))
    end
  end

  # In development it will become nil if the translations file is removed
  self.i18n_backend = if translation_files.any?
    ViewComponent::Translatable::I18nBackend.new(
      i18n_scope: i18n_scope,
      load_paths: translation_files
    )
  end
end