Skip to content

Commit 7287107

Browse files
authored
Merge pull request #1967 from Plant-for-the-Planet-org/feature/migrate-nexti18next-to-nextintl
Feature/migrate nexti18next to nextintl
2 parents 4e915f2 + 1fbc84a commit 7287107

File tree

395 files changed

+19422
-38854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

395 files changed

+19422
-38854
lines changed

.storybook/i18n.js

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,98 @@
1-
import i18n from 'i18next';
2-
import Backend from 'i18next-http-backend';
3-
import LanguageDetector from 'i18next-browser-languagedetector';
4-
import { initReactI18next } from 'react-i18next';
1+
import bulkCodes from '../public/static/locales/en/bulkCodes.json';
2+
import common from '../public/static/locales/en/common.json';
3+
import country from '../public/static/locales/en/country.json';
4+
import donate from '../public/static/locales/en/donate.json';
5+
import donationLink from '../public/static/locales/en/donationLink.json';
6+
import editProfile from '../public/static/locales/en/editProfile.json';
7+
import giftfunds from '../public/static/locales/en/giftfunds.json';
8+
import leaderboard from '../public/static/locales/en/leaderboard.json';
9+
import managePayouts from '../public/static/locales/en/managePayouts.json';
10+
import manageProjects from '../public/static/locales/en/manageProjects.json';
11+
import maps from '../public/static/locales/en/maps.json';
12+
import me from '../public/static/locales/en/me.json';
13+
import planet from '../public/static/locales/en/planet.json';
14+
import planetcash from '../public/static/locales/en/planetcash.json';
15+
import profile from '../public/static/locales/en/profile.json';
16+
import redeem from '../public/static/locales/en/redeem.json';
17+
import registerTrees from '../public/static/locales/en/registerTrees.json';
18+
import tenants from '../public/static/locales/en/tenants.json';
19+
import treemapper from '../public/static/locales/en/treemapper.json';
20+
import treemapperAnalytics from '../public/static/locales/en/treemapperAnalytics.json';
521

6-
i18n
7-
.use(Backend)
8-
.use(LanguageDetector)
9-
.use(initReactI18next)
10-
.init({
11-
fallbackLng: 'en',
12-
debug: true,
13-
backend: {
14-
loadPath: '/static/locales/{{lng}}/{{ns}}.json',
15-
},
16-
});
22+
import bulkCodesDE from '../public/static/locales/de/bulkCodes.json';
23+
import commonDE from '../public/static/locales/de/common.json';
24+
import countryDE from '../public/static/locales/de/country.json';
25+
import donateDE from '../public/static/locales/de/donate.json';
26+
import donationLinkDE from '../public/static/locales/de/donationLink.json';
27+
import editProfileDE from '../public/static/locales/de/editProfile.json';
28+
import giftfundsDE from '../public/static/locales/de/giftfunds.json';
29+
import leaderboardDE from '../public/static/locales/de/leaderboard.json';
30+
import managePayoutsDE from '../public/static/locales/de/managePayouts.json';
31+
import manageProjectsDE from '../public/static/locales/de/manageProjects.json';
32+
import mapsDE from '../public/static/locales/de/maps.json';
33+
import meDE from '../public/static/locales/de/me.json';
34+
import planetDE from '../public/static/locales/de/planet.json';
35+
import planetcashDE from '../public/static/locales/de/planetcash.json';
36+
import profileDE from '../public/static/locales/de/profile.json';
37+
import redeemDE from '../public/static/locales/de/redeem.json';
38+
import registerTreesDE from '../public/static/locales/de/registerTrees.json';
39+
import tenantsDE from '../public/static/locales/de/tenants.json';
40+
import treemapperDE from '../public/static/locales/de/treemapper.json';
41+
import treemapperAnalyticsDE from '../public/static/locales/de/treemapperAnalytics.json';
1742

18-
export default i18n;
43+
import deepmerge from 'deepmerge';
44+
45+
const messages_en = {
46+
...bulkCodes,
47+
...common,
48+
...country,
49+
...donate,
50+
...donationLink,
51+
...editProfile,
52+
...giftfunds,
53+
...leaderboard,
54+
...managePayouts,
55+
...manageProjects,
56+
...maps,
57+
...me,
58+
...planet,
59+
...planetcash,
60+
...profile,
61+
...redeem,
62+
...registerTrees,
63+
...tenants,
64+
...treemapper,
65+
...treemapperAnalytics,
66+
};
67+
68+
const messages_de = {
69+
...bulkCodesDE,
70+
...commonDE,
71+
...countryDE,
72+
...donateDE,
73+
...donationLinkDE,
74+
...editProfileDE,
75+
...giftfundsDE,
76+
...leaderboardDE,
77+
...managePayoutsDE,
78+
...manageProjectsDE,
79+
...mapsDE,
80+
...meDE,
81+
...planetDE,
82+
...planetcashDE,
83+
...profileDE,
84+
...redeemDE,
85+
...registerTreesDE,
86+
...tenantsDE,
87+
...treemapperDE,
88+
...treemapperAnalyticsDE,
89+
};
90+
91+
const getMessages = (locale) => {
92+
if (locale === 'de') {
93+
return deepmerge(messages_en, messages_de);
94+
}
95+
return messages_en;
96+
};
97+
98+
export default getMessages;

.storybook/preview.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import './storybook.scss';
33
import { ThemeProvider as MUIThemeProvider } from '@mui/material';
44
import materialTheme from '../src/theme/themeStyles';
55
import { ThemeProvider } from '@storybook/theming';
6-
import { I18nextProvider } from 'react-i18next';
7-
import i18n from './i18n';
8-
import { useEffect } from 'react';
9-
10-
// import { ThemeProvider } from 'emotion-theming';
6+
import getMessages from './i18n';
7+
import { NextIntlClientProvider } from 'next-intl';
118

129
/*
1310
* Global decorator to apply the styles to all stories
@@ -16,20 +13,16 @@ import { useEffect } from 'react';
1613
*/
1714
export const decorators = [
1815
(Story, context) => {
19-
const { locale } = context.globals;
20-
21-
useEffect(() => {
22-
i18n.changeLanguage(locale);
23-
}, [locale]);
16+
const locale = context.globals.locale;
2417

2518
return (
26-
<I18nextProvider i18n={i18n}>
19+
<NextIntlClientProvider messages={getMessages(locale)} locale={locale}>
2720
<MUIThemeProvider theme={materialTheme}>
2821
<ThemeProvider theme={materialTheme}>
2922
<Story />
3023
</ThemeProvider>
3124
</MUIThemeProvider>
32-
</I18nextProvider>
25+
</NextIntlClientProvider>
3326
);
3427
},
3528
];

global.d.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Use type safe message keys with `next-intl`
2+
type MessagesBulkCodes =
3+
typeof import('./public/static/locales/en/bulkCodes.json');
4+
type MessagesCommon = typeof import('./public/static/locales/en/common.json');
5+
type MessagesCountry = typeof import('./public/static/locales/en/country.json');
6+
type MessagesDonate = typeof import('./public/static/locales/en/donate.json');
7+
type MessagesDonationLink =
8+
typeof import('./public/static/locales/en/donationLink.json');
9+
type MessagesEditProfile =
10+
typeof import('./public/static/locales/en/editProfile.json');
11+
type MessagesGiftfunds =
12+
typeof import('./public/static/locales/en/giftfunds.json');
13+
type MessagesLeaderboard =
14+
typeof import('./public/static/locales/en/leaderboard.json');
15+
type MessagesManagePayouts =
16+
typeof import('./public/static/locales/en/managePayouts.json');
17+
type MessagesManageProjects =
18+
typeof import('./public/static/locales/en/manageProjects.json');
19+
type MessagesMaps = typeof import('./public/static/locales/en/maps.json');
20+
type MessagesMe = typeof import('./public/static/locales/en/me.json');
21+
type MessagesPlanet = typeof import('./public/static/locales/en/planet.json');
22+
type MessagesPlanetcash =
23+
typeof import('./public/static/locales/en/planetcash.json');
24+
type MessagesProfile = typeof import('./public/static/locales/en/profile.json');
25+
type MessagesRedeem = typeof import('./public/static/locales/en/redeem.json');
26+
type MessagesRegisterTrees =
27+
typeof import('./public/static/locales/en/registerTrees.json');
28+
type MessagesTenants = typeof import('./public/static/locales/en/tenants.json');
29+
type MessagesTreemapper =
30+
typeof import('./public/static/locales/en/treemapper.json');
31+
type MessagesTreemapperAnalytics =
32+
typeof import('./public/static/locales/en/treemapperAnalytics.json');
33+
34+
type Messages = MessagesBulkCodes &
35+
MessagesCommon &
36+
MessagesCountry &
37+
MessagesDonate &
38+
MessagesDonationLink &
39+
MessagesEditProfile &
40+
MessagesGiftfunds &
41+
MessagesLeaderboard &
42+
MessagesManagePayouts &
43+
MessagesManageProjects &
44+
MessagesMaps &
45+
MessagesMe &
46+
MessagesPlanet &
47+
MessagesPlanetcash &
48+
MessagesProfile &
49+
MessagesRedeem &
50+
MessagesRegisterTrees &
51+
MessagesTenants &
52+
MessagesTreemapper &
53+
MessagesTreemapperAnalytics;
54+
55+
declare interface IntlMessages extends Messages {}

