Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit d9ebf74

Browse files
committed
react-i18next
1 parent 49d0f2f commit d9ebf74

File tree

8 files changed

+66
-29
lines changed

8 files changed

+66
-29
lines changed

components/NavPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type NavPanelProps = {
66
backHref?: string;
77
backText?: string;
88
nextHref?: string
9-
nextText?: string
9+
nextText?: string | null
1010
}
1111

1212
export default function NavPanel(props: NavPanelProps) {

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@navikt/ds-react": "^2.0.6",
1616
"@navikt/nav-dekoratoren-moduler": "^1.8.1",
1717
"date-fns": "^2.29.3",
18+
"i18next": "^22.4.6",
1819
"next": "13.0.5",
1920
"react": "18.2.0",
2021
"react-dom": "18.2.0",

src/pages/_app.tsx

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,68 @@
11
import "../../styles/globals.css";
22
import "@navikt/ds-css";
33

4-
import type { AppProps } from "next/app";
5-
import { onLanguageSelect } from "@navikt/nav-dekoratoren-moduler";
6-
74
import i18n from 'i18next';
85
import { initReactI18next } from 'react-i18next';
96

7+
import { onLanguageSelect } from "@navikt/nav-dekoratoren-moduler";
8+
import type { AppProps } from "next/app";
9+
10+
11+
// Await init?
1012
i18n
1113
// pass the i18n instance to react-i18next.
1214
.use(initReactI18next)
1315
// init i18next
1416
// for all options read: https://www.i18next.com/overview/configuration-options
1517
.init({
16-
debug: true,
18+
debug: false,
1719
fallbackLng: 'nb',
1820
interpolation: {
1921
escapeValue: false, // not needed for react as it escapes by default
2022
},
2123
resources: {
22-
en: {
23-
translation: {
24-
"menuSend": "Send",
25-
"menuHistory": "Previous report cards",
26-
"menuAbout": "About",
27-
"menuFaq": "FAQ",
28-
"title": "New solution"
29-
}
30-
},
3124
nb: {
3225
translation: {
3326
"menuSend": "Send",
3427
"menuHistory": "Tidligere meldekort",
3528
"menuAbout": "Om meldekort",
3629
"menuFaq": "Ofte stilte spørsmål",
37-
"title": "Ny løsning"
30+
31+
"indexTitle": "Ny løsning",
32+
"indexDescription": "Du kan sende inn meldekort for følgende perioder:",
33+
34+
"historyTitle": "Tidligere meldekort",
35+
36+
"aboutTitle": "Om meldekort",
37+
38+
"faqTitle": "Ofte stilte spørsmål",
39+
40+
"period": "Periode",
41+
"date": "Dato",
42+
"week": "Uke",
43+
"startFillingOut": "Begynn utfylling"
44+
}
45+
},
46+
en: {
47+
translation: {
48+
"menuSend": "Send",
49+
"menuHistory": "Previous report cards",
50+
"menuAbout": "About",
51+
"menuFaq": "FAQ",
52+
53+
"indexTitle": "New solution",
54+
"indexDescription": "You can submit registration cards for the following periods:",
55+
56+
"historyTitle": "Previous report cards",
57+
58+
"aboutTitle": "About report cards",
59+
60+
"faqTitle": "FAQ",
61+
62+
"period": "Period",
63+
"date": "Date",
64+
"week": "Week",
65+
"startFillingOut": "Start filling out"
3866
}
3967
}
4068
}

src/pages/about.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { GuidePanel } from "@navikt/ds-react";
22
import Menu from "../../components/Menu";
33
import Spacer from "../../components/Spacer";
4+
import { useTranslation } from "react-i18next";
45

56
export default function Page() {
67

8+
const { t } = useTranslation();
9+
710
return (
811
<main>
912
<Menu />
1013

11-
<h1>Om meldekort</h1>
14+
<h1>{t('aboutTitle')}</h1>
1215

1316
<GuidePanel poster>
1417
Saksbehandlingstiden varierer fra kommune til kommune. Hvis det går mer

src/pages/faq.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { Accordion } from "@navikt/ds-react";
22
import Menu from "../../components/Menu";
33
import Spacer from "../../components/Spacer";
4+
import { useTranslation } from "react-i18next";
45

56
export default function Page() {
67

8+
const { t } = useTranslation();
9+
710
return (
811
<main>
912
<Menu />
1013

11-
<h1>Ofte stilte spørsmål</h1>
14+
<h1>{t('faqTitle')}</h1>
1215

1316
<Accordion>
1417
<Accordion.Item>

src/pages/history.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { Table } from "@navikt/ds-react";
22
import Menu from "../../components/Menu";
33
import Spacer from "../../components/Spacer";
44
import { format, getISOWeek } from "date-fns";
5+
import { useTranslation } from "react-i18next";
56

67
export default function Page() {
78

9+
const { t } = useTranslation();
10+
811
const data = [
912
{
1013
startDate: new Date(2022, 9, 24, 12, 0),
@@ -20,21 +23,21 @@ export default function Page() {
2023
<main>
2124
<Menu />
2225

23-
<h1>Tidligere meldekort</h1>
26+
<h1>{t('historyTitle')}</h1>
2427

2528
<Table zebraStripes>
2629
<Table.Header>
2730
<Table.Row>
28-
<Table.HeaderCell scope="col">Periode</Table.HeaderCell>
29-
<Table.HeaderCell scope="col">Dato</Table.HeaderCell>
31+
<Table.HeaderCell scope="col">{t('period')}</Table.HeaderCell>
32+
<Table.HeaderCell scope="col">{t('date')}</Table.HeaderCell>
3033
</Table.Row>
3134
</Table.Header>
3235
<Table.Body>
3336
{data.map(({ startDate, endDate }) => {
3437
return (
3538
<Table.Row key={startDate.getTime()}>
3639
<Table.HeaderCell scope="row">
37-
Uke {getISOWeek(startDate)} - {getISOWeek(endDate)}
40+
{t('week')} {getISOWeek(startDate)} - {getISOWeek(endDate)}
3841
</Table.HeaderCell>
3942
<Table.DataCell>
4043
{format(startDate, "dd.MM.yyyy")} - {format(endDate, "dd.MM.yyyy")}

src/pages/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ export default function Page() {
2828
<main>
2929
<Menu />
3030

31-
<h1>{t('title')}</h1>
32-
<p>Du kan sende inn meldekort for følgende perioder:</p>
31+
<h1>{t('indexTitle')}</h1>
32+
<p>{t('indexDescription')}</p>
3333

3434
<Table zebraStripes>
3535
<Table.Header>
3636
<Table.Row>
37-
<Table.HeaderCell scope="col">Periode</Table.HeaderCell>
38-
<Table.HeaderCell scope="col">Dato</Table.HeaderCell>
37+
<Table.HeaderCell scope="col">{t('period')}</Table.HeaderCell>
38+
<Table.HeaderCell scope="col">{t('date')}</Table.HeaderCell>
3939
</Table.Row>
4040
</Table.Header>
4141
<Table.Body>
4242
{data.map(({ startDate, endDate }) => {
4343
return (
4444
<Table.Row key={startDate.getTime()}>
4545
<Table.HeaderCell scope="row">
46-
Uke {getISOWeek(startDate)} - {getISOWeek(endDate)}
46+
{t('week')} {getISOWeek(startDate)} - {getISOWeek(endDate)}
4747
</Table.HeaderCell>
4848
<Table.DataCell>
4949
{format(startDate, "dd.MM.yyyy")} - {format(endDate, "dd.MM.yyyy")}
@@ -56,7 +56,7 @@ export default function Page() {
5656

5757
<Spacer />
5858

59-
<NavPanel nextHref="/form" nextText="Begynn utfylling" />
59+
<NavPanel nextHref="/form" nextText={t('startFillingOut')} />
6060
</main>
6161
);
6262
}

0 commit comments

Comments
 (0)