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

Add check for available translations #4661

Merged
merged 1 commit into from
Feb 26, 2025
Merged

Conversation

leenagupte
Copy link
Contributor

@leenagupte leenagupte commented Feb 26, 2025

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

Reinstate the original logic from government-frontend to check for the presence of translations.

Why

The available translations method looks through the available_translations and replaces the English translation with "".

That means that if there's only an English translation, then the available_translations will return [""].

any? was being used in the view to determine whether or not to display the translations partial, however, any? returns true for [""].

frontend(dev)> a = [""]
=> [""]
frontend(dev)> a.any?
=> true
frontend(dev)> a.length > 1
=> false

So rather than not rendering anything when there is only an English translation, an empty div was being rendered:

<div class="govuk-grid-column-one-third"></div>

Instead of any? the original logic from government-frontend is being reinstated.

This logic has been made into a method in the model so that it can be easily tested.

See: #4600 (review)

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4661 February 26, 2025 17:03 Inactive
@leenagupte leenagupte force-pushed the add-check-for-translations branch from 0c41b94 to d59626a Compare February 26, 2025 17:07
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4661 February 26, 2025 17:07 Inactive
The available translations method looks through the
`available_translations` and replaces the English translation with `""`.

That means that if there's only an English translation, then the
`available_translations` will return `[""]`.

`any?` was being used in the view to determine whether or not to display
the translations partial, however, `any?` returns true for `[""]`.

```
frontend(dev)> a = [""]
=> [""]
frontend(dev)> a.any?
=> true
frontend(dev)> a.length > 1
=> false
```

So rather than not rendering anything when there is only an English
translation, an empty `div` was being rendered:

`<div class="govuk-grid-column-one-third"></div>`

Instead of `any?` the original logic from [government-frontend] is being
reinstated.

This logic has been made into a method in the model so that it can be
easily tested.

[government-frontend]: https://github.com/alphagov/government-frontend/blob/85f4681feed9ed3b57bb7f2ea0dce10bf6e0338a/app/views/shared/_translations.html.erb#L1
@leenagupte leenagupte force-pushed the add-check-for-translations branch from d59626a to ed46929 Compare February 26, 2025 17:10
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4661 February 26, 2025 17:10 Inactive
@leenagupte leenagupte merged commit 826ad57 into main Feb 26, 2025
13 checks passed
@leenagupte leenagupte deleted the add-check-for-translations branch February 26, 2025 17:49
Copy link
Contributor

@KludgeKML KludgeKML left a comment

Choose a reason for hiding this comment

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

Do we know why the available translations is an array with an empty string? I feel like it should either be an empty array (and this is unnecessary), or an array with "en" in it (and then this method gets modified slightly)

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

Successfully merging this pull request may close these issues.

4 participants