Class: ViewComponent::Translatable::I18nBackend
- Inherits:
-
I18n::Backend::Simple
- Object
- I18n::Backend::Simple
- ViewComponent::Translatable::I18nBackend
- Defined in:
- lib/view_component/translatable.rb
Constant Summary collapse
- EMPTY_HASH =
{}.freeze
Instance Method Summary collapse
-
#initialize(i18n_scope:, load_paths:) ⇒ I18nBackend
constructor
A new instance of I18nBackend.
-
#load_translations ⇒ Object
Ensure the Simple backend won’t load paths from ::I18n.load_path.
- #scope_data(data) ⇒ Object
- #store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
Constructor Details
#initialize(i18n_scope:, load_paths:) ⇒ I18nBackend
Returns a new instance of I18nBackend.
36 37 38 39 |
# File 'lib/view_component/translatable.rb', line 36 def initialize(i18n_scope:, load_paths:) @i18n_scope = i18n_scope.split(".") @load_paths = load_paths end |
Instance Method Details
#load_translations ⇒ Object
Ensure the Simple backend won’t load paths from ::I18n.load_path
42 43 44 |
# File 'lib/view_component/translatable.rb', line 42 def load_translations super(@load_paths) end |
#scope_data(data) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/view_component/translatable.rb', line 46 def scope_data(data) @i18n_scope.reverse_each do |part| data = { part => data} end data end |
#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
53 54 55 |
# File 'lib/view_component/translatable.rb', line 53 def store_translations(locale, data, = EMPTY_HASH) super(locale, scope_data(data), ) end |