From df250eddcb218f737cb1f28ee1f3e2391aae194e Mon Sep 17 00:00:00 2001 From: aronmal Date: Sun, 16 Apr 2023 15:48:08 +0200 Subject: [PATCH] Working translation --- next-i18next.config.js | 5 +++++ pnpm-lock.yaml | 6 +++--- public/locales/de/common.json | 3 +++ public/locales/en/common.json | 3 +++ src/pages/index.tsx | 22 ++++++++++++++++++++-- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/next-i18next.config.js b/next-i18next.config.js index 0cb98b8..f9d3dc7 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -1,3 +1,8 @@ +// @ts-check + +/** + * @type {import('next-i18next').UserConfig} + */ module.exports = { i18n: { defaultLocale: "en", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56aeb84..cc74d64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,7 +62,7 @@ packages: resolution: {integrity: sha512-oLcVCTeIFadUoArDTwpluncplrYBmTCCZZgXCbgNGvOBBiSDDK3eWO4b/+eOTli5tKv1lg+a5/NAXg+nTcei1w==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.21.4 jsesc: 2.5.2 source-map: 0.5.7 dev: true @@ -118,7 +118,7 @@ packages: engines: {node: '>=6.0.0'} hasBin: true dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.21.4 dev: true /@babel/runtime@7.21.0: @@ -148,7 +148,7 @@ packages: '@babel/helper-hoist-variables': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 '@babel/parser': 7.21.4 - '@babel/types': 7.17.0 + '@babel/types': 7.21.4 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: diff --git a/public/locales/de/common.json b/public/locales/de/common.json index e69de29..e8a3ecd 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -0,0 +1,3 @@ +{ + "cna": "Erstelle Next App" +} diff --git a/public/locales/en/common.json b/public/locales/en/common.json index e69de29..ae6ffa9 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -0,0 +1,3 @@ +{ + "cna": "Create Next App" +} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 89bbec3..d88c120 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,15 +1,26 @@ import styles from "@/styles/Home.module.css" +import { GetStaticProps, InferGetStaticPropsType } from "next" +import { useTranslation } from "next-i18next" +import { serverSideTranslations } from "next-i18next/serverSideTranslations" import { Inter } from "next/font/google" import Head from "next/head" import Image from "next/image" const inter = Inter({ subsets: ["latin"] }) -export default function Home() { +interface Props { + // Add custom props here +} + +export default function Home( + _props: InferGetStaticPropsType +) { + const { t } = useTranslation("common") + return ( <> - Create Next App + {t("cna")} @@ -112,3 +123,10 @@ export default function Home() { ) } + +// or getServerSideProps: GetServerSideProps = async ({ locale }) +export const getStaticProps: GetStaticProps = async ({ locale }) => ({ + props: { + ...(await serverSideTranslations(locale ?? "en", ["common", "footer"])), + }, +})