Skip to content

Commit

Permalink
feature: add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
gcor committed Apr 2, 2023
1 parent b96047d commit e9eba36
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 12 deletions.
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const nextConfig = {
images: {
unoptimized: true,
},
i18n: {
locales: ["ru", "en"],
defaultLocale: "ru",
},
};

module.exports = nextConfig;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint": "8.36.0",
"eslint-config-next": "13.2.4",
"next": "13.2.4",
"next-intl": "^2.12.0",
"postcss": "^8.4.21",
"postcss-nesting": "^11.2.1",
"react": "^18.2.0",
Expand Down
86 changes: 86 additions & 0 deletions pnpm-lock.yaml

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

18 changes: 9 additions & 9 deletions src/components/header/Header.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { useEffect } from "react";
import { useTranslations } from "next-intl";
import cn from "classnames";
import styles from "./Header.module.css";
import { initSmoothScroll } from "./smooth-scroll";

export function Header() {
const t = useTranslations("Dev");

useEffect(() => {
initSmoothScroll();
}, []);

return (
<header className={cn(styles.header)}>
<div className={cn(styles.header__text)}>
<p data-id="header-text">
Это Код Екатеринбурга&nbsp;&mdash; команда, которая сделает
невозможное. Невыполнимое, сложное и&nbsp;безумное. Сделает&nbsp;то,
что никто не&nbsp;сможет. Это тот проект, о&nbsp;котором
вы&nbsp;мечтали. Это&nbsp;&mdash; проект судьбы.
</p>
<p
data-id="header-text"
dangerouslySetInnerHTML={{ __html: t.raw("header") }}
></p>
<a
className={cn(styles.header__more)}
href="#about"
data-id="header-more"
>
Узнать, что мы&nbsp;будем делать
</a>
dangerouslySetInnerHTML={{ __html: t.raw("learnMore") }}
/>
</div>
</header>
);
Expand Down
7 changes: 7 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Dev": {
"title": "Ekaterinburg code",
"header": "This is the Yekaterinburg Code - a team that will achieve the impossible. The unattainable, complex, and insane. They will do what no one else can. This is the project you've dreamed of. It is the project of destiny.",
"learnMore": "Find out what we will be doing"
}
}
7 changes: 7 additions & 0 deletions src/locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Dev": {
"title": "Код Екатеринбурга",
"header": "Это Код Екатеринбурга&nbsp;&mdash; команда, которая сделает невозможное. Невыполнимое, сложное и&nbsp;безумное. Сделает&nbsp;то, что никто не&nbsp;сможет. Это тот проект, о&nbsp;котором вы&nbsp;мечтали. Это&nbsp;&mdash; проект судьбы.",
"learnMore": "Узнать, что мы&nbsp;будем делать"
}
}
9 changes: 7 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { NextIntlProvider } from "next-intl";
import type { AppProps } from "next/app";
import "@/styles/globals.css";
import "../../public/fonts/index.css";
import "../../public/font-jetbrains-mono/index.css";
import type { AppProps } from "next/app";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
return (
<NextIntlProvider messages={pageProps.messages}>
<Component {...pageProps} />
</NextIntlProvider>
);
}
14 changes: 13 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @next/next/no-img-element */
import Head from "next/head";
import { useTranslations } from "next-intl";
import cn from "classnames";
import styles from "@/components/page/Page.module.css";
import { Preview } from "@/components/preview/Preview";
Expand All @@ -9,12 +10,15 @@ import { Road } from "@/components/road/Road";
import { Iframe } from "@/components/iframe/Iframe";
import { Team } from "@/components/team/Team";
import { MainAction } from "@/components/action/MainAction";
import { GetStaticProps } from "next";

export default function Home() {
const t = useTranslations("Dev");

return (
<>
<Head>
<title>Код Екатеринбурга</title>
<title>{t("title")}</title>
</Head>
<Preview>
<Header />
Expand Down Expand Up @@ -146,3 +150,11 @@ export default function Home() {
</>
);
}

export const getStaticProps: GetStaticProps = async (context) => {
return {
props: {
messages: (await import(`../locales/${context.locale}.json`)).default,
},
};
};

0 comments on commit e9eba36

Please sign in to comment.