-
Notifications
You must be signed in to change notification settings - Fork 20
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
Update devolved nations component to accept type property #2337
Conversation
539683c
to
e602f16
Compare
@@ -15,7 +17,7 @@ | |||
<% if devolved_nations_helper.nations_with_urls.any? %> | |||
<%= content_tag :ul, class: "govuk-list govuk-!-margin-top-1 govuk-!-margin-bottom-0" do -%> | |||
<% devolved_nations_helper.nations_with_urls.each do |k, v| %> | |||
<%= content_tag(:li, link_to("Guidance for #{t("components.devolved_nations.#{k}")}", v[:alternative_url], class: "govuk-link")) %> | |||
<%= content_tag(:li, link_to("#{type} for #{t("components.devolved_nations.#{k}")}", v[:alternative_url], class: "govuk-link")) %> |
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.
Can we do anything to clean up the translations here? It seems we only ever have publication or guidance, is that right? Ideally we would be translating the whole phrase Guidance|Publication for |Scotland|Wales|Ireland as you can't guarantee word order in other languages, and also here we're not translating the word "for" at all.
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 can see consultations also probably gets passed but doesn't seem to be rendered as they don't seem to have alternatives - but we could have consultations as a third string type, maybe. We could probably have placeholders for the language and so would need only the 3 phrases
Consultation for %{country}
Publication for %{country}
Guidance for %{country}
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.
Can we do anything to clean up the translations here? It seems we only ever have publication or guidance, is that right?
I think so. There's lots of different schema names that could potentially be passed to the component but despite looking at quite a few examples I’ve only found either "Publication" or "Guidance".
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 can see consultations also probably gets passed but doesn't seem to be rendered as they don't seem to have alternatives
Similar to above, I can’t seem to find any consultations - do you know of any examples I could take a look at?
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.
We could probably have placeholders for the language and so would need only the 3 phrases Consultation for %{country} Publication for %{country} Guidance for %{country}
The only problem I can see with this approach is that I’m passing in a type that’s already been translated in government_frontend
e.g.
Maybe I should do the translation in components
instead?
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.
All the consultations I found looked like this: https://www.gov.uk/government/consultations/open-access-restriction-at-castle-beeny-farm-2-how-to-comment - basically they're all saying "This applies to England" and offering no alternatives. But I'm by no means certain I'm catching everything.
I think it would make sense to do the translation in the component wholly, it is after all what does the presentation - taking data to make that decision feels cleaner. Do ask around for a second opinion though as I'm not confident that this is definitely the way we should go. We do need to handle the whole string, though, I think, and if the calling app is responsible for the strings you start to question the point of the component, which is why I'm leaning that way.
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'll investigate some more and see if anything comes up. I've been trawling through this list here: https://www.gov.uk/search/policy-papers-and-consultations?page=1 but so far nothing.
I think you're right too - i'd wondered about it myself beforehand but since we already had the translations in government_frontend
decided to leave it there.
I'll get another opinion but does seem a better approach to move it all to the component.
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.
There's lots of different schema names that could potentially be passed to the component but despite looking at quite a few examples I’ve only found either "Publication" or "Guidance".
I think it's because the overarching type is Publication for a whole raft of content types - I don't know that getting more granular is necessarily expected as publication is understood internally and relatively clear to the end user in context.
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 think it would make sense to do the translation in the component wholly, it is after all what does the presentation - taking data to make that decision feels cleaner. Do ask around for a second opinion though...
Second opinion here: https://gds.slack.com/archives/CARGH33JS/p1633606644023200
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've now created a helper to handle the translation and to keep the view a bit tidier. The only issue I have is that it seems necessary to translate a key twice but this seems to be a common issue in Ruby / Rails https://stackoverflow.com/questions/14306469/use-another-i18n-key-in-an-i18n-interpolation.
Changes include:
- Handle different types:
- Publication (publication - also the default)
- Guidance (guidance and detailed_guide)
- Consultation (consultation if any exist)
- Update tests to include different types that can be passed the the component including invalid or nil types
- Update docs to include:
- New use cases and
- To replace references to "Guidance" as "Alternative content" (except where "Guidance" is the actual type)
e602f16
to
cadaa94
Compare
cadaa94
to
9b54a82
Compare
I see Percy is reporting a few errors. As far as I can see the errors are just differences in -
|
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.
Nice work.
def alternative_content_text(name) | ||
nation = I18n.t("components.devolved_nations.#{name}") | ||
|
||
if I18n.exists?("components.devolved_nations.type.#{@type}") |
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.
Nice safety check!
assert_select ".gem-c-devolved-nations > ul > li:nth-child(1) > [href='/guidance-northern-ireland']", text: "Guidance for Northern Ireland" | ||
end | ||
|
||
it "renders a devolved nations component, which applies to one nation, with individual pubilcation available, when invalid type provided, correctly" do |
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.
🆒
9b54a82
to
d4d7d1c
Compare
What
https://trello.com/c/4SUBn4mb/880-update-devolved-nations-component
Why
Currently, all alternative content are labelled as guidance e.g.
However, not all alternative content is guidance. We should refer to "Publication" as the default but allow a type property to be passed to the component.
Visual Changes
Anything else
Prerequisite for alphagov/government-frontend#2240