From 2bae7c43764df5678fe2fc2e68be11ae95d85a41 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 28 Jan 2022 16:21:47 +0100 Subject: fix: handle translation with lingui The previous method was not working so I tried a different approach. Translation is loaded but I'm still getting warnings: * Plurals for locale undefined aren't loaded * Text content did not match I can't figure how to fix them... --- src/pages/index.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/pages/index.tsx') diff --git a/src/pages/index.tsx b/src/pages/index.tsx index bc89334..ae5fe4b 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,10 +1,10 @@ import type { ReactElement } from 'react'; -import { GetStaticProps } from 'next'; +import { GetStaticProps, GetStaticPropsContext } from 'next'; import Head from 'next/head'; import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; import { NextPageWithLayout } from '@ts/types/app'; -import { loadTranslation } from '@utils/helpers/i18n'; +import { defaultLocale, loadTranslation } from '@utils/helpers/i18n'; import HomePageContent from '@content/pages/homepage.mdx'; import { ButtonLink } from '@components/Buttons'; import styles from '@styles/pages/Home.module.scss'; @@ -137,14 +137,15 @@ Home.getLayout = function getLayout(page: ReactElement) { return {page}; }; -export const getStaticProps: GetStaticProps = async (ctx) => { - const translation = await loadTranslation( - ctx.locale!, - process.env.NODE_ENV === 'production' - ); +export const getStaticProps: GetStaticProps = async ( + context: GetStaticPropsContext +) => { + const { locale } = context; + const translation = await loadTranslation(locale || defaultLocale); return { props: { + locale, translation, }, }; -- cgit v1.2.3