-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from alphagov/create-translation-component
Create translation navigation component
- Loading branch information
Showing
21 changed files
with
233 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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,35 @@ | ||
.app-c-translation-nav { | ||
margin-bottom: $gutter; | ||
border-bottom: 1px solid $border-colour; | ||
@include responsive-top-margin; | ||
@include core-16; | ||
} | ||
|
||
.app-c-translation-nav__list { | ||
@extend %contain-floats; | ||
list-style: none; | ||
margin-left: -$gutter-one-third; | ||
margin-right: -$gutter-one-third; | ||
} | ||
|
||
.app-c-translation-nav__list__language { | ||
float: left; | ||
padding-left: $gutter-one-third; | ||
padding-right: $gutter-one-third; | ||
margin-bottom: $gutter-one-third; | ||
border-right: 1px solid $border-colour; | ||
height: 16px; | ||
|
||
.direction-rtl & { | ||
direction: rtl; | ||
float: right; | ||
text-align: start; | ||
border-left: 1px solid $border-colour; | ||
border-right: 0; | ||
} | ||
} | ||
|
||
.app-c-translation-nav__list__language:last-child { | ||
border-right: 0; | ||
border-left: 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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,13 @@ | ||
<div class="app-c-translation-nav"> | ||
<ul class="app-c-translation-nav__list"> | ||
<% translations.each.with_index do |translation, i| %> | ||
<li class="app-c-translation-nav__list__language"> | ||
<% if translation[:active] %> | ||
<%= translation[:text] %> | ||
<% else %> | ||
<%= link_to translation[:text], translation[:base_path], lang: translation[:locale], rel: "alternate" %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> |
This file contains 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,45 @@ | ||
name: Translation Nav | ||
description: A navigation item for available language translations. | ||
body: The active property should be used to indicate the currently selected language. | ||
accessibility_criteria: | | ||
The translation nav must: | ||
- accept focus | ||
- be focusable with a keyboard | ||
- indicate when it has focus | ||
- be usable with a keyboard | ||
- inform the user of the language option, if the user has that language installed | ||
fixtures: | ||
# TODO: We need to add a fixture to show component rendering right-to-left. | ||
# This is dependant on being able to provide context to fixtures. | ||
default: | ||
translations: | ||
- locale: 'en' | ||
base_path: '/en' | ||
text: 'English' | ||
active: true | ||
- locale: 'hi' | ||
base_path: '/hi' | ||
text: 'हिंदी' | ||
multiple_translations: | ||
translations: | ||
- locale: 'en' | ||
base_path: '/en' | ||
text: 'English' | ||
active: true | ||
- locale: 'fr' | ||
base_path: '/fr' | ||
text: 'French' | ||
- locale: 'hi' | ||
base_path: '/hi' | ||
text: 'हिंदी' | ||
- locale: 'ja' | ||
base_path: '/ja' | ||
text: '日本語' | ||
- locale: 'ur' | ||
base_path: '/ur' | ||
text: 'اردو' | ||
- locale: 'zh' | ||
base_path: '/zh' | ||
text: '中文' | ||
|
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<% if @content_item.available_translations.any? %> | ||
<%= render 'shared/available_languages', | ||
translations: @content_item.available_translations | ||
%> | ||
<% if @content_item.available_translations.length > 1 %> | ||
<%= render 'components/translation-nav', | ||
translations: @content_item.available_translations %> | ||
<% end %> |
This file contains 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<% if @content_item.available_translations.any? %> | ||
<% if @content_item.available_translations.length > 1 %> | ||
<div class="column-third"> | ||
<%= render 'shared/available_languages', | ||
translations: @content_item.available_translations | ||
%> | ||
<%= render 'components/translation-nav', | ||
translations: @content_item.available_translations %> | ||
</div> | ||
<% end %> |
This file contains 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,95 @@ | ||
require 'component_test_helper' | ||
|
||
class TranslationNavTest < ComponentTestCase | ||
def component_name | ||
"translation-nav" | ||
end | ||
|
||
test "fails to render a translation nav when no translations are given" do | ||
assert_raise do | ||
render_component({}) | ||
end | ||
end | ||
|
||
test "renders an active translation nav item with a text description" do | ||
render_component( | ||
translations: [ | ||
{ | ||
locale: 'en', | ||
base_path: '/en', | ||
text: 'English', | ||
active: true | ||
}, | ||
{ | ||
locale: 'hi', | ||
base_path: '/hi', | ||
text: 'हिंदी', | ||
} | ||
] | ||
) | ||
|
||
assert_select ".app-c-translation-nav__list__language", text: "English" | ||
|
||
assert_select ".app-c-translation-nav__list__language a[lang=\"hi\"]", text: "हिंदी" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/hi\"]" | ||
end | ||
|
||
test "does not render an active translation item with a link" do | ||
render_component( | ||
translations: [ | ||
{ | ||
locale: 'en', | ||
base_path: '/en', | ||
text: 'English', | ||
active: true | ||
}, | ||
{ | ||
locale: 'hi', | ||
base_path: '/hi', | ||
text: 'हिंदी', | ||
} | ||
] | ||
) | ||
|
||
assert_select ".app-c-translation-nav__list__language", text: "English" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/en\"]", | ||
false, "An active item should not link to a page translation" | ||
|
||
|
||
assert_select ".app-c-translation-nav__list__language a[lang=\"hi\"]", text: "हिंदी" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/hi\"]" | ||
end | ||
|
||
test "renders an inactive translation nav item with locale, base path and text" do | ||
render_component( | ||
translations: [ | ||
{ | ||
locale: 'fr', | ||
base_path: '/fr', | ||
text: 'French', | ||
}, | ||
{ | ||
locale: 'hi', | ||
base_path: '/hi', | ||
text: 'हिंदी', | ||
active: true | ||
}, | ||
{ | ||
locale: 'zh', | ||
base_path: '/zh', | ||
text: '中文' | ||
} | ||
] | ||
) | ||
|
||
assert_select ".app-c-translation-nav__list__language a[lang=\"fr\"]", text: "French" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/fr\"]" | ||
|
||
assert_select ".app-c-translation-nav__list__language a[lang=\"zh\"]", text: "中文" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/zh\"]" | ||
|
||
assert_select ".app-c-translation-nav__list__language", text: "हिंदी" | ||
assert_select ".app-c-translation-nav__list__language a[href=\"/hi\"]", | ||
false, "An active item should not link to a page translation" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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
Oops, something went wrong.