Skip to content

Commit

Permalink
fix: i18n for register page
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilsabatp committed Nov 3, 2022
1 parent 0633dac commit d002129
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 12 deletions.
1 change: 1 addition & 0 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
fallbackLng: 'en',
defaultLocale: 'en',
locales: ['en', 'de', 'cs', 'es', 'fr', 'it', 'pt-BR'],
localeDetection: false,
},
localePath: path.resolve('./public/static/locales'),
reloadOnPrerender: false,
Expand Down
9 changes: 9 additions & 0 deletions pages/all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GetLeaderboardMeta from './../src/utils/getMetaTags/GetLeaderboardMeta';
import { TENANT_ID } from '../src/utils/constants/environment';
import { ErrorHandlingContext } from '../src/features/common/Layout/ErrorHandlingContext';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';

interface Props {
initialized: Boolean;
Expand All @@ -13,6 +14,14 @@ interface Props {
export default function Home({ initialized }: Props) {
const [leaderboard, setLeaderboard] = React.useState(null);
const { handleError } = React.useContext(ErrorHandlingContext);
const { i18n } = useTranslation();

React.useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

React.useEffect(() => {
async function loadLeaderboard() {
Expand Down
10 changes: 10 additions & 0 deletions pages/complete-signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ import CompleteSignup from '../src/features/user/CompleteSignup';
import tenantConfig from '../tenant.config';
import Head from 'next/head';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';

export default function UserProfile() {
const { i18n } = useTranslation();

React.useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

const config = tenantConfig();
return (
<>
Expand Down
9 changes: 9 additions & 0 deletions pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import GetHomeMeta from '../src/utils/getMetaTags/GetHomeMeta';
import { getRequest } from '../src/utils/apiRequests/api';
import { ErrorHandlingContext } from '../src/features/common/Layout/ErrorHandlingContext';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';

interface Props {
initialized: Boolean;
Expand All @@ -16,11 +17,19 @@ interface Props {
export default function Home(initialized: Props) {
const router = useRouter();
const config = tenantConfig();
const { i18n } = useTranslation();

const [leaderboard, setLeaderboard] = React.useState(null);
const [tenantScore, setTenantScore] = React.useState(null);
const { handleError } = React.useContext(ErrorHandlingContext);

React.useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

React.useEffect(() => {
async function loadTenantScore() {
const newTenantScore = await getRequest(
Expand Down
9 changes: 1 addition & 8 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ export default function Donate({
setProject(null);
setZoomLevel(1);
}, []);
console.log(
internalLanguage,
i18n.language,
internalCurrencyCode,
currencyCode,
internalCurrencyCode
);

// Load all projects
React.useEffect(() => {
async function loadProjects() {
Expand All @@ -94,7 +88,6 @@ export default function Donate({
currencyCode !== internalCurrencyCode ||
internalLanguage !== i18n.language
) {
console.log('lol');
const currency = getStoredCurrency();
setInternalCurrencyCode(currency);
setCurrencyCode(currency);
Expand Down
9 changes: 9 additions & 0 deletions pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ import UserProfileLoader from '../src/features/common/ContentLoaders/UserProfile
import { useRouter } from 'next/router';
import { UserPropsContext } from '../src/features/common/Layout/UserPropsContext';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';

interface Props {}

function Login({}: Props): ReactElement {
const router = useRouter();
const { i18n } = useTranslation();

// if the user is authenticated check if we have slug, and if we do, send user to slug
// else send user to login flow

const { user, contextLoaded, loginWithRedirect } =
React.useContext(UserPropsContext);

React.useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

React.useEffect(() => {
async function loadFunction() {
// redirect
Expand Down
9 changes: 8 additions & 1 deletion pages/open-app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Footer from '../src/features/common/Layout/Footer';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';
import { useEffect } from 'react';

export default function OpenApp() {
const { t, ready } = useTranslation(['common']);
const { t, ready, i18n } = useTranslation(['common']);

const styles = {
width: '100vw',
Expand All @@ -14,6 +15,12 @@ export default function OpenApp() {
flexDirection: 'column',
color: 'var(--primary-font-color)',
};
useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

return ready ? (
<>
Expand Down
14 changes: 11 additions & 3 deletions pages/profile/register-trees.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement } from 'react';
import React, { ReactElement, useEffect } from 'react';
import dynamic from 'next/dynamic';
import UserLayout from '../../src/features/common/Layout/UserLayout/UserLayout';
import Head from 'next/head';
Expand All @@ -8,7 +8,15 @@ import { useTranslation } from 'next-i18next';
interface Props {}

export default function Register({}: Props): ReactElement {
const { t } = useTranslation('me');
const { t, i18n } = useTranslation('me');

useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

const RegisterTrees = dynamic(
() => import('../../src/features/user/RegisterTrees/RegisterTrees')
);
Expand All @@ -22,7 +30,7 @@ export default function Register({}: Props): ReactElement {
);
}

export async function getStaticProps({ locale }) {
export async function getStaticProps({ locale }: any) {
return {
props: {
...(await serverSideTranslations(
Expand Down
11 changes: 11 additions & 0 deletions pages/verify-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ import Footer from '../src/features/common/Layout/Footer';
import LandingSection from '../src/features/common/Layout/LandingSection';
import VerifyEmailComponent from './../src/features/common/VerifyEmail/VerifyEmail';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useEffect } from 'react';
import { useTranslation } from 'next-i18next';

interface Props {}

function VerifyEmail({}: Props): ReactElement {
const { i18n } = useTranslation();

useEffect(() => {
if (localStorage.getItem('i18nextLng') !== null && i18n) {
const languageFromLocalStorage: any = localStorage.getItem('i18nextLng');
i18n.changeLanguage(languageFromLocalStorage);
}
}, [i18n]);

return (
<div>
<LandingSection>
Expand Down

0 comments on commit d002129

Please sign in to comment.