-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(www): Pull in translated gatsby docs (ENABLE_LOCALIZATIONS env var needed) #20637
Changes from all commits
556f848
4a484dc
c875f20
5297081
4e35791
09ee77d
f17b8ce
a9870f8
a7d111f
2b6ae0b
01b6efd
efc1403
1e4b012
0a67d19
eb2ff7c
bd0e24b
43aed34
427723c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ "code": "es", "name": "Spanish" }, | ||
{ "code": "id", "name": "Indonesian" }, | ||
{ "code": "pl", "name": "Polish" }, | ||
{ "code": "pt-BR", "name": "Brazilian Portuguese" }, | ||
{ "code": "zh-Hans", "name": "Simplified Chinese" } | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
import { Link } from "gatsby" | ||
import { LocaleContext } from "./layout" | ||
import { localizedPath } from "../utils/i18n" | ||
|
||
// Use the globally available context to choose the right path | ||
const LocalizedLink = ({ to, ...props }) => { | ||
const locale = React.useContext(LocaleContext) | ||
|
||
return <Link {...props} to={localizedPath(locale, to)} /> | ||
} | ||
|
||
export default LocalizedLink |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
import LocalizedLink from "./localized-link" | ||
|
||
const isHash = str => /^#/.test(str) | ||
const isInternal = to => /^\/(?!\/)/.test(to) | ||
|
||
// Only use <LocalizedLink /> for internal links | ||
const MdxLink = ({ href, ...props }) => | ||
isHash(href) || !isInternal(href) ? ( | ||
<a {...props} href={href} /> | ||
) : ( | ||
<LocalizedLink {...props} to={href} /> | ||
) | ||
|
||
export default MdxLink |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { graphql, useStaticQuery } from "gatsby" | |
|
||
import gatsbyIcon from "../assets/gatsby-icon.png" | ||
|
||
const SiteMetadata = ({ pathname }) => { | ||
const SiteMetadata = ({ pathname, locale }) => { | ||
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. Is it better to pull in context or pass the locale down? 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. For the current setup I don't think it'll make a difference. I would consider using Context if the component e.g. would be used in MDX (for ease of use). |
||
const { | ||
site: { | ||
siteMetadata: { siteUrl, title, twitter }, | ||
|
@@ -23,7 +23,7 @@ const SiteMetadata = ({ pathname }) => { | |
|
||
return ( | ||
<Helmet defer={false} defaultTitle={title} titleTemplate={`%s | ${title}`}> | ||
<html lang="en" /> | ||
<html lang={locale} /> | ||
<link rel="canonical" href={`${siteUrl}${pathname}`} /> | ||
<meta name="docsearch:version" content="2.0" /> | ||
<meta | ||
|
@@ -33,7 +33,7 @@ const SiteMetadata = ({ pathname }) => { | |
|
||
<meta property="og:url" content={siteUrl} /> | ||
<meta property="og:type" content="website" /> | ||
<meta property="og:locale" content="en" /> | ||
<meta property="og:locale" content={locale} /> | ||
<meta property="og:site_name" content={title} /> | ||
<meta property="og:image" content={`${siteUrl}${gatsbyIcon}`} /> | ||
<meta property="og:image:width" content="512" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const defaultLang = "en" | ||
|
||
function isDefaultLang(locale) { | ||
return locale === defaultLang | ||
} | ||
|
||
function localizedPath(locale, path) { | ||
const isIndex = path === `/` | ||
|
||
// TODO generalize this to other paths | ||
const isLocalized = !isDefaultLang(locale) && path.startsWith("/tutorial/") | ||
// If it's the default language, don't do anything | ||
// If it's another language, add the "path" | ||
// However, if the homepage/index page is linked don't add the "to" | ||
// Because otherwise this would add a trailing slash | ||
return isLocalized ? `${locale}${isIndex ? `` : `${path}`}` : path | ||
} | ||
|
||
module.exports = { defaultLang, localizedPath } |
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.
It might end up causing confusion since here, "slug = path without locale".
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.
I guess in the interim phase we have to live with that, once we have all parts of the site we could make a
localizedSlug
or localize theslug