Skip to content

Commit 0025c04

Browse files
committed
Add spec coverage for missing translations handling
1 parent dcab63a commit 0025c04

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

admin/app/components/solidus_admin/base_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def missing_translation(key, options)
4343

4444
logger.debug " [#{self.class}] Missing translation: #{keys.join('.')}"
4545

46-
if options[:locale] != :en
46+
if (options[:locale] || I18n.default_locale) != :en
4747
t(key, **options, locale: :en)
4848
else
4949
"translation missing: #{keys.join('.')}"

admin/config/initializers/view_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
clear = "\e[0m"
1111

1212
ActiveSupport::Notifications.subscribe("render.view_component") do |*args|
13-
next unless args.last[:name].starts_with?("SolidusAdmin::")
13+
next unless args.last[:name]&.starts_with?("SolidusAdmin::")
1414

1515
event = ActiveSupport::Notifications::Event.new(*args)
1616
SolidusAdmin::BaseComponent.logger.debug \

admin/spec/components/solidus_admin/base_component_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ def call
4848
expect(SolidusAdmin::Foo::Bar::Component.new.stimulus_id).to eq("foo--bar")
4949
end
5050
end
51+
52+
describe "missing translations" do
53+
it "logs and shows the full chain of keys" do
54+
debug_logs = []
55+
56+
allow(Rails.logger).to receive(:debug) { debug_logs << _1 }
57+
58+
component_class = stub_const("Foo::Component", Class.new(described_class){ erb_template "" })
59+
component = component_class.new
60+
render_inline(component)
61+
translation = component.translate("foo.bar.baz")
62+
63+
expect(translation).to eq("translation missing: en.foo.bar.baz")
64+
expect(debug_logs).to include(%{ [Foo::Component] Missing translation: en.foo.bar.baz})
65+
end
66+
end
5167
end

0 commit comments

Comments
 (0)