This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
i18n Banner #46
Merged
Merged
i18n Banner #46
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a13482a
Set up footer
f986c4f
placeholder for homepage
2f1e494
Add links and SVGs
1e1f77b
Merge branch 'master' into header
b1d032d
Add semi-functional i18n banner
775711c
make it more responsive
665e755
update language list
a0ac395
could we?
fae7ead
Merge branch 'master' into header
4b6d4bf
Merge branch 'master' into header
9982039
move around css file and include banner in app layout
485ae48
PR feedback
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import React, { Component } from 'react'; | ||
import locale from 'browser-locale'; | ||
|
||
import CaretDownSVG from 'svg/CaretDown'; | ||
|
||
const languages = [ | ||
{ | ||
title: 'English', | ||
abbr: 'en', | ||
}, { | ||
title: 'Español', | ||
abbr: 'es', | ||
}, { | ||
title: 'Tiếng Việt', | ||
abbr: 'vn', | ||
}, { | ||
title: '中文', | ||
abbr: 'zh', | ||
}, { | ||
title: 'عربى', | ||
abbr: 'ar', | ||
}, { | ||
title: '한국어', | ||
abbr: 'ko', | ||
}, { | ||
title: 'اردو', | ||
abbr: 'ur', | ||
}, { | ||
title: 'မြန်မာ', | ||
abbr: 'my', | ||
}, | ||
] | ||
|
||
class I18nBanner extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
activeLanguage: locale().substring(0,2) || 'en', | ||
}; | ||
this.displayedLanguageAmount = 4; | ||
this.visibleLanguageOptions = languages.slice(0, this.displayedLanguageAmount); | ||
this.secondaryLanguageOptions = languages.slice(this.displayedLanguageAmount, languages.length); | ||
} | ||
|
||
getLanguageMenuClassName = (language) => { | ||
const classNameBase = `coa-I18nBanner__language`; | ||
return language.abbr === this.state.activeLanguage | ||
? `${classNameBase}--active` | ||
: '' | ||
} | ||
|
||
getSecondaryLanguageMenuClassName = () => { | ||
const base = `coa-I18nBanner__other-language-options`; | ||
return this.state.isOpen ? `${base}--open` : `${base}--closed`; | ||
} | ||
|
||
handleSetLanguage = (e) => { | ||
e.stopPropagation(); | ||
e.nativeEvent.stopImmediatePropagation(); | ||
const languageAbbr = e.target.lang; | ||
console.log(languageAbbr) | ||
this.setState({ | ||
activeLanguage: languageAbbr, | ||
isOpen: false, | ||
}) | ||
} | ||
|
||
handleExpandMenu = () => { | ||
this.setState({ | ||
isOpen: !this.state.isOpen | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="coa-I18nBanner"> | ||
<div className="wrapper"> | ||
<div className="row"> | ||
<div className="col-md-4 col-xs"> | ||
<div className="coa-I18nBanner__prompt"> | ||
Choose your preferred language | ||
</div> | ||
</div> | ||
<div className="col-md-8 col-xs-12"> | ||
<ul className="coa-I18nBanner__language-list"> | ||
{ this.visibleLanguageOptions.map((language, i) => { | ||
return ( | ||
<li className={`coa-I18nBanner__language ${this.getLanguageMenuClassName(language)}`} | ||
onClick={this.handleSetLanguage} | ||
key={i} | ||
> | ||
<span className="hidden--sm visible--md" | ||
lang={language.abbr} | ||
> | ||
{language.title} | ||
</span> | ||
<span className="hidden--md visible--sm" | ||
lang={language.abbr} | ||
> | ||
{language.abbr.toUpperCase()} | ||
</span> | ||
</li> | ||
) | ||
})} | ||
{ this.secondaryLanguageOptions.length > 0 && | ||
<li className="coa-I18nBanner__language--other" | ||
onClick={this.handleExpandMenu} | ||
> | ||
<span className="hidden--sm">Other Language </span> | ||
<CaretDownSVG size="20"/> | ||
<ul className={this.getSecondaryLanguageMenuClassName()}> | ||
{ this.secondaryLanguageOptions.map((language) => { | ||
return ( | ||
<li onClick={this.handleSetLanguage} | ||
className={this.getLanguageMenuClassName(language)} | ||
> | ||
<span lang={language.abbr}> | ||
{language.title} | ||
</span> | ||
</li> | ||
) | ||
}) | ||
} | ||
</ul> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
} | ||
|
||
export default I18nBanner; |
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,32 @@ | ||
.nowrap { | ||
white-space: nowrap; | ||
} | ||
|
||
.hidden--sm { | ||
// --> display none for small width screens and higher | ||
display: none; | ||
@include media($medium-screen) { | ||
display: inline; | ||
} | ||
} | ||
|
||
.hidden--md { | ||
// --> display none for medium width screens and higher | ||
display: inline; | ||
@include media($medium-screen) { | ||
display: none !important; | ||
} | ||
} | ||
|
||
.visible--sm { | ||
// --> display none by default, display initial for small screens and higher | ||
display: inline; | ||
} | ||
|
||
.visible--md { | ||
// --> display none by default, display initial for medium screens and higher | ||
display: none; | ||
@include media($medium-screen) { | ||
display: inline; | ||
} | ||
} |
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,62 @@ | ||
.coa-I18nBanner { | ||
width: 100%; | ||
background-color: $color-gray-light; | ||
padding: $coa-space-level1; | ||
} | ||
|
||
.coa-I18nBanner__language-list { | ||
text-align: right; | ||
font-size: $small-font-size; | ||
} | ||
|
||
.coa-I18nBanner__prompt { | ||
display: none; | ||
font-size: $small-font-size; | ||
position: absolute; | ||
left: -999em; | ||
@include media($medium-screen) { | ||
position: relative; | ||
left: auto; | ||
display: block; | ||
}; | ||
} | ||
|
||
@mixin coa-I18nBanner__language { | ||
display: inline; | ||
padding: 0 $coa-space-level2; | ||
cursor: pointer; | ||
} | ||
|
||
.coa-I18nBanner__language { | ||
@include coa-I18nBanner__language; | ||
} | ||
|
||
.coa-I18nBanner__language--active { | ||
background-color: $color-gray-lighter; | ||
} | ||
|
||
.coa-I18nBanner__language--other { | ||
@include coa-I18nBanner__language; | ||
position: relative; | ||
svg { | ||
vertical-align: middle; | ||
} | ||
} | ||
|
||
@mixin coa-I18nBanner__other-language-options { | ||
position: absolute; | ||
background-color: $color-gray-light; | ||
list-style: none; | ||
top: $coa-space-level5; | ||
right: $coa-space-level2; | ||
padding: $coa-space-level3; | ||
} | ||
|
||
.coa-I18nBanner__other-language-options--open { | ||
@include coa-I18nBanner__other-language-options; | ||
} | ||
|
||
.coa-I18nBanner__other-language-options--closed { | ||
@include coa-I18nBanner__other-language-options; | ||
display: none; | ||
} |
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 @@ | ||
import React from 'react'; | ||
|
||
function CaretDown(props) { | ||
const { size } = props | ||
|
||
return ( | ||
<svg width={size} height={size} viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg" aria-labelledby="title"> | ||
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. SHOW ME HOW TO MAKE SVG PEEEEEAS! 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. remind me when we are both back in the office. no magic here. |
||
<title id="title">Caret Arrow Down</title> | ||
<path d="M1408 704q0 26-19 45l-448 448q-19 19-45 19t-45-19l-448-448q-19-19-19-45t19-45 45-19h896q26 0 45 19t19 45z"/> | ||
</svg> | ||
) | ||
} | ||
export default CaretDown; |
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
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.
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.
are there supposed to be two languages abbreviated with zh (中文, Chinese Traditional)?
Since we're using the abbr prop to indicate active state, two languages will be shown as active.
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.
Yeah, this is a good point. I didn't get all the way to the end of my research about the form of Chinese we'll be using.
This is the best list of language codes I've found: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
And its seems like Simplified and Traditional Chinese share the
zh
language code, but have subtags to distinguish them. Not sure what that means for us in practice, if we're really going to translate for both, or how we would deal with language codes that aren't just two characters.Thus, I just kept their abbreviation the same.
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.
Created an issue: #53 For now, I think I'll just comment out Traditional Chinese for simplicity.