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
Return Nil if there is no translation for palette_ params #58008
Return Nil if there is no translation for palette_ params #58008
Conversation
smart: true | ||
) | ||
if i18n_params != localized_params | ||
unless i18n_params.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be to have default: {}
and then remove the condition altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not process the content if translations aren't available. We would only iterate over the parameters when there's a translation, avoiding errors such as the one found in honeybadger.
smart: true | ||
) | ||
if i18n_params != localized_params | ||
unless i18n_params.nil? | ||
localized_params&.each do |param| | ||
param_key = param['name'].to_sym |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would still need a next unless param.key?('name')
here to fix the honeybadger error in the thread... I guess... since we are here already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My theory is that if there is no name param, the string won't be picked up in the sync, and there won't ever be a translation available, returning nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's still going to render incorrectly... they need to fix the content, imo. we should not mitigate it by assuming the inappropriate metadata can happen.
This is a good change for the sake of keeping the code logical. Technically, it does not matter too much. The default would always yield some kind of dict that differs from localized_params and then it would just kind of fail to do anything with it leading to it to return the right thing anyway. But that's obviously very confusing... but nothing that's causing a user-facing issue. |
In PR #49395 I added a method to localize the parameters in programming expressions.
In that implementation, I assumed the default value returned when the I18n API did not find any localized content, was the same as the original content (an Array of Hashes).
However, after a regression in the content, we analyzed more in-depth what the
I18n.t
method was returning and found out only the first element of the array was return when defaulting.Instead, I decided to return
Nil Value
by default (when no localized content is found) and then, when the localized content is notNil
, merge the localized parameters with the non-localized ones.Localized params look like this:
{:"[height]"=>{:type=>"número"}, :"[width]"=>{:type=>"número"}}
PR Checklist: