-
Notifications
You must be signed in to change notification settings - Fork 64
GYE-2403: Added welsh translation toggle #158
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
Open
rashadmughal
wants to merge
3
commits into
hmrc:main
Choose a base branch
from
rashadmughal:GYE-2403
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/twirl/uk/gov/hmrc/play/views/layouts/LanguageSelection.scala.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| @* | ||
| * Copyright 2021 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| *@ | ||
|
|
||
| @(langMap: Map[String, Lang], langToCall: String => Call, customClass: Option[String] = None, appName: Option[String] = None)(implicit messages: Messages) | ||
|
|
||
| <nav class="@if(customClass.isDefined) {@customClass.get} hmrc-language-select" aria-label="@messages("language.toggle.aria.label")"> | ||
| <ul class="hmrc-language-select__list language-toggle" style="display: block;" > | ||
| @langMap.map { case (key: String, value: Lang) => | ||
| @if(messages.lang.code != value.code) { | ||
| <li class="hmrc-language-select__list-item" style="display: inline-block;" > | ||
| <a id="@key-switch" href="@langToCall(key)" target="_self" data-sso="false" data-journey-click="@{appName.map(name => s"$name:language: ${value.code}")}"> | ||
| <span class="visually-hidden">@messages(s"language.toggle.hidden.$key")</span> | ||
| <span aria-hidden="true">@key.capitalize</span> | ||
| </a> | ||
| </li> | ||
| } else { | ||
| <li class="hmrc-language-select__list-item" style="display: inline-block;" > | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rashadmughal I'll see if I can find an alternative for you, but the use of inline style attributes here feels like something we should avoid to prevent unexpected conflicts in the future |
||
| <span aria-current="true">@key.capitalize</span> | ||
| </li> | ||
| } | ||
| @if(key != langMap.last._1) { | ||
| @Html(" | ") | ||
| } | ||
| } | ||
| </ul> | ||
| </nav> | ||
103 changes: 103 additions & 0 deletions
103
src/test/scala/uk/gov/hmrc/play/views/layouts/LanguageSelectionSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Copyright 2021 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package uk.gov.hmrc.play.views.layouts | ||
|
|
||
| import org.scalatestplus.play.PlaySpec | ||
| import org.scalatestplus.play.guice.GuiceOneAppPerSuite | ||
| import play.api.Application | ||
| import play.api.i18n.{Lang, Messages, MessagesApi} | ||
| import play.api.inject.guice.GuiceApplicationBuilder | ||
| import play.api.mvc.{Call, PathBindable} | ||
| import play.api.test.Helpers._ | ||
| import uk.gov.hmrc.play.views.html.layouts.LanguageSelection | ||
|
|
||
| import java.util.Locale | ||
|
|
||
| class LanguageSelectionSpec extends PlaySpec with GuiceOneAppPerSuite { | ||
| override implicit lazy val app: Application = new GuiceApplicationBuilder() | ||
| .configure(Map("play.i18n.langs" -> Seq("en", "cy", "es"))) | ||
| .build() | ||
| val messagesApi: MessagesApi = app.injector.instanceOf[MessagesApi] | ||
| val messagesEnglish: Messages = messagesApi.preferred(Seq(Lang(new Locale("en")))) | ||
| val messagesWelsh: Messages = messagesApi.preferred(Seq(Lang(new Locale("cy")))) | ||
| val messagesSpanish: Messages = messagesApi.preferred(Seq(Lang(new Locale("es")))) | ||
| val EnglishLangCode = "en" | ||
| val WelshLangCode = "cy" | ||
|
|
||
| val English: Lang = Lang(EnglishLangCode) | ||
| val Welsh: Lang = Lang(WelshLangCode) | ||
|
|
||
| def languageMap: Map[String, Lang] = Map("english" -> English, "cymraeg" -> Welsh) | ||
| def langToUrl(lang: String): Call = Call("GET", "/language/" + implicitly[PathBindable[String]].unbind("lang", lang)) | ||
|
|
||
| "Language selection template view" should { | ||
|
|
||
| "give a link to switch to Welsh when current language is English" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, None, messagesEnglish) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include(messagesEnglish("id=\"cymraeg-switch\"")) | ||
| contentAsString(html) must include("/language/cymraeg") | ||
| } | ||
|
|
||
| "show correct current language message when current language is English" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, None, messagesEnglish) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("<span aria-current=\"true\">English</span>") | ||
| } | ||
|
|
||
| "give a link to switch to English when current language is Welsh" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, None, messagesWelsh) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include(messagesEnglish("id=\"english-switch\"")) | ||
| contentAsString(html) must include("/language/english") | ||
| } | ||
|
|
||
| "show correct current language message when current language is Welsh" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, None, messagesWelsh) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("<span aria-current=\"true\">Cymraeg</span>") | ||
| } | ||
|
|
||
| "show a custom class if it is set" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, Some("float--right"), None, messagesWelsh) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("class=\"float--right") | ||
| } | ||
|
|
||
| "show a data-journey-click attribute for GA if it is set and language is Welsh" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, Some("appName"), messagesWelsh) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("data-journey-click=\"appName:language: en\"") | ||
| } | ||
|
|
||
| "show a data-journey-click attribute for GA if it is set and language is English" in { | ||
| val html = LanguageSelection.render(languageMap, langToUrl, None, Some("appName"), messagesEnglish) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("data-journey-click=\"appName:language: cy\"") | ||
| } | ||
|
|
||
| "show correct current language message when current language is Spanish" in { | ||
| val Spanish = Lang("es") | ||
|
|
||
| val mockLanguageMap = Map("english" -> English, "cymraeg" -> Welsh, "español" -> Spanish) | ||
|
|
||
| val html = LanguageSelection.render(mockLanguageMap, langToUrl, None, None, messagesSpanish) | ||
| contentType(html) must be("text/html") | ||
| contentAsString(html) must include("<span aria-current=\"true\">Español</span>") | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.