Class: ViewComponent::Translatable::I18nBackend

Inherits:
I18n::Backend::Simple
  • Object
show all
Defined in:
lib/view_component/translatable.rb

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(scope:, load_paths:) ⇒ I18nBackend

Returns a new instance of I18nBackend.



71
72
73
74
# File 'lib/view_component/translatable.rb', line 71

def initialize(scope:, load_paths:)
  @__vc_i18n_scope = scope.split(".").map(&:to_sym)
  @__vc_load_paths = load_paths
end

Instance Method Details

#load_translationsObject

Ensure the Simple backend won’t load paths from ::I18n.load_path



77
78
79
# File 'lib/view_component/translatable.rb', line 77

def load_translations
  super(@__vc_load_paths)
end

#scope_data(data) ⇒ Object



81
82
83
84
85
86
# File 'lib/view_component/translatable.rb', line 81

def scope_data(data)
  @__vc_i18n_scope.reverse_each do |part|
    data = {part => data}
  end
  data
end

#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object



88
89
90
# File 'lib/view_component/translatable.rb', line 88

def store_translations(locale, data, options = EMPTY_HASH)
  super(locale, scope_data(data), options)
end