-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(www): Pull in translated gatsby docs (ENABLE_LOCALIZATIONS env v…
…ar needed) (#20637) * add spanish files to source * disable spanish for now * add spanish again * aksldjasdf * get everything working * display spanish and portuguese pages * get all the links working! * a few more fixes * simplify * whats gatsby-cli doing here * i18n util file * update site metadata * disable translations by default * explain how to enable localizations in readme * add more languages
- Loading branch information
1 parent
3815740
commit 56bc2b1
Showing
16 changed files
with
139 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,16 @@ ANALYTICS_SERVICE_ACCOUNT="service [email protected]" | |
ANALYTICS_SERVICE_ACCOUNT_KEY="PEM KEY VALUE" | ||
``` | ||
|
||
### Enabling localizations | ||
|
||
Localizations are currently a work-in-progress and are thus disabled by default. They can be enabled by setting the `ENABLE_LOCALIZATIONS` env variable: | ||
|
||
```shell | ||
ENABLE_LOCALIZATIONS=true | ||
``` | ||
|
||
There is currently no UI to link to the localizations, so you'll have to type in the name of the file you want to go to using the language code (e.g. /es/tutorial/part-one). | ||
|
||
## Running slow build? (Screenshots placeholder) | ||
|
||
If you are not working on a starter or site showcase, it might be beneficial to use a placeholder image instead of actual screenshots. It will skip downloading screenshots and generating responsive images for all screenshots and replace them with a placeholder image. | ||
|
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,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" } | ||
] |
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
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 |
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,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 |
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
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,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 } |
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