Created
June 16, 2021 07:04
-
-
Save philJohnson/5539b9ffc5d611de2e99c13467ef6ec2 to your computer and use it in GitHub Desktop.
Polylang Language Selector
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
import React from 'react'; | |
import { StaticQuery, graphql } from 'gatsby'; | |
import { StyledLocationSelector, StyledList } from './styles'; | |
export const LanguageSelector: React.StatelessComponent<any> = ({language}) => ( | |
<StaticQuery | |
query={graphql` | |
query Languages { | |
wp { | |
languages { | |
name | |
homeUrl | |
} | |
} | |
} | |
`} | |
render={({wp: {languages}}) => { | |
if(languages.length > 1) { | |
return ( | |
<StyledLocationSelector> | |
<span>Language Select</span> | |
<StyledList> | |
{languages.map(({homeUrl, name}) => { | |
return <li><a href={homeUrl} >{name}</a></li> | |
})} | |
</StyledList> | |
</StyledLocationSelector> | |
)} | |
return null; | |
}} | |
/> | |
); | |
export default LanguageSelector; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment