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

Add lingui js and translate pages #40

Merged
merged 17 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Set main content to use `main` tag.
- Disable autocomplete on search bar.
- Update mentions popup to use the typeahead component.
- Translated all pages to portuguese.

### Fixed
- Drawer items not tabbable.
Expand Down
11 changes: 11 additions & 0 deletions packages/app/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"macros"
],
"presets": [
["@babel/preset-env", {"targets": {"node": "current"}}],
"react-app",
"@babel/preset-typescript"
]
}
2 changes: 2 additions & 0 deletions packages/app/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/locales/_build/
src/locales/**/*.js
2 changes: 2 additions & 0 deletions packages/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/locales/_build/
src/locales/**/*.js
6 changes: 6 additions & 0 deletions packages/app/.linguirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"localeDir": "src/locales/",
"srcPathDirs": ["src/"],
"format": "po",
"sourceLocale": "en"
}
4 changes: 2 additions & 2 deletions packages/app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
testEnvironment: 'jsdom',
testURL: 'http://localhost',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': 'babel-jest',
'^.+\\.(gql|graphql)$': 'jest-transform-graphql',
'^.+\\.css$': '<rootDir>/jest/cssTransform.js',
'^(?!.*\\.(js|jsx|css|json)$)': '<rootDir>/jest/fileTransform.js',
Expand All @@ -20,7 +20,7 @@ module.exports = {
],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
'^.+\\.global\\.(css|sass|scss)$': 'identity-obj-proxy',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'],
}
22 changes: 20 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
"scripts": {
"dev": "cks dev",
"start": "cks start",
"prebuild": "yarn compile --strict",
"build": "cks build",
"postinstall": "yarn compile",
"prettier": "prettier --write 'src/**/*.ts' 'src/**/*.tsx'",
"test": "jest -c jest.config.js",
"lint": "eslint --ext ts,tsx src && tsc --noEmit",
"schema-download": "apollo service:download --endpoint=http://localhost:5000/graphql -k",
"gen-types": "apollo client:codegen __generated__ --target=typescript --localSchemaFile=schema.json --includes='src/**/*.gql,src/schema.graphql'"
"gen-types": "apollo client:codegen __generated__ --target=typescript --localSchemaFile=schema.json --includes='src/**/*.gql,src/schema.graphql'",
"add-locale": "lingui add-locale",
"extract": "lingui extract",
"compile": "lingui compile"
},
"dependencies": {
"@cramkle/app-server": "^0.2.2",
"@lingui/react": "^2.7.4",
"@material/react-button": "^0.12.0",
"@material/react-card": "^0.12.0",
"@material/react-checkbox": "^0.12.0",
Expand Down Expand Up @@ -58,13 +64,22 @@
"yup": "^0.27.0"
},
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@hot-loader/react-dom": "^16.8.3",
"@lingui/cli": "^2.7.4",
"@lingui/macro": "^2.7.4",
"@lucasecdb/eslint-config": "^0.3.6",
"@types/classnames": "^2.2.7",
"@types/draft-js": "^0.10.30",
"@types/exenv": "^1.2.0",
"@types/graphql": "^14.0.7",
"@types/jest": "^24.0.9",
"@types/lingui__core": "^2.7.0",
"@types/lingui__macro": "^2.7.3",
"@types/lingui__react": "^2.5.2",
"@types/ramda": "types/npm-ramda#dist",
"@types/react": "^16.8.5",
"@types/react-dom": "^16.8.2",
Expand All @@ -73,6 +88,10 @@
"@types/react-router-dom": "^4.3.1",
"@types/yup": "^0.26.10",
"apollo": "^2.9.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.8.0",
"babel-plugin-macros": "^2.5.1",
"babel-preset-react-app": "^8.0.0",
"eslint": "^5.16.0",
"identity-obj-proxy": "3.0.0",
"jest": "^24.1.0",
Expand All @@ -86,7 +105,6 @@
"stylelint": "^9.10.1",
"stylelint-config-recommended-scss": "^3.2.0",
"stylelint-scss": "^3.5.3",
"ts-jest": "^24.0.0",
"typescript": "^3.4.5"
},
"browserslist": [
Expand Down
145 changes: 75 additions & 70 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { I18nProvider } from '@lingui/react'
import React, { lazy } from 'react'
import { Helmet } from 'react-helmet'
import { Route, Switch, withRouter } from 'react-router'
Expand All @@ -12,6 +13,8 @@ import NotFoundPage from './components/pages/NotFoundPage'
import ShellRoute from './components/routes/ShellRoute'
import { UserRoute, GuestRoute } from './components/routes/AuthRoute'
import { MobileProvider } from './components/MobileContext'
import en from './locales/en/messages'
import pt from './locales/pt/messages'
import client from './utils/apolloClient'

import './theme.global.scss'
Expand All @@ -25,77 +28,79 @@ const StatisticsPage = lazy(() => import('./components/pages/StatisticsPage'))
const AddModelPage = lazy(() => import('./components/pages/AddModelPage'))

const App: React.FunctionComponent<{}> = () => (
<ApolloProvider client={client}>
<MobileProvider>
<Helmet
defaultTitle="Cramkle"
titleTemplate="%s - Cramkle"
meta={[
{
name: 'application-name',
content: 'Cramkle',
},
{
name: 'description',
content: 'Make sure your knowledge will last',
},
{
name: 'keywords',
content: 'flashcards,anki,srs,spaced repetition',
},
]}
/>
<Switch>
<GuestRoute component={LandingPage} path="/" exact />
<ShellRoute
component={HomePage}
RouteComponent={UserRoute}
path={['/home', '/decks', '/models']}
exact
<I18nProvider language="en" catalogs={{ en, pt }}>
<ApolloProvider client={client}>
<MobileProvider>
<Helmet
defaultTitle="Cramkle"
titleTemplate="%s - Cramkle"
meta={[
{
name: 'application-name',
content: 'Cramkle',
},
{
name: 'description',
content: 'Make sure your knowledge will last',
},
{
name: 'keywords',
content: 'flashcards,anki,srs,spaced repetition',
},
]}
/>
<ShellRoute
component={DeckPage}
RouteComponent={UserRoute}
path="/d/:slug"
exact
/>
<ShellRoute
component={ModelPage}
RouteComponent={UserRoute}
path="/m/:id"
exact
/>
<ShellRoute
component={AddModelPage}
RouteComponent={UserRoute}
path="/models/create"
exact
/>
<ShellRoute
component={MarketplacePage}
RouteComponent={UserRoute}
path="/marketplace"
exact
/>
<ShellRoute
component={StatisticsPage}
RouteComponent={UserRoute}
path="/statistics"
exact
/>
<ShellRoute
component={SettingsPage}
RouteComponent={UserRoute}
path="/settings"
exact
/>
<GuestRoute component={RegisterPage} path="/register" exact />
<GuestRoute component={LoginPage} path="/login" exact />
<Route component={AboutPage} path="/about" exact />
<Route component={NotFoundPage} />
</Switch>
</MobileProvider>
</ApolloProvider>
<Switch>
<GuestRoute component={LandingPage} path="/" exact />
<ShellRoute
component={HomePage}
RouteComponent={UserRoute}
path={['/home', '/decks', '/models']}
exact
/>
<ShellRoute
component={DeckPage}
RouteComponent={UserRoute}
path="/d/:slug"
exact
/>
<ShellRoute
component={ModelPage}
RouteComponent={UserRoute}
path="/m/:id"
exact
/>
<ShellRoute
component={AddModelPage}
RouteComponent={UserRoute}
path="/models/create"
exact
/>
<ShellRoute
component={MarketplacePage}
RouteComponent={UserRoute}
path="/marketplace"
exact
/>
<ShellRoute
component={StatisticsPage}
RouteComponent={UserRoute}
path="/statistics"
exact
/>
<ShellRoute
component={SettingsPage}
RouteComponent={UserRoute}
path="/settings"
exact
/>
<GuestRoute component={RegisterPage} path="/register" exact />
<GuestRoute component={LoginPage} path="/login" exact />
<Route component={AboutPage} path="/about" exact />
<Route component={NotFoundPage} />
</Switch>
</MobileProvider>
</ApolloProvider>
</I18nProvider>
)

export default hot(withRouter(App))
54 changes: 30 additions & 24 deletions packages/app/src/components/AppDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { t } from '@lingui/macro'
import { I18n } from '@lingui/react'
import Drawer, {
DrawerHeader,
DrawerTitle,
Expand Down Expand Up @@ -69,30 +71,34 @@ const AppDrawer: React.FunctionComponent<ChildDataProps<Props, Data>> = ({
}, [history])

const drawerItems = (
<List dense singleSelection>
<ListItem onClick={handleHomeClick}>
<ListItemGraphic graphic={<MaterialIcon icon="home" />} />
<ListItemText primaryText="Home" />
</ListItem>
<ListItem onClick={handleMarketplaceClick}>
<ListItemGraphic
graphic={<MaterialIcon icon="store_mall_directory" />}
/>
<ListItemText primaryText="Marketplace" />
</ListItem>
<ListItem onClick={handleStatisticsClick}>
<ListItemGraphic graphic={<MaterialIcon icon="bar_chart" />} />
<ListItemText primaryText="Statistics" />
</ListItem>
<ListItem onClick={handleSettingsClick}>
<ListItemGraphic graphic={<MaterialIcon icon="settings" />} />
<ListItemText primaryText="Settings" />
</ListItem>
<ListItem onClick={handleLogout}>
<ListItemGraphic graphic={<MaterialIcon icon="exit_to_app" />} />
<ListItemText primaryText="Logout" />
</ListItem>
</List>
<I18n>
{({ i18n }) => (
<List dense singleSelection>
<ListItem onClick={handleHomeClick}>
<ListItemGraphic graphic={<MaterialIcon icon="home" />} />
<ListItemText primaryText={i18n._(t`Home`)} />
</ListItem>
<ListItem onClick={handleMarketplaceClick}>
<ListItemGraphic
graphic={<MaterialIcon icon="store_mall_directory" />}
/>
<ListItemText primaryText={i18n._(t`Marketplace`)} />
</ListItem>
<ListItem onClick={handleStatisticsClick}>
<ListItemGraphic graphic={<MaterialIcon icon="bar_chart" />} />
<ListItemText primaryText={i18n._(t`Statistics`)} />
</ListItem>
<ListItem onClick={handleSettingsClick}>
<ListItemGraphic graphic={<MaterialIcon icon="settings" />} />
<ListItemText primaryText={i18n._(t`Settings`)} />
</ListItem>
<ListItem onClick={handleLogout}>
<ListItemGraphic graphic={<MaterialIcon icon="exit_to_app" />} />
<ListItemText primaryText={i18n._(t`Logout`)} />
</ListItem>
</List>
)}
</I18n>
)

const header = (
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/components/BackButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Button from '@material/react-button'
import Icon from '@material/react-material-icon'
import { Trans } from '@lingui/macro'
import React, { useCallback } from 'react'
import { withRouter, RouteComponentProps } from 'react-router'

Expand All @@ -13,11 +14,11 @@ const BackButton: React.FunctionComponent<RouteComponentProps> = ({
return (
<Button
className="mv2"
icon={<Icon icon="arrow_back" />}
icon={<Icon icon="arrow_back" aria-hidden="true" />}
onClick={handleClick}
dense
>
Go back
<Trans>Go back</Trans>
</Button>
)
}
Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/components/DeckList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Trans } from '@lingui/macro'
import { Grid, Row, Cell } from '@material/react-layout-grid'
import { Body1 } from '@material/react-typography'
import React, { useEffect } from 'react'
import { compose, graphql, ChildProps } from 'react-apollo'
import { Body1 } from '@material/react-typography'
import { Grid, Row, Cell } from '@material/react-layout-grid'

import DeckCard from './DeckCard'
import decksQuery from '../graphql/decksQuery.gql'
Expand All @@ -23,7 +24,9 @@ const DeckList: React.FunctionComponent<ChildProps<{}, DecksQuery>> = ({
if (decks.length === 0) {
return (
<div className="flex flex-column items-center">
<Body1 className="mt4">The decks you create will appear here.</Body1>
<Body1 className="mt4">
<Trans>The decks you create will appear here.</Trans>
</Body1>
</div>
)
}
Expand Down