Skip to content
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

feature(www): Translate text through js-lingui #21633

Merged
merged 28 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
170d72e
WIP lingui integration
tesseralis Feb 21, 2020
08dd899
translate and extract more stuff
tesseralis Feb 21, 2020
fdecff7
remove extraneous
tesseralis Feb 21, 2020
bbae55d
add toggle text
tesseralis Feb 21, 2020
3eb5989
egghead embed
tesseralis Feb 21, 2020
2c686bd
fix tests
tesseralis Feb 21, 2020
5e47b02
rename lingui functions
tesseralis Feb 21, 2020
17474b1
ignore translation files in typo check
tesseralis Feb 21, 2020
2d878dd
Merge branch 'master' into lingui
tesseralis Feb 21, 2020
a18e353
Merge branch 'master' into lingui
tesseralis Feb 21, 2020
b7c886b
build lingui in onPreInit
tesseralis Feb 21, 2020
2c1927e
finish everything
tesseralis Feb 21, 2020
701e375
remove babelrc
tesseralis Feb 21, 2020
5a95af0
add husky
tesseralis Feb 21, 2020
18b045d
add stuff
tesseralis Feb 21, 2020
f655152
redo navigation
tesseralis Feb 21, 2020
ab159be
try to do something
tesseralis Feb 21, 2020
e6e0b2a
remove husky and lint-saged for now
tesseralis Feb 22, 2020
b739698
fix stuff
tesseralis Feb 22, 2020
707083a
Merge branch 'master' into lingui
tesseralis Feb 26, 2020
a4f2134
move preset info to packages.json
tesseralis Feb 27, 2020
386754b
move preset to extractCoptions"
tesseralis Feb 27, 2020
5af54f3
Merge branch 'master' into lingui
tesseralis Mar 2, 2020
822055b
reorganize i18n stuff
tesseralis Mar 2, 2020
6fc6582
Merge branch 'master' into lingui
tesseralis Mar 9, 2020
8ead7e3
fix locale provider
tesseralis Mar 9, 2020
fe2d9e9
move build logic
tesseralis Mar 9, 2020
ce3d606
Merge branch 'master' into lingui
tesseralis Mar 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ excluded_files:
- "**/*.ts"
- "**/*.jsx"
- "**/*.tsx"
- "*.po" # PO translation files
# Any typos we should ignore?
excluded_words:
- typoci
Expand Down
4 changes: 4 additions & 0 deletions www/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ src/cache

# Env variables
.env*

# Lingui
src/data/locales/**/messages.js
src/data/locales/_build
5 changes: 5 additions & 0 deletions www/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Promise = require(`bluebird`)
const fetch = require(`node-fetch`)
const fs = require(`fs-extra`)
const child_process = require(`child_process`)
const startersRedirects = require(`./starter-redirects.json`)
const yaml = require(`js-yaml`)
const redirects = yaml.load(fs.readFileSync(`./redirects.yaml`))
Expand Down Expand Up @@ -37,6 +38,10 @@ exports.onCreateNode = helpers => {
sections.forEach(section => section.onCreateNode(helpers))
}

exports.onPreInit = () => {
child_process.execSync(`yarn lingui:build`)
}

