Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks t('.something')? 😭 #6

Closed
andrewculver opened this issue Dec 8, 2020 · 7 comments
Closed

Breaks t('.something')? 😭 #6

andrewculver opened this issue Dec 8, 2020 · 7 comments

Comments

@andrewculver
Copy link
Contributor

andrewculver commented Dec 8, 2020

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
@andrewculver
Copy link
Contributor Author

This is a hard one. 😑

@andrewculver
Copy link
Contributor Author

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.

@domchristie
Copy link
Contributor

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 😬

@andrewculver
Copy link
Contributor Author

@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.

@domchristie
Copy link
Contributor

my solution to this problem doesn't support unnamed block content anymore

controversial! 😝

@domchristie
Copy link
Contributor

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 🤷‍♂️

@andrewculver
Copy link
Contributor Author

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.

andrewculver added a commit that referenced this issue Feb 11, 2021
Initial attempt at fixing the `t` helper prefix. Fixes #6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants