Skip to content

Commit 5193d63

Browse files
authored
Merge pull request #8 from Craftserve/feature/i18n
i18n configuration review
2 parents 5ab2d61 + dfb75e4 commit 5193d63

File tree

7 files changed

+81
-6
lines changed

7 files changed

+81
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
},
1212
"dependencies": {
1313
"@stitches/react": "^1.2.8",
14+
"i18next": "^25.3.6",
1415
"react": "^19.1.0",
1516
"react-dom": "^19.1.0",
17+
"react-i18next": "^15.6.1",
1618
"react-icons": "^5.5.0",
1719
"react-router-dom": "^7.6.3"
1820
},

src/i18n/en.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"JoinUs": {
3+
"title": "Join Us"
4+
},
5+
"Contact": {
6+
"title": "Contact Us"
7+
},
8+
"FindOut": {
9+
"title": "Find Out"
10+
},
11+
"MoreAboutUs": {
12+
"title": "More About Us"
13+
},
14+
"WhyUs": {
15+
"title": "Why Us"
16+
}
17+
}

src/i18n/i18n.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import i18n from "i18next";
2+
import { initReactI18next } from "react-i18next";
3+
4+
import pl from './pl.json'
5+
import en from './en.json'
6+
7+
const DEFAULT_LANG = "en-US";
8+
9+
const userLang = navigator.language || DEFAULT_LANG;
10+
const resources = {
11+
"pl-PL": pl,
12+
"en-US": en,
13+
"en-GB": en,
14+
};
15+
16+
i18n
17+
.use(initReactI18next) // passes i18n down to react-i18next
18+
.init({
19+
resources,
20+
lng: userLang,
21+
keySeparator: false,
22+
nsSeparator: ".",
23+
fallbackLng: DEFAULT_LANG,
24+
cache: {
25+
enabled: true,
26+
},
27+
interpolation: {
28+
escapeValue: false,
29+
},
30+
});
31+
32+
export default i18n;

src/i18n/pl.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"JoinUs": {
3+
"title": "Dołącz do nas"
4+
},
5+
"Contact": {
6+
"title": "Zkontaktuj się"
7+
},
8+
"FindOut": {
9+
"title": "Dowiedz się"
10+
},
11+
"MoreAboutUs": {
12+
"title": "Więcej o nas"
13+
},
14+
"WhyUs": {
15+
"title": "Dlaczego my"
16+
}
17+
}

src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
33
import App from "./App.tsx";
44
import { BrowserRouter } from "react-router-dom";
5+
import "./i18n/i18n.js";
56

67
createRoot(document.getElementById("root")!).render(
78
<StrictMode>

src/modules/shared/components/navbar/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import Button from "../button";
1313
import { FaPhoneAlt } from "react-icons/fa";
1414
import { IoMenu } from "react-icons/io5";
1515
import { useState } from "react";
16+
import { useTranslation } from "react-i18next";
1617

1718
const Navbar = () => {
1819
const [isMenuOpen, setIsMenuOpen] = useState<boolean>(false);
1920

21+
const {t} = useTranslation();
22+
2023
const toggleMenu = (): void => {
2124
setIsMenuOpen(!isMenuOpen);
2225
};
@@ -32,13 +35,13 @@ const Navbar = () => {
3235
<StyledMenuList>
3336
<StyledMenuItem>
3437
<Link className="nav-link" to="/whyus">
35-
Dlaczego my
38+
{t("WhyUs.title")}
3639
</Link>
3740
</StyledMenuItem>
3841
<StyledMenuItem>
3942
<Button variant="secondary" fontSize="16px">
4043
<FaPhoneAlt />
41-
Kontakt
44+
{t("Contact.title")}
4245
</Button>
4346
</StyledMenuItem>
4447
</StyledMenuList>

src/screens/HeroScreen/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import Navbar from "../../modules/shared/components/navbar";
66
import Box from "../../modules/shared/components/box";
77
import Card from "../../modules/shared/components/card";
88
import ImageWrapper from "./style";
9+
import { useTranslation } from "react-i18next";
910

1011
const HeroScreen = () => {
12+
const {t} = useTranslation();
13+
1114
return (
1215
<>
1316
<Layout>
@@ -16,17 +19,17 @@ const HeroScreen = () => {
1619
<Box display="flex" gap="20px" margin="20px">
1720
<Button variant="primary">
1821
<FaPhoneAlt />
19-
Dołącz do nas
22+
{t("JoinUs.title")}
2023
</Button>
2124
<Button variant="secondary">
2225
<FaPhoneAlt />
23-
Kontakt
26+
{t("Contact.title")}
2427
</Button>
2528
<Button variant="outlined">
2629
<IoIosInformationCircle size="1.8em" />
2730
<Box display="flex" direction="column">
28-
<span style={{ fontSize: "14px", fontWeight: "normal" }}>dowiedz się</span>
29-
<span>Więcej o nas</span>
31+
<span style={{ fontSize: "14px", fontWeight: "normal" }}>{t("FindOut.title")}</span>
32+
<span>{t("MoreAboutUs.title")}</span>
3033
</Box>
3134
</Button>
3235
</Box>

0 commit comments

Comments
 (0)