Skip to content

Commit

Permalink
Project created
Browse files Browse the repository at this point in the history
  • Loading branch information
phfsouza committed Dec 22, 2020
1 parent 9202cda commit 9883187
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 82 deletions.
9 changes: 9 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const NextI18Next = require('next-i18next').default
const { localeSubpaths } = require('next/config').default().publicRuntimeConfig
const path = require('path')

module.exports = new NextI18Next({
otherLanguages: ['fr'],
localeSubpaths,
localePath: path.resolve('./public/static/locales')
})
2 changes: 2 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
14 changes: 14 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { nextI18NextRewrites } = require('next-i18next/rewrites')

const localeSubpaths = {
fr: 'fr',
en: 'eng',
}

module.exports = {
rewrites: async () => nextI18NextRewrites(localeSubpaths),
publicRuntimeConfig: {
localeSubpaths,
},
poweredByHeader: false,
}
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
"start": "next start"
},
"dependencies": {
"next": "10.0.3",
"react": "17.0.1",
"react-dom": "17.0.1"
"next": "^10.0.3",
"next-i18next": "^7.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@types/node": "^14.14.14",
"@types/react": "^17.0.0",
"typescript": "^4.1.3"
}
}
7 changes: 0 additions & 7 deletions pages/_app.js

This file was deleted.

25 changes: 25 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "../styles/globals.css";

import React from "react";
import App, { AppProps } from "next/app";
import Head from "next/head";

import { appWithTranslation } from "../i18n";

function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<title>Example</title>
{/* <link rel='icon' type='image/png' href='/favicon.png' /> */}
</Head>
<Component {...pageProps} />
</>
);
}

MyApp.getInitialProps = async (appContext) => ({
...(await App.getInitialProps(appContext)),
});

export default appWithTranslation(MyApp);
34 changes: 34 additions & 0 deletions pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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)
File renamed without changes.
65 changes: 0 additions & 65 deletions pages/index.js

This file was deleted.

30 changes: 30 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import styles from "../styles/Home.module.css";
import PropTypes from 'prop-types'

import React from "react";
import { TFunction } from "next-i18next";
import { Link, i18n, withTranslation } from "../i18n";

function Page({ t }: { readonly t: TFunction }) {
return (
<div className={styles.container}>
{t("language")}

<button
className={styles.btn1}
type="button"
onClick={() =>
i18n.changeLanguage(i18n.language === "en" ? "fr" : "en")
}
>
{t("change-language")}
</button>
</div>
);
}

Page.getInitialProps = async () => ({
namespacesRequired: ['common'],
});

export default withTranslation('common')(Page);
4 changes: 4 additions & 0 deletions public/static/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"change-language": "Fr",
"language": "Language"
}
4 changes: 4 additions & 0 deletions public/static/locales/fr/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"change-language": "En",
"language": "Langage"
}
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
, "i18n.js", "pages/_error.js" ],
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit 9883187

Please sign in to comment.