Support i18n key at translation of value in submit tag#26799
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @chancancode (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
|
Could you explain better what is not supported now? For what I could see by the code i18n is supported |
|
I try to write code example. class RichBlog::PoorPost << ActiveRecord::Base
enden:
activerecord:
models:
rich_blog/poor_post: blog post
attributes:
rich_blog/poor_post:
title: post title
helpers:
submit:
rich_blog_poor_post:
create: Post my post
|
rafaelfranca
left a comment
There was a problem hiding this comment.
Thanks! It make sense to me. Could you add a test case and a CHANGELOG entry?
There was a problem hiding this comment.
Instead of adding a new lookup can we add the :"helpers.submit.#{object.model_name.i18n_key}.#{key}" if it object responds to model_name and defaults << :"helpers.submit.#{object_name}.#{key}" if it doesn't?
There was a problem hiding this comment.
What should I think about specification of :as option?
If :as option is given to form_for method, is it prior than actual model name in translation?
For example,
class Blog::Post << ActiveRecord::Base
endform_for @blog_post, as: :my_post do |f|
f.submit
enden:
helpers:
submit:
"blog/post":
create: Post blog post
my_post:
create: Post my postThen which value is expected Post blog post or Post my post?
There was a problem hiding this comment.
Instead of adding a new lookup can we add the :"helpers.submit.#{object.model_name.i18n_key}.#{key}" if it object responds to model_name and defaults << :"helpers.submit.#{object_name}.#{key}" if it doesn't?
Got it! |
8a93d72 to
3bdd0f5
Compare
|
i18n-debug is very useful to debug/visualize which translations are being looked up by Rails Just in case you didn't know this handy helper 🤓 |
|
@rafaelfranca Could you reply to #26799 (comment) ? |
|
@rafaelfranca Any update on this? |
3bdd0f5 to
ce9661b
Compare
There was a problem hiding this comment.
Consider :as and :scope option is the top priority for i18n key.
There was a problem hiding this comment.
Not modified existing tests.
There was a problem hiding this comment.
Add new test about code that I implemented.
|
@rafaelfranca Could you review again? |
|
@rafaelfranca Hello. Any updates on this? |
|
@rafaelfranca Hello, what should I do for this? |
|
Sorry, I dropped the ball here. Can you squash your commits and rebase this branch? The code looks good. |
|
Thank you 😄 Got it! |
…odule_name/class_name Currently submit_tag value translation does not support i18n key style locale key. It confuses me a bit because many other components support i18n key style locale key. I added i18n key style locale key support to submit tag.
ce9661b to
e579c74
Compare
|
Wow! I'm so happy because this is a my first time Rails contribution! |
|
Thank YOU! And welcome to the list of contributors http://contributors.rubyonrails.org/contributors/rui-onodera/commits |
|
@deraru Thanks for your contribution. I'm wondering why this feature does not work as expected for me ... I got the following namespaced model In the view helper for the default submit value the code does not reach this line: https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/form_helper.rb#L2682 This line would produce the expected lookup key That's why the code proceeds with the line I'm by far not familiar enough with Rails to come up with a better condition in line https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/form_helper.rb#L2681 but the current one seems to be too exclusive. Maybe @rafaelfranca can assist? I'm looking forward to your reply. Thanks a lot in advance. I'm using Rails 7.0.4.2 btw. |
|
For example line https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/form_helper.rb#L2674 could be changed from |
Summary
Currently submit tag value translation does not support i18n key style
locale key.
It confuses me a bit because many other components support i18n key
style locale key.
I added i18n key style locale key support to submit tag.