exports.onPostBuild = () => {
fs.copySync(
`../docs/blog/2017-02-21-1-0-progress-update-where-came-from-where-going/gatsbygram.mp4`,
Expand Down
29 changes: 28 additions & 1 deletion www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@emotion/styled": "^10.0.23",
"@jamo/graphql-request": "2.0.2",
"@lingui/react": "^2.9.1",
"@loadable/component": "^5.11.0",
"@mdx-js/mdx": "^1.5.1",
"@reach/skip-nav": "^0.6.2",
Expand Down Expand Up @@ -110,6 +111,24 @@
"license": "MIT",
"main": "n/a",
"private": true,
"babel": {
"presets": ["babel-preset-gatsby"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wardpeet, @pvdz told me that you might know what's up. For some reason, Lingui requires this configuration in order for the CLI to run properly and let us do lingui extract. But it shouldn't be necessary, since it's the default included in gatsby.

Copy link
Contributor

Choose a reason for hiding this comment

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

(This was in relation to webpack, but it turns out this was actually needed because lingui couldn't figure out our preset without a hint like this)

},
"lingui": {
"sourceLocale": "en",
"localeDir": "src/data/locales",
"srcPathDirs": [
"src/components",
"src/pages",
"src/templates",
"src/views"
],
"srcPathIgnorePatterns": [
"__tests__"
],
"format": "po",
"sorting": "origin"
},
"scripts": {
"build": "gatsby build",
"deploy": "gatsby build --prefix-paths && gh-pages -d public",
Expand All @@ -121,11 +140,19 @@
"scrapeStarters": "cd src/data/StarterShowcase && node scraper.js",
"stylelint": "stylelint './src/**/*.js'",
"forestry:preview": "gatsby develop -p 8080 -H 0.0.0.0",
"postinstall": "cd plugins/gatsby-transformer-gatsby-api-calls && npm install"
"postinstall": "cd plugins/gatsby-transformer-gatsby-api-calls && npm install",
"lingui:add-locale": "lingui add-locale",
"lingui:extract": "lingui extract",
"lingui:compile": "lingui compile",
"lingui:build": "yarn lingui:extract && yarn lingui:compile"
},
"devDependencies": {
"@lingui/cli": "^2.9.1",
"@lingui/macro": "^2.9.1",
"@testing-library/react": "^8.0.9",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.9.0",
"babel-plugin-macros": "^2.8.0",
"babel-preset-gatsby": "^0.2.23",
"cross-env": "^5.2.1",
"front-matter": "^2.3.0",
Expand Down
11 changes: 7 additions & 4 deletions www/src/components/dark-mode-toggle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react"
import styled from "@emotion/styled"
import { useColorMode } from "theme-ui"
import { t } from "@lingui/macro"
import { withI18n } from "@lingui/react"

import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"

Expand Down Expand Up @@ -123,26 +125,27 @@ const MoonMask = styled.div`
width: 24px;
`

function DarkModeToggle() {
function DarkModeToggle({ i18n }) {
const [colorMode, setColorMode] = useColorMode()
const isDark = colorMode === `dark`

function toggleColorMode(event) {
event.preventDefault()
setColorMode(isDark ? `light` : `dark`)
}
const label = isDark ? t`Activate light mode` : t`Activate dark mode`

return (
<IconWrapper
isDark={isDark}
onClick={toggleColorMode}
aria-label={isDark ? `Activate light mode` : `Activate dark mode`}
title={isDark ? `Activate light mode` : `Activate dark mode`}
aria-label={label}
title={label}
>
<MoonOrSun isDark={isDark} />
<MoonMask isDark={isDark} />
</IconWrapper>
)
}

export default DarkModeToggle
export default withI18n()(DarkModeToggle)
8 changes: 6 additions & 2 deletions www/src/components/docs-table-of-contents.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import { Link } from "gatsby"
import { colors, mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"
import { Trans } from "@lingui/macro"
import {
colors,
mediaQueries,
} from "gatsby-design-tokens/dist/theme-gatsbyjs-org"

function isUnderDepthLimit(depth, maxDepth) {
if (maxDepth === null) {
Expand Down Expand Up @@ -86,7 +90,7 @@ function TableOfContents({ page, location }) {
textTransform: `uppercase`,
}}
>
Table of Contents
<Trans>Table of Contents</Trans>
</h2>
<ul
sx={{
Expand Down
5 changes: 4 additions & 1 deletion www/src/components/guide-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import { Trans } from "@lingui/macro"

import docsHierarchy from "../data/sidebars/doc-links.yaml"
import tutorialHierarchy from "../data/sidebars/tutorial-links.yaml"
Expand Down Expand Up @@ -42,7 +43,9 @@ const GuideList = ({ slug }) => {
))
const toc = subitemList.length ? (
<>
<h2>In this section:</h2>
<h2>
<Trans>In this section:</Trans>
</h2>
<ul>{subitemList}</ul>
</>
) : null
Expand Down
7 changes: 4 additions & 3 deletions www/src/components/markdown-page-footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import React from "react"
import { Trans } from "@lingui/macro"
import { graphql } from "gatsby"
import EditIcon from "react-icons/lib/md/create"

Expand All @@ -20,9 +21,9 @@ export default class MarkdownPageFooter extends React.Component {
this.props.packagePage ? `packages` : `docs`
}/${this.props.page ? this.props.page.parent.relativePath : ``}`}
>
<EditIcon sx={{ marginRight: 2 }} />
{` `}
Edit this page on GitHub
<Trans>
<EditIcon sx={{ marginRight: 2 }} /> Edit this page on GitHub
</Trans>
</a>
)}
</>
Expand Down
26 changes: 19 additions & 7 deletions www/src/components/navigation-mobile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import { Link } from "gatsby"
import { t } from "@lingui/macro"
import { withI18n } from "@lingui/react"

import {
BlogIcon,
Expand Down Expand Up @@ -39,8 +41,15 @@ const MobileNavItem = ({ linkTo, label, icon }) => (
<div>{label}</div>
</Link>
)
const navItems = [
{ id: "docs", text: t`Docs`, icon: DocsIcon },
{ id: `tutorial`, text: t`Tutorials`, icon: TutorialIcon },
{ id: `plugins`, text: t`Plugins`, icon: PluginsIcon },
{ id: `blog`, text: t`Blog`, icon: BlogIcon },
{ id: `showcase`, text: t`Showcase`, icon: ShowcaseIcon },
]

const MobileNavigation = () => (
const MobileNavigation = ({ i18n }) => (
<div
sx={{
alignItems: `center`,
Expand All @@ -62,15 +71,18 @@ const MobileNavigation = () => (
},
}}
>
<MobileNavItem linkTo="/docs/" label="Docs" icon={DocsIcon} />
<MobileNavItem linkTo="/tutorial/" label="Tutorials" icon={TutorialIcon} />
<MobileNavItem linkTo="/plugins/" label="Plugins" icon={PluginsIcon} />
<MobileNavItem linkTo="/blog/" label="Blog" icon={BlogIcon} />
<MobileNavItem linkTo="/showcase/" label="Showcase" icon={ShowcaseIcon} />
{navItems.map(({ id, text, icon }) => (
<MobileNavItem
linkTo={`/${id}/`}
key={id}
text={i18n._(text)}
icon={icon}
/>
))}
</div>
)

export default MobileNavigation
export default withI18n()(MobileNavigation)

const styles = {
svg: {
Expand Down
35 changes: 22 additions & 13 deletions www/src/components/navigation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import { useColorMode } from "theme-ui"
import { withI18n } from "@lingui/react"
import { t, Trans } from "@lingui/macro"
import GithubIcon from "react-icons/lib/go/mark-github"
import TwitterIcon from "react-icons/lib/fa/twitter"

Expand Down Expand Up @@ -80,7 +82,17 @@ const SocialNavItem = ({ href, title, children }) => (
</a>
)

const Navigation = ({ pathname }) => {
const navItems = [
{ id: "docs", text: t`Docs` },
{ id: "tutorial", text: t`Tutorial` },
{ id: "plugins", text: t`Plugins` },
{ id: "features", text: t`Features` },
{ id: "blog", text: t`Blog` },
{ id: "showcase", text: t`Showcase` },
{ id: "contributing", text: t`Contributing` },
]

const Navigation = ({ pathname, i18n }) => {
const [colorMode] = useColorMode()
const isHomepage = pathname === `/`

Expand Down Expand Up @@ -149,7 +161,7 @@ const Navigation = ({ pathname }) => {
width: [`24px`, null, `auto`],
overflow: [`hidden`, null, `visible`],
}}
aria-label="Gatsby, Back to homepage"
aria-label={i18n._(t`Gatsby, Back to homepage`)}
>
<img
src={colorMode === `light` ? logo : logoInverted}
Expand All @@ -159,13 +171,13 @@ const Navigation = ({ pathname }) => {
maxWidth: `none`,
m: 0,
}}
alt="Gatsby Logo"
alt={i18n._(t`Gatsby Logo`)}
aria-hidden="true"
/>
</Link>
<nav
className="navigation"
aria-label="Primary Navigation"
aria-label={i18n._(t`Primary Navigation`)}
sx={{
display: `none`,
[mediaQueries.md]: {
Expand Down Expand Up @@ -193,14 +205,11 @@ const Navigation = ({ pathname }) => {
},
}}
>
<NavItem linkTo="/docs/">Docs</NavItem>
<NavItem linkTo="/tutorial/">Tutorials</NavItem>
<NavItem linkTo="/plugins/">Plugins</NavItem>
<NavItem linkTo="/features/">Features</NavItem>
<NavItem linkTo="/blog/">Blog</NavItem>
<NavItem linkTo="/showcase/">Showcase</NavItem>
<NavItem linkTo="/contributing/">Contributing</NavItem>
{/* <NavItem linkTo="/starters/">Starters</NavItem> */}
{navItems.map(({ id, text }) => (
<NavItem key={id} linkTo={`/${id}/`}>
<Trans id={text} />
</NavItem>
))}
</ul>
</nav>
<SearchForm key="SearchForm" offsetVertical={navItemTopOffset} />
Expand Down Expand Up @@ -254,4 +263,4 @@ const Navigation = ({ pathname }) => {
)
}

export default Navigation
export default withI18n()(Navigation)
16 changes: 11 additions & 5 deletions www/src/components/prev-and-next.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import { t, Trans } from "@lingui/macro"
import { withI18n } from "@lingui/react"
import Link from "./localized-link"
import ArrowForwardIcon from "react-icons/lib/md/arrow-forward"
import ArrowBackIcon from "react-icons/lib/md/arrow-back"
Expand All @@ -25,14 +27,14 @@ const prevNextLabelStyles = {
mt: 0,
}

const PrevAndNext = ({ prev = null, next = null, ...props }) => {
const PrevAndNext = ({ prev = null, next = null, i18n, ...props }) => {
if (!prev && !next) {
return null
}

return (
<nav
aria-label="pagination"
aria-label={i18n._(t`pagination`)}
sx={{
[mediaQueries.sm]: {
display: `flex`,
Expand All @@ -45,7 +47,9 @@ const PrevAndNext = ({ prev = null, next = null, ...props }) => {
<div css={{ [mediaQueries.sm]: { width: `48%` } }}>
{prev && (
<Link to={prev.link} sx={prevNextLinkStyles}>
<p sx={prevNextLabelStyles}>Previous</p>
<p sx={prevNextLabelStyles}>
<Trans>Previous</Trans>
</p>
<span
sx={{
[mediaQueries.md]: {
Expand Down Expand Up @@ -76,7 +80,9 @@ const PrevAndNext = ({ prev = null, next = null, ...props }) => {
>
{next && (
<Link to={next.link} sx={prevNextLinkStyles}>
<p sx={prevNextLabelStyles}>Next</p>
<p sx={prevNextLabelStyles}>
<Trans>Next</Trans>
</p>
<span
sx={{
[mediaQueries.md]: {
Expand All @@ -102,4 +108,4 @@ const PrevAndNext = ({ prev = null, next = null, ...props }) => {
)
}

export default PrevAndNext
export default withI18n()(PrevAndNext)
Loading