[usecase][m]: experiment i18n on homeage

This commit is contained in:
steveoni
2020-11-25 16:04:52 +01:00
parent e22805bc77
commit 55c6a85180

View File

@@ -5,11 +5,20 @@ import Nav from '../components/home/Nav';
import Recent from '../components/home/Recent'; import Recent from '../components/home/Recent';
import Form from '../components/search/Form'; import Form from '../components/search/Form';
import { SEARCH_QUERY } from '../graphql/queries'; import { SEARCH_QUERY } from '../graphql/queries';
import { loadNamespaces } from './_app';
import useTranslation from 'next-translate/useTranslation';
const Home: React.FC = () => ( const Home: React.FC<{ locale: any; locales: any }> = ({
locale,
locales,
}) => {
const { t } = useTranslation();
return (
<>
<div className="container mx-auto"> <div className="container mx-auto">
<Head> <Head>
<title>Portal</title> <title>{t`common:title`}</title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>
<Nav /> <Nav />
@@ -20,9 +29,7 @@ const Home: React.FC = () => (
<span className="text-orange-500">Datahub</span> <span className="text-orange-500">Datahub</span>
</h1> </h1>
<p className="text-md font-light mb-3 w-4/5"> <p className="text-md font-light mb-3 w-4/5">
At Datahub, we have over thousands of datasets for free and a Premium {t`common:description`}
Data Service for additional or customised data with guaranteed
updates.
</p> </p>
<Form /> <Form />
</div> </div>
@@ -32,9 +39,14 @@ const Home: React.FC = () => (
</section> </section>
<Recent /> <Recent />
</div> </div>
); </>
);
};
export const getServerSideProps: GetServerSideProps = async () => { export const getServerSideProps: GetServerSideProps = async ({
locale,
locales,
}) => {
const apolloClient = initializeApollo(); const apolloClient = initializeApollo();
await apolloClient.query({ await apolloClient.query({
@@ -48,6 +60,9 @@ export const getServerSideProps: GetServerSideProps = async () => {
return { return {
props: { props: {
initialApolloState: apolloClient.cache.extract(), initialApolloState: apolloClient.cache.extract(),
_ns: await loadNamespaces(['common'], locale),
locale,
locales,
}, },
}; };
}; };