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

Issue 2963: Adding Next-i18next for front-end translations #3053

Closed
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"jsdom": "18.1.1",
"linkify-html": "3.0.5",
"linkifyjs": "3.0.5",
"next-i18next": "10.4.0",
"node-fetch": "2.6.7",
"normalize-url": "6.1.0",
"opml-generator": "1.1.1",
Expand Down
195 changes: 194 additions & 1 deletion pnpm-lock.yaml

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

10 changes: 10 additions & 0 deletions src/web/next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// this preloads the locales from web/public/locales
module.exports = {
i18n: {
defaultLanguage: 'en',
defaultLocale: 'en',
fallbackLng: 'en',
locales: ['en', 'es'],
},
react: { useSuspense: false },
};
2 changes: 2 additions & 0 deletions src/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const dotenv = require('dotenv');
const withPlugins = require('next-compose-plugins');
const withPWA = require('next-pwa');
const runtimeCaching = require('next-pwa/cache');
const { i18n } = require('./next-i18next.config');

// Load an env file
const loadApiUrlFromEnv = (envFile) => dotenv.config({ path: envFile });
Expand Down Expand Up @@ -81,5 +82,6 @@ module.exports = withPlugins([
},
},
],
{ i18n },
nextConfig,
]);
1 change: 1 addition & 0 deletions src/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"nanoid": "3.2.0",
"next": "12.0.9",
"next-compose-plugins": "2.2.1",
"next-i18next": "^10.4.0",
"next-pwa": "5.4.4",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
5 changes: 5 additions & 0 deletions src/web/public/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"aboutUs": "About Us",
"signIn": "Sign In",
"signOut": "Sign out"
}
5 changes: 5 additions & 0 deletions src/web/public/locales/es/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"aboutUs": "sobre nosotros",
"signIn": "Iniciar sesión",
"signOut": "Cerrar sesión"
}
7 changes: 5 additions & 2 deletions src/web/src/components/BannerButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Link from 'next/link';
import { useRouter } from 'next/router';
import { makeStyles, Tooltip, withStyles, Zoom } from '@material-ui/core';
import Button from '@material-ui/core/Button';
import { useTranslation } from 'next-i18next';
import useAuth from '../hooks/use-auth';
import TelescopeAvatar from './TelescopeAvatar';
import PopUp from './PopUp';
Expand Down Expand Up @@ -53,6 +54,8 @@ const BannerButtons = () => {

const router = useRouter();

const { t } = useTranslation(`common`);

return (
<div
className={`${classes.buttonsContainer} ${
Expand All @@ -78,7 +81,7 @@ const BannerButtons = () => {
}}
variant="outlined"
>
About us
{t('aboutUs')}
</Button>
</Link>
{user?.isRegistered ? (
Expand All @@ -105,7 +108,7 @@ const BannerButtons = () => {
onClick={() => login()}
variant="outlined"
>
Sign in
{t('signIn')}
</Button>
{/* Bandaid solution to avoid signing up */}
{/* <Link href="/signup" passHref>
Expand Down
3 changes: 2 additions & 1 deletion src/web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect } from 'react';
import { AppProps } from 'next/app';
import { ThemeProvider } from '@material-ui/core/styles';
import { SWRConfig } from 'swr';
import { appWithTranslation } from 'next-i18next';

import AuthProvider from '../components/AuthProvider';

Expand Down Expand Up @@ -49,4 +50,4 @@ const App = ({ Component, pageProps }: AppProps) => {
);
};

export default App;
export default appWithTranslation(App);
Loading