Breaks `t('.something')`? ๐ญ
Closed this issue ยท 7 comments
It looks like the magic of t('.something')
is broken because the yield
that causes it to execute is in a different view. This is pretty sad, TBH.
For example, in app/views/some_class/_index.html.erb
:
<%= render 'shared/box' do |p| %>
<% p.content_for :title do %>
<%= t(".contexts.something.header") %>
<% end %>
<% p.content_for :description do %>
<%= t(".contexts.something.description") %>
<% end %>
<% end %>
Yields:
translation missing: en.shared.box.contexts.something.header
It should have been:
en.some_class.index.contexts.something.header
This is a hard one. ๐
I've solved this, but tagging @domchristie because my solution to this problem doesn't support unnamed block content anymore... and I'm not sure there is anything I can do about it. Will tidy this up and push up a PR tomorrow.
Is the non-shorthand version that bad? (e.g. t("some_class.index.contexts.something.header")
) and if it needs to be dynamic, would something like t("#{controller_name}.#{action_name}.contexts.something.header")
work? Obviously not as clean, but I feel like there might be more cases like this (given that we're playing around with rendering contexts), and handling everyone might be ๐ฌ
@domchristie Yeah, I had the same thought, but I don't like the idea that we'd be breaking something people are used to, and in my own project I noticed that use of the shorthand is keeping the views really, really clean, especially in applications with large domain models with lots of name spacing, etc.
my solution to this problem doesn't support unnamed block content anymore
controversial! ๐
I suppose the downside is that it loses the natural progression of going from "layout" partials to Nice Partials, e.g.
<%= render 'section' do %>
<p>Lorem ipsum</p>
<% end %>
<%= render 'section' do |p| %>
<% p.content_for :heading, 'Hello, World' %>
<p>Lorem ipsum</p>
<% end %>
This would require an update to every template to wrap <p>Lorem ipsum</p>
. Trade-offs, I guess ๐คทโโ๏ธ
Hmm... actually, it's possible my solution to the t
helper thing could be expanded to cover the entire block if I could figure out where the block is being yielded to.