Skip to content

Commit

Permalink
Merge pull request #5590 from solidusio/elia/vc-3.9
Browse files Browse the repository at this point in the history
[admin] Require ViewComponent v3.9 with inheritable translations
  • Loading branch information
elia committed Jan 9, 2024
2 parents 7bab27b + 23e87cc commit 64f6a58
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
25 changes: 0 additions & 25 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,6 @@ def icon_tag(name, **attrs)
render component("ui/icon").new(name: name, **attrs)
end

module InheritableTranslations
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
end

# Can be removed once https://github.com/ViewComponent/view_component/pull/1934 is released
extend InheritableTranslations unless Gem::Version.new(ViewComponent::VERSION::STRING) >= Gem::Version.new("3.9")

def missing_translation(key, options)
keys = I18n.normalize_keys(options[:locale] || I18n.locale, key, options[:scope])

Expand Down
2 changes: 1 addition & 1 deletion admin/solidus_admin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ Gem::Specification.new do |s|
s.add_dependency 'solidus_core', '> 4.2'
s.add_dependency 'stimulus-rails', '~> 1.2'
s.add_dependency 'turbo-rails', '~> 1.4'
s.add_dependency 'view_component', '~> 3.3'
s.add_dependency 'view_component', '~> 3.9'
end

0 comments on commit 64f6a58

Please sign in to comment.