i18n-config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// i18n config for next-intl
2+
export const i18nConfig = {
3+
defaultLocale: 'en',
4+
locales: ['en', 'de', 'cs', 'es', 'fr', 'it', 'pt-BR'],
5+
};
6+
7+
export type Locale = (typeof i18nConfig)['locales'][number];

i18n.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { getRequestConfig } from 'next-intl/server';
2+
import deepmerge from 'deepmerge';
3+
4+
// IMP - Import any new translation file here in `userMessages` add `defaultMessages`, to enable translation auto complete.
5+
export default getRequestConfig(async ({ locale }) => {
6+
const userMessages = {
7+
...(await import(`./public/static/locales/${locale}/bulkCodes.json`))
8+
.default,
9+
...(await import(`./public/static/locales/${locale}/common.json`)).default,
10+
...(await import(`./public/static/locales/${locale}/country.json`)).default,
11+
...(await import(`./public/static/locales/${locale}/donate.json`)).default,
12+
...(await import(`./public/static/locales/${locale}/donationLink.json`))
13+
.default,
14+
...(await import(`./public/static/locales/${locale}/editProfile.json`))
15+
.default,
16+
...(await import(`./public/static/locales/${locale}/giftfunds.json`))
17+
.default,
18+
...(await import(`./public/static/locales/${locale}/leaderboard.json`))
19+
.default,
20+
...(await import(`./public/static/locales/${locale}/managePayouts.json`))
21+
.default,
22+
...(await import(`./public/static/locales/${locale}/manageProjects.json`))
23+
.default,
24+
...(await import(`./public/static/locales/${locale}/maps.json`)).default,
25+
...(await import(`./public/static/locales/${locale}/me.json`)).default,
26+
...(await import(`./public/static/locales/${locale}/planet.json`)).default,
27+
...(await import(`./public/static/locales/${locale}/planetcash.json`))
28+
.default,
29+
...(await import(`./public/static/locales/${locale}/profile.json`)).default,
30+
...(await import(`./public/static/locales/${locale}/redeem.json`)).default,
31+
...(await import(`./public/static/locales/${locale}/registerTrees.json`))
32+
.default,
33+
...(await import(`./public/static/locales/${locale}/tenants.json`)).default,
34+
...(await import(`./public/static/locales/${locale}/treemapper.json`))
35+
.default,
36+
...(
37+
await import(`./public/static/locales/${locale}/treemapperAnalytics.json`)
38+
).default,
39+
};
40+
41+
const defaultMessages = {
42+
...(await import(`./public/static/locales/en/bulkCodes.json`)).default,
43+
...(await import(`./public/static/locales/en/common.json`)).default,
44+
...(await import(`./public/static/locales/en/country.json`)).default,
45+
...(await import(`./public/static/locales/en/donate.json`)).default,
46+
...(await import(`./public/static/locales/en/donationLink.json`)).default,
47+
...(await import(`./public/static/locales/en/editProfile.json`)).default,
48+
...(await import(`./public/static/locales/en/giftfunds.json`)).default,
49+
...(await import(`./public/static/locales/en/leaderboard.json`)).default,
50+
...(await import(`./public/static/locales/en/managePayouts.json`)).default,
51+
...(await import(`./public/static/locales/en/manageProjects.json`)).default,
52+
...(await import(`./public/static/locales/en/maps.json`)).default,
53+
...(await import(`./public/static/locales/en/me.json`)).default,
54+
...(await import(`./public/static/locales/en/planet.json`)).default,
55+
...(await import(`./public/static/locales/en/planetcash.json`)).default,
56+
...(await import(`./public/static/locales/en/profile.json`)).default,
57+
...(await import(`./public/static/locales/en/redeem.json`)).default,
58+
...(await import(`./public/static/locales/en/registerTrees.json`)).default,
59+
...(await import(`./public/static/locales/en/tenants.json`)).default,
60+
...(await import(`./public/static/locales/en/treemapper.json`)).default,
61+
...(await import(`./public/static/locales/en/treemapperAnalytics.json`))
62+
.default,
63+
};
64+
65+
const messages: IntlMessages = deepmerge(defaultMessages, userMessages);
66+
67+
// Single file, no fallback
68+
// messages: (await import(`./messages/${locale}.json`)).default,
69+
70+
return { messages };
71+
});

0 commit comments

Comments
 (0)