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

Setup next-i18n #5

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const NextI18Next = require('next-i18next').default

module.exports = new NextI18Next({
defaultLanguage: 'nl',
otherLanguages: ['en'],
})
131 changes: 131 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"scripts": {
"dev": "next dev -p 4080",
"build": "next build",
"start": "next start"
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"isomorphic-unfetch": "^3.0.0",
"lodash": "^4.17.15",
"next": "9.3.5",
"next-i18next": "^4.4.2",
"react": "16.13.1",
"react-dom": "16.13.1"
},
Expand Down
9 changes: 8 additions & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import '../styles/index.css'
import App from 'next/app'
import { appWithTranslation } from '../i18n'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
MyApp.getInitialProps = async (appContext) => {
const appProps = await App.getInitialProps(appContext)
return { ...appProps }
}

export default appWithTranslation(MyApp)
36 changes: 36 additions & 0 deletions pages/_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import PropTypes from 'prop-types'

import { withTranslation } from '../i18n'

const Error = ({ statusCode, t }) => (
<p>
{statusCode
? t('error-with-status', { statusCode })
: t('error-without-status')}
</p>
)

Error.getInitialProps = async ({ res, err }) => {
let statusCode = null
if (res) {
({ statusCode } = res)
} else if (err) {
({ statusCode } = err)
}
return {
namespacesRequired: ['common'],
statusCode,
}
}

Error.defaultProps = {
statusCode: null,
}

Error.propTypes = {
statusCode: PropTypes.number,
t: PropTypes.func.isRequired,
}

export default withTranslation('common')(Error)
8 changes: 8 additions & 0 deletions pages/courses/[course]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ function CourseDetails() {
)
}

export async function getStaticProps(context) {
return {
props: {
namespacesRequired: ['common'],
},
}
}

export default CourseDetails
8 changes: 8 additions & 0 deletions pages/courses/[course]/learn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ function CourseDetails() {
)
}

export async function getStaticProps(context) {
return {
props: {
namespacesRequired: ['common'],
},
}
}

export default CourseDetails
8 changes: 8 additions & 0 deletions pages/courses/[course]/learn/units/[unit]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ function CourseDetails() {
)
}

export async function getStaticProps(context) {
return {
props: {
namespacesRequired: ['common'],
},
}
}

export default CourseDetails
Loading