Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

i18n Banner #46

Merged
merged 12 commits into from
Dec 29, 2017
Merged

i18n Banner #46

merged 12 commits into from
Dec 29, 2017

Conversation

mateoclarke
Copy link
Contributor

@mateoclarke mateoclarke commented Dec 21, 2017

Addresses part of #21. Punts on most of #35

This isn't totally functional yet. Just mainly focusing on the markup. The language choice doesn't persist and it is only stored in the state of this component when it should probably be managed at a higher level.

We still need to:

  • update the API call to pull down language appropriate data onto the page
  • and/or we need to reroute the user to a url with with the language code appended, ex: austin.gov/es
  • The dropdown isn't a great UX, but I wanted to talk to Celine about what she expects from it before spending more time on it. edit: now remembering about Language Selection #35 where its better defined

Not sure about the best long term approach there so I'm going to punt until we can investigate if Next.js has some patterns we should look into.

screen shot 2017-12-20 at 6 07 48 pm

screen shot 2017-12-20 at 6 08 13 pm

Copy link
Contributor

@benweatherman benweatherman left a comment

Choose a reason for hiding this comment

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

Code looks 👌 to me. Thanks for posting the screenshots.

I feel like the URL redirect is a best practice as a long term solution (some people on stackexchange say so). Using a URL would allow us to detect the language the first time a user visits the site and do a redirect from the server. Also forgive me if you weren't looking for feedback on that stuff yet.

constructor(props) {
super(props);
this.state = {
activeLanguage: locale().substring(0,2) || 'en', // we could
Copy link
Contributor

Choose a reason for hiding this comment

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

could we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

activeLanguage: languageAbbr,
isOpen: false,
})
console.log(this.state.activeLanguage)
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely not something for right now: if/when we do server redirects for language we should set a cookie here so the server will know the user has overridden the language from the browser settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#54

This was referenced Dec 21, 2017
Copy link
Contributor

@ifsimicoded ifsimicoded left a comment

Choose a reason for hiding this comment

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

HOLIDAAAAAYS!!!
giphy 5

}

render() {
const displayedLanguageAmount = 4
Copy link
Contributor

Choose a reason for hiding this comment

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

really minor, but since the number of shown languages doesn't change on each render, you can create a method that sets this.primaryLanguages and this.secondaryLanguages in the constructor. and then reference those two class vars in render.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, that makes sense.

@@ -0,0 +1,74 @@
.coa-I18nBanner {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this _I18nBanner.scss so it's treated as a partial. This will fix the missing scss var issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.coa-I18nBanner {
width: 100%;
background-color: $color-gray-light;
padding: .7rem 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we not use magic numbers and stick to the padding dimensions we have? $coa-space-level1 or $coa-space-level2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


.coa-I18nBanner__prompt {
display: none;
font-size: 1.5rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, can we stick to using variables for defining sizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool. Do we want to define these in _variables_coa.scss? For now, I'm using the font size values set in _variables_uswds.scss

};
}

languageClassName = (language) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

SUUUUPER minor, can we update these functions to getLanguageClassName and getSecondaryLanguageMenuClassName? I like the action the function is performing to be REAAAALLLLY STUPID obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

onClick={this.setLangauage} lang={language.abbr}
key={i}
>
<span className="coa-I18nBanner__language--hide-sm">{language.title}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of creating specific hide-sm classes can we create generic ones for breakpoints.
.hidden--sm --> display none for small width screens and higher
.hidden--md --> display none for medium width screens and higher
.visible--sm --> display none by default, display initial for small screens and higher
.visible--md --> display none by default, display initial for medium screens and higher
We can use our screen size variables to build these helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, I knew I was taking a step in that direction but was hesitant to commit to it. Thanks for calling it out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So as I started digging into how to create these helper classes, I thought it was pretty interesting how they are doing it now in Bootstrap v4:
Code: https://github.com/twbs/bootstrap/blob/7b766e1ad53b0c22de42dac04d2472f287334e2a/scss/utilities/_display.scss
Docs: https://getbootstrap.com/docs/4.0/utilities/display/#hiding-elements

Should we move in that direction?

<div className="coa-I18nBanner">
<div className="wrapper">
<div className="row">
<div className="col-md-4 col-xs coa-I18nBanner__prompt">
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we try to nest things inside of grid classes so display properties and margin properties and stuff don't conflict.
so ... <div className="col-md-4 col-xs>.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

.coa-I18nBanner__prompt {
display: none;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use the visible--md helper instead of defining specific styles for hiding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const { size } = props

return (
<svg width={size} height={size} viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg" aria-labelledby="title">
Copy link
Contributor

Choose a reason for hiding this comment

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

SHOW ME HOW TO MAKE SVG PEEEEEAS!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

setLangauage = (e) => {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
const languageAbbr = e.target.parentElement.lang;
Copy link
Contributor

Choose a reason for hiding this comment

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

this way of getting the element that's clicked seems highly coupled to the dom structure. maybe try e.currentTarget to get the element which had the handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, great point. I was trying to accommodate both the main list and secondary list markup which had a small difference in DOM structure. But you're right that this is brittle and would break if someone refactored the HTML and not this line 60. I'm changing the lang="foo" attribute to live directly on the span instead of the parent li

@mateoclarke mateoclarke merged commit 06b34ef into master Dec 29, 2017
@mateoclarke mateoclarke deleted the header branch February 8, 2018 17:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants