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

El 1975 hook up translation link #429

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kmahern
Copy link
Contributor

@kmahern kmahern commented Feb 11, 2025

What does this pull request do?

  • This pr adds fuctionality to the language_switcher link, to allow the user to toggle between english and welsh.
  • It uses the inbuilt django set_language view to set the cookie/headers/do the translation
  • It uses javascript to submit the language_switcher_form. The language_switcher_link should be hidden for users without javascript enabled on their browser.
  • This pr also contains a fix for allowed_hosts that was preventing the post to set_language/triggering a 400 response (with thanks to @psweeting1), it also reverts an earlier change to fala_staging that had been made to fix allowed_hosts that is no longer required.

Any other changes that would benefit highlighting?

Intentionally left blank.

Checklist

  • Provided JIRA ticket number in the title, e.g. "LGA-152: Sample title"

@kmahern kmahern force-pushed the el-1975-hook-up-translation-link branch 8 times, most recently from c3ec7de to 6ff2840 Compare February 11, 2025 13:39
@kmahern kmahern changed the base branch from el-1975-hook-up-translation-button to main February 11, 2025 13:39
@kmahern kmahern force-pushed the el-1975-hook-up-translation-link branch 2 times, most recently from 146bc3b to 2f59850 Compare February 12, 2025 08:26
@kmahern kmahern force-pushed the el-1975-hook-up-translation-link branch from e210460 to 711624e Compare February 12, 2025 09:53
@kmahern kmahern force-pushed the el-1975-hook-up-translation-link branch from a86092e to b94213c Compare February 12, 2025 10:54
@kmahern kmahern marked this pull request as ready for review February 12, 2025 11:18
@kmahern kmahern requested a review from a team as a code owner February 12, 2025 11:18
Copy link
Contributor

@willc-work willc-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - feels more straight forward than I was expecting.

def translation_link(self, request):
user_language = request.COOKIES.get("django_language", "en")
if user_language == "cy":
return "<a class='govuk-body govuk-link' id='language_switcher_link'>English</a> / Cymraeg"
Copy link
Contributor

@psweeting1 psweeting1 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spotted a small problem. These anchor links do not have href. Because of that the link doesn't show a cursor icon when you hover over them.

An tag without an href attribute fails accessibility because it is not recognised as an interactive element by screen readers, keyboard navigation, and assistive technologies.

You will need to add href="#" However the anchor link may try and go to the URL, so below in the JS I have added some code to help prevent that.

Copy link
Contributor

@psweeting1 psweeting1 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're also missing some other needed attributes

These are all on DWP component so you can find anything you've missed and need there.

  hreflang="cy"
      lang="cy"
      rel="alternate"
      aria-label="Newid yr iaith ir Gymraeg"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks @psweeting1 have made these updates. I think the form seems to work without the javascript to prevent the link behaviour but this is definitely worth testing.

psweeting1
psweeting1 previously approved these changes Feb 13, 2025
Copy link
Contributor

@psweeting1 psweeting1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM we just have to wait on the accessibility team to confirm the HTML.

@psweeting1 psweeting1 dismissed their stale review February 13, 2025 12:54

Spotted arial label description

if user_language == "cy":
return "<a class='govuk-body govuk-link' id='language_switcher_link' href='#' hreflang='en' lang='en' rel='altternate' aria-label='English'>English</a> / Cymraeg"
else:
return "English / <a class='govuk-body govuk-link' id='language_switcher_link' href='#' hreflang='cy' lang='cy' rel='altternate' aria-label='Cymraeg'>Cymraeg</a>"
Copy link
Contributor

@psweeting1 psweeting1 Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use DWP's Aria label as they've got a really good descriptions for both welsh and english. aria-label should always be descriptive and meaningful, providing enough context for screen readers to understand the purpose of the element.

Both english and welsh aria labels say "change language to X" on the DWP ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants