Conversation
BlakeWilliams
left a comment
There was a problem hiding this comment.
I had a few comments/questions but so far this is looking great!
Thank you for adding a benchmark too!
elia
left a comment
There was a problem hiding this comment.
Just a few comments to address concerns and questions (still didn't had the time to finish up the PR, fix specs, remove debug statements etc.)
5f4e502 to
2fb94b0
Compare
BlakeWilliams
left a comment
There was a problem hiding this comment.
I had a few small questions/comments, but looking good!
docs/index.md
Outdated
| </div> | ||
| ``` | ||
|
|
||
| ##### Translations |
There was a problem hiding this comment.
Can we mark this as experimental similar to how we've marked V2 as experimental?
The goal is to include this for V3 but don't want to commit to a specific API/behavior until then.
lib/view_component/base.rb
Outdated
| # | ||
| # The provided array of extensions is expected to contain | ||
| # strings starting without the "dot", example: `["erb", "haml"]` | ||
| def sidecar_files(extensions) |
There was a problem hiding this comment.
I'm not sure that we want to make this part of the public API just yet. Thoughts on prefixing this with an _ and making it private, or moving it back to the compiler?
| <p class="isolated"><%= t("isolated_translation", default: "This won't be used") %></p> | ||
| <p class="missing"><%= t("translations_component.title", default: "Not the original value") %></p> | ||
| <p class="helpers"><%= helpers.t("translations_component.title", default: "Not the original value") %></p> | ||
| <p class="global"><%= ::I18n.t("translations_component.title", default: "Not the original value") %></p> |
There was a problem hiding this comment.
This was a little confusing since I didn't know we had an existing translations file that had a component namespace. Thoughts on using some other namespace that's more general?
There was a problem hiding this comment.
I cleaned it up a bit, hope is more understandable now.
joelhawksley
left a comment
There was a problem hiding this comment.
Some docs feedback. Thanks again for your hard work on this feature 😄
eaac036 to
35e95e4
Compare
elia
left a comment
There was a problem hiding this comment.
I set both APIs as experimental, I think _sidecar_files might come useful for other plugins as well, as it encapsulates what is considered a sidecar file by ViewComponent.
| <p class="isolated"><%= t("isolated_translation", default: "This won't be used") %></p> | ||
| <p class="missing"><%= t("translations_component.title", default: "Not the original value") %></p> | ||
| <p class="helpers"><%= helpers.t("translations_component.title", default: "Not the original value") %></p> | ||
| <p class="global"><%= ::I18n.t("translations_component.title", default: "Not the original value") %></p> |
There was a problem hiding this comment.
I cleaned it up a bit, hope is more understandable now.
docs/index.md
Outdated
| <p><%= t("hello") %></p> | ||
| ``` | ||
|
|
||
| To access global translations, explicitly mention `helper` or `I18n`: |
There was a problem hiding this comment.
Would it be possible to have t also access global translations? I think it's a little awkward to re-define t with a local scope and then expect consumers to know when to use the helpers prefix.
218a982 to
90a3bb7
Compare
elia
left a comment
There was a problem hiding this comment.
@joelhawksley the fallback to the global I18n has been added, I also updated the benchmark to reflect the different scenarios, and a note in the docs to explain how to reach translation keys shadowed by the sidecar file.
|
This is looking great @elia! 🙌 I'm a bit late to the party, but what about using a dot as a way to disambiguate between local and global I18n?
en:
hello: "Hello world!"To access the local translation:
<p><%= t(".hello") %></p>To access a global translation <%= t("my.global.translation") %>So if a global translation is shadowed by the sidecar file you just have to drop the dot:
<%= t("hello") %>Seems very Railsy to me but maybe I'm missing something? |
joelhawksley
left a comment
There was a problem hiding this comment.
Just leaving a small docs tweak here. I think @Spone might be on to something with the local syntax proposal 🤔
|
@Spone @joelhawksley that's surely feasible, although I have some concerns about that:
I don't necessarily oppose doing that, but I lean more toward keeping things simple, adding features later, if required. One of the first things I tried was to include the original |
I totally agree. Let's just keep in mind that changing how locale lookup works in a future version of For the sake of the argument, I'm taking the point of view of a developer using
|
Probably doesn't matter, the worst that can happen is that we change the title of this PR 😄 @Spone I've been sitting on your comment for 3 days, pondering how could we possibly do that in a way that makes sense for the consumer of this API and the code that needs to implement it. Below I tried to summarize what we're trying to accomplish and the problems we need to overcome. Desired featuresIt seems like what we want is:
Current issuesI would add the following as issues, but @BlakeWilliams and @joelhawksley please check if these are things we don't want to worry too much about:
Open questions
Especially if we want to use the "lazy lookup" I'd say we need to rely on Rails, which in turn means that we need to keep the sidecar translations global either respecting the I'm interested in your thoughts on this, but also on alternative approaches I might have missed. |
|
@Spone @BlakeWilliams I just pushed an additional commit with an attempt at isolated lazy path translations for components. I also dropped support for multiple translations using the What else can change to have this ready for a merge? / What other criteria should it meet? |
16321bc to
1969256
Compare
joelhawksley
left a comment
There was a problem hiding this comment.
👋🏻 leaving a naming comment here. I'm going to defer to @BlakeWilliams for the technical review.
docs/index.md
Outdated
|
|
||
| ##### Translations (experimental) | ||
|
|
||
| To use experimental support for `I18n` translations, include `ViewComponent::SidecarI18n`: |
There was a problem hiding this comment.
What do you think about renaming this to Translatable be more idiomatic Ruby?
| To use experimental support for `I18n` translations, include `ViewComponent::SidecarI18n`: | |
| To use experimental support for `I18n` translations, include `ViewComponent::Translatable`: |
There was a problem hiding this comment.
That's a great suggestion, it fits well with existing modules 👍
|
@elia I have a small favor to ask you ❤️ Might you be willing to open a separate PR introducing |
|
@joelhawksley sure, will take just a minute 👍 |
|
@joelhawksley there you go #676 OT is there a reason for sticking with bundler v1? |
I think it's due to how many Ruby/Rails versions we support in CI? |
BlakeWilliams
left a comment
There was a problem hiding this comment.
I had two small questions, but otherwise this looks great!
|
Thanks for your work on this PR @elia! |
|
Thanks for making the final changes and merging! |
Summary
A proof of concept for #552 (comment) with I18n translations that are only accessible from within the component.
There's still some work to do, but if the general idea is ok this PR can replace #552.
One thing to note is that this code has not been tried on any real-world production app.
Other Information