Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/migrate nexti18next to nextintl #1967

Merged
merged 82 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1211737
chore: install next-intl packages
mohitb35 Jan 30, 2024
4600f25
refactor: move pages into sites/[slug][locale] subfolder
mohitb35 Jan 30, 2024
8962eec
feat: set up i18n.ts and typescript for messages
mohitb35 Feb 15, 2024
a90b7fc
Merge from 'feature/my_forest' to feature/migrate-nexti18next-to-next…
mohitb35 Feb 15, 2024
4578a48
feat: set up middleware for i18n routing
mohitb35 Feb 16, 2024
19cfdd9
feat: adds default fallback behaviour for unsupported locales in url
mohitb35 Feb 19, 2024
c59f9d0
feat: sets up static paths for locale all routes
mohitb35 Feb 19, 2024
28c70ce
fix: fixes invalid import path
mohitb35 Feb 19, 2024
80399ad
feat: integrates next-intl with / route
mohitb35 Feb 20, 2024
549fc1d
Merge from 'feature/my_forest' to feature/migrate-nexti18next-to-next…
mohitb35 Feb 21, 2024
472876a
feat: updates LanguageSelection logic (footer)
mohitb35 Feb 21, 2024
4c431ed
feat: enclose translation files in outer namespace (de/en only)
mohitb35 Feb 21, 2024
4e79720
feat: adapts interpolation text format in translation files for next-…
mohitb35 Feb 21, 2024
a9cce0c
feat: updates translation code in components
mohitb35 Feb 22, 2024
9411162
feat: integrates next-intl with project details page
mohitb35 Feb 23, 2024
4c13cb9
Merge from 'develop' to feature/migrate-nexti18next-to-nextintl
mohitb35 Feb 29, 2024
beb63f2
feat: integrates next-intl with login page
mohitb35 Mar 4, 2024
b025ab8
feat: integrates next-intl with /profile
mohitb35 Mar 4, 2024
6fbc46d
feat: sets up next-intl for settings/widget pages
mohitb35 Mar 4, 2024
c2c22ce
refactor: introduces getMessagesForPage utility function
mohitb35 Mar 4, 2024
285eb1c
feat: integrates next-intl with pages (part 1)
mohitb35 Mar 4, 2024
1f545fc
feat: integrates next-intl with pages (part 2)
mohitb35 Mar 4, 2024
5a8d090
feat: integrates next-intl with pages (part 3)
mohitb35 Mar 5, 2024
7358a59
refactor: updates getMessagesForPage to import JSON files correctly
mohitb35 Mar 5, 2024
5565f1f
fix: remove unused deepmerge imports
mohitb35 Mar 5, 2024
47b7048
refactor: refactor Props interface for pages to include PageProps
mohitb35 Mar 5, 2024
32fcac3
feat: integrates next-intl on 404 page
mohitb35 Mar 8, 2024
c3aaa4f
feat: migrates existing translation files from i18next to next-intl f…
mohitb35 Mar 8, 2024
5a4c510
refactor: updates localization strings as per next-intl
mohitb35 Mar 8, 2024
3a2cc88
feat: integrates next-intl with storybook
mohitb35 Mar 11, 2024
a64fe1d
refactor: remove unused dependencies/code relating to i18next
mohitb35 Mar 11, 2024
be05aad
Merge 'develop' to feature/migrate-nexti18next-to-nextintl
mohitb35 Mar 12, 2024
debad20
refactor: removes unused login.json translation files
mohitb35 Mar 12, 2024
150bae6
refactor: removes i18next pluralization related strings
mohitb35 Mar 12, 2024
def1f0a
fix: corrects typos in translation namespaces
mohitb35 Mar 13, 2024
74da2b5
🌐 Language update from LingoHub 🤖
lingohub[bot] Mar 13, 2024
dd046bd
Merge pull request #2004 from Plant-for-the-Planet-org/lingohub_langu…
mohitb35 Mar 13, 2024
bf5ce3b
🌐 Language update from LingoHub 🤖
lingohub[bot] Mar 13, 2024
b535166
Merge pull request #2005 from Plant-for-the-Planet-org/lingohub_langu…
mohitb35 Mar 13, 2024
9c783e9
fix: resolves missing message warning in SelectLanguageAndCountry
mohitb35 Mar 13, 2024
f8cbe30
refactor: removes commented import
mohitb35 Mar 13, 2024
cf6f092
fix: update localeRegex used in removeLocaleFromUrl
mohitb35 Mar 13, 2024
cbf739b
fix: resolves missing message warning for Edit Profile
mohitb35 Mar 13, 2024
031b5a0
refactor: refactor i18nConfig and locale logic in middleware
mohitb35 Mar 13, 2024
94abc57
refactor: handles errors in getLocale function
mohitb35 Mar 13, 2024
58196f0
refactor: removes console logs
mohitb35 Mar 13, 2024
6adf1ce
fix: removes unsupported country option
mohitb35 Mar 13, 2024
953271d
fix: updates checks on `asPath` in profile to include `locale`
mohitb35 Mar 13, 2024
c398f95
Merge branch 'develop' into feature/migrate-nexti18next-to-nextintl
mohitb35 Mar 18, 2024
d24c1f5
refactor: removes instances of destructuring of `router` for code rea…
mohitb35 Mar 20, 2024
c6d36ab
fix: minor updates to usage of `router` within pages/
mohitb35 Mar 20, 2024
0011963
fix: resolves github-advanced-security warning for URL containing use…
mohitb35 Mar 21, 2024
48b91f2
fix: removes unused `language` from QueryParamsContext
mohitb35 Mar 21, 2024
19187ad
refactor: updates DirectGift to use Link instead of useRouter
mohitb35 Mar 21, 2024
7118d91
refactor: reduces duplication in project navigation logic in Markers …
mohitb35 Mar 21, 2024
b2fd3fa
refactor: removes instances of `router` destructuring for readability
mohitb35 Mar 21, 2024
2f6eedf
refactor: minor changes to routing/route comparison logic
mohitb35 Mar 21, 2024
189b669
Merge 'develop' to feature/migrate-nexti18next-to-nextintl
mohitb35 Mar 21, 2024
ed7dbfa
refactor: minor cleanup
mohitb35 Mar 21, 2024
7e61e41
fix: updates pluralized translation strings to include number
mohitb35 Mar 22, 2024
dcd6254
fix: resolves missing translation import warnings
mohitb35 Mar 22, 2024
f8d1b4b
refactor: delete unused translations
mohitb35 Mar 22, 2024
db0fe8a
🌐 Language update from LingoHub 🤖
lingohub[bot] Mar 22, 2024
642e0fa
feat: corrects share text
mohitb35 Mar 22, 2024
12fffee
fix: corrects add project description
mohitb35 Mar 22, 2024
3c75b3c
Merge pull request #2017 from Plant-for-the-Planet-org/lingohub_langu…
mohitb35 Mar 22, 2024
735ee19
fix: resolves issue (lang change on navigation)
mohitb35 Mar 26, 2024
b7c0b2a
feat: filters available locales based on tenant
mohitb35 Apr 2, 2024
f24ee4d
docs: add console logs to identify points of failure in middleware
mohitb35 Apr 2, 2024
048df3f
Merge branch 'develop' into feature/migrate-nexti18next-to-nextintl
mohitb35 Apr 3, 2024
df4afb1
Merge from 'develop' to feature/migrate-nexti18next-to-nextintl
mohitb35 Apr 4, 2024
9395ee9
fix: resolves locale mismatch while fetching projects
mohitb35 Apr 8, 2024
79f255d
Merge from 'develop' into feature/migrate-nexti18next-to-nextintl
mohitb35 Apr 15, 2024
cd5d55c
fix: replaces a.plant-for-the-planet links again
mohitb35 Apr 15, 2024
dd4c975
chore: updates package lock to fix build errors
mohitb35 Apr 15, 2024
3b24f7b
fix: resolves language switching bug on back button (single project)
mohitb35 Apr 15, 2024
a13b08f
fix: resolves blank map on switching language (project details pg)
mohitb35 Apr 16, 2024
b6abe89
fix: fixes issue (no site query string on first load of project detai…
mohitb35 Apr 16, 2024
b7714f3
fix: resolves caching issue after updating language
mohitb35 Apr 16, 2024
522ae94
fix: resolves language caching issue for back button click (single pr…
mohitb35 Apr 16, 2024
aac6bb4
fix: removes additional history item on language change
mohitb35 Apr 17, 2024
1fbc84a
fix: resolves cache issue for locale in project detail pages
mohitb35 Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
112 changes: 96 additions & 16 deletions .storybook/i18n.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,98 @@
import i18n from 'i18next';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import bulkCodes from '../public/static/locales/en/bulkCodes.json';
import common from '../public/static/locales/en/common.json';
import country from '../public/static/locales/en/country.json';
import donate from '../public/static/locales/en/donate.json';
import donationLink from '../public/static/locales/en/donationLink.json';
import editProfile from '../public/static/locales/en/editProfile.json';
import giftfunds from '../public/static/locales/en/giftfunds.json';
import leaderboard from '../public/static/locales/en/leaderboard.json';
import managePayouts from '../public/static/locales/en/managePayouts.json';
import manageProjects from '../public/static/locales/en/manageProjects.json';
import maps from '../public/static/locales/en/maps.json';
import me from '../public/static/locales/en/me.json';
import planet from '../public/static/locales/en/planet.json';
import planetcash from '../public/static/locales/en/planetcash.json';
import profile from '../public/static/locales/en/profile.json';
import redeem from '../public/static/locales/en/redeem.json';
import registerTrees from '../public/static/locales/en/registerTrees.json';
import tenants from '../public/static/locales/en/tenants.json';
import treemapper from '../public/static/locales/en/treemapper.json';
import treemapperAnalytics from '../public/static/locales/en/treemapperAnalytics.json';

i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
backend: {
loadPath: '/static/locales/{{lng}}/{{ns}}.json',
},
});
import bulkCodesDE from '../public/static/locales/de/bulkCodes.json';
import commonDE from '../public/static/locales/de/common.json';
import countryDE from '../public/static/locales/de/country.json';
import donateDE from '../public/static/locales/de/donate.json';
import donationLinkDE from '../public/static/locales/de/donationLink.json';
import editProfileDE from '../public/static/locales/de/editProfile.json';
import giftfundsDE from '../public/static/locales/de/giftfunds.json';
import leaderboardDE from '../public/static/locales/de/leaderboard.json';
import managePayoutsDE from '../public/static/locales/de/managePayouts.json';
import manageProjectsDE from '../public/static/locales/de/manageProjects.json';
import mapsDE from '../public/static/locales/de/maps.json';
import meDE from '../public/static/locales/de/me.json';
import planetDE from '../public/static/locales/de/planet.json';
import planetcashDE from '../public/static/locales/de/planetcash.json';
import profileDE from '../public/static/locales/de/profile.json';
import redeemDE from '../public/static/locales/de/redeem.json';
import registerTreesDE from '../public/static/locales/de/registerTrees.json';
import tenantsDE from '../public/static/locales/de/tenants.json';
import treemapperDE from '../public/static/locales/de/treemapper.json';
import treemapperAnalyticsDE from '../public/static/locales/de/treemapperAnalytics.json';

export default i18n;
import deepmerge from 'deepmerge';

const messages_en = {
...bulkCodes,
...common,
...country,
...donate,
...donationLink,
...editProfile,
...giftfunds,
...leaderboard,
...managePayouts,
...manageProjects,
...maps,
...me,
...planet,
...planetcash,
...profile,
...redeem,
...registerTrees,
...tenants,
...treemapper,
...treemapperAnalytics,
};

const messages_de = {
...bulkCodesDE,
...commonDE,
...countryDE,
...donateDE,
...donationLinkDE,
...editProfileDE,
...giftfundsDE,
...leaderboardDE,
...managePayoutsDE,
...manageProjectsDE,
...mapsDE,
...meDE,
...planetDE,
...planetcashDE,
...profileDE,
...redeemDE,
...registerTreesDE,
...tenantsDE,
...treemapperDE,
...treemapperAnalyticsDE,
};

const getMessages = (locale) => {
if (locale === 'de') {
return deepmerge(messages_en, messages_de);
}
return messages_en;
};

export default getMessages;
17 changes: 5 additions & 12 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import './storybook.scss';
import { ThemeProvider as MUIThemeProvider } from '@mui/material';
import materialTheme from '../src/theme/themeStyles';
import { ThemeProvider } from '@storybook/theming';
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';
import { useEffect } from 'react';

// import { ThemeProvider } from 'emotion-theming';
import getMessages from './i18n';
import { NextIntlClientProvider } from 'next-intl';

/*
* Global decorator to apply the styles to all stories
Expand All @@ -16,20 +13,16 @@ import { useEffect } from 'react';
*/
export const decorators = [
(Story, context) => {
const { locale } = context.globals;

useEffect(() => {
i18n.changeLanguage(locale);
}, [locale]);
const locale = context.globals.locale;

return (
<I18nextProvider i18n={i18n}>
<NextIntlClientProvider messages={getMessages(locale)} locale={locale}>
<MUIThemeProvider theme={materialTheme}>
<ThemeProvider theme={materialTheme}>
<Story />
</ThemeProvider>
</MUIThemeProvider>
</I18nextProvider>
</NextIntlClientProvider>
);
},
];
Expand Down
55 changes: 55 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Use type safe message keys with `next-intl`
type MessagesBulkCodes =
typeof import('./public/static/locales/en/bulkCodes.json');
type MessagesCommon = typeof import('./public/static/locales/en/common.json');
type MessagesCountry = typeof import('./public/static/locales/en/country.json');
type MessagesDonate = typeof import('./public/static/locales/en/donate.json');
type MessagesDonationLink =
typeof import('./public/static/locales/en/donationLink.json');
type MessagesEditProfile =
typeof import('./public/static/locales/en/editProfile.json');
type MessagesGiftfunds =
typeof import('./public/static/locales/en/giftfunds.json');
type MessagesLeaderboard =
typeof import('./public/static/locales/en/leaderboard.json');
type MessagesManagePayouts =
typeof import('./public/static/locales/en/managePayouts.json');
type MessagesManageProjects =
typeof import('./public/static/locales/en/manageProjects.json');
type MessagesMaps = typeof import('./public/static/locales/en/maps.json');
type MessagesMe = typeof import('./public/static/locales/en/me.json');
type MessagesPlanet = typeof import('./public/static/locales/en/planet.json');
type MessagesPlanetcash =
typeof import('./public/static/locales/en/planetcash.json');
type MessagesProfile = typeof import('./public/static/locales/en/profile.json');
type MessagesRedeem = typeof import('./public/static/locales/en/redeem.json');
type MessagesRegisterTrees =
typeof import('./public/static/locales/en/registerTrees.json');
type MessagesTenants = typeof import('./public/static/locales/en/tenants.json');
type MessagesTreemapper =
typeof import('./public/static/locales/en/treemapper.json');
type MessagesTreemapperAnalytics =
typeof import('./public/static/locales/en/treemapperAnalytics.json');

type Messages = MessagesBulkCodes &
MessagesCommon &
MessagesCountry &
MessagesDonate &
MessagesDonationLink &
MessagesEditProfile &
MessagesGiftfunds &
MessagesLeaderboard &
MessagesManagePayouts &
MessagesManageProjects &
MessagesMaps &
MessagesMe &
MessagesPlanet &
MessagesPlanetcash &
MessagesProfile &
MessagesRedeem &
MessagesRegisterTrees &
MessagesTenants &
MessagesTreemapper &
MessagesTreemapperAnalytics;

declare interface IntlMessages extends Messages {}
7 changes: 7 additions & 0 deletions i18n-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// i18n config for next-intl
export const i18nConfig = {
defaultLocale: 'en',
locales: ['en', 'de', 'cs', 'es', 'fr', 'it', 'pt-BR'],
};

export type Locale = (typeof i18nConfig)['locales'][number];
71 changes: 71 additions & 0 deletions i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { getRequestConfig } from 'next-intl/server';
import deepmerge from 'deepmerge';

// IMP - Import any new translation file here in `userMessages` add `defaultMessages`, to enable translation auto complete.
export default getRequestConfig(async ({ locale }) => {
const userMessages = {
...(await import(`./public/static/locales/${locale}/bulkCodes.json`))
.default,
...(await import(`./public/static/locales/${locale}/common.json`)).default,
...(await import(`./public/static/locales/${locale}/country.json`)).default,
...(await import(`./public/static/locales/${locale}/donate.json`)).default,
...(await import(`./public/static/locales/${locale}/donationLink.json`))
.default,
...(await import(`./public/static/locales/${locale}/editProfile.json`))
.default,
...(await import(`./public/static/locales/${locale}/giftfunds.json`))
.default,
...(await import(`./public/static/locales/${locale}/leaderboard.json`))
.default,
...(await import(`./public/static/locales/${locale}/managePayouts.json`))
.default,
...(await import(`./public/static/locales/${locale}/manageProjects.json`))
.default,
...(await import(`./public/static/locales/${locale}/maps.json`)).default,
...(await import(`./public/static/locales/${locale}/me.json`)).default,
...(await import(`./public/static/locales/${locale}/planet.json`)).default,
...(await import(`./public/static/locales/${locale}/planetcash.json`))
.default,
...(await import(`./public/static/locales/${locale}/profile.json`)).default,
...(await import(`./public/static/locales/${locale}/redeem.json`)).default,
...(await import(`./public/static/locales/${locale}/registerTrees.json`))
.default,
...(await import(`./public/static/locales/${locale}/tenants.json`)).default,
...(await import(`./public/static/locales/${locale}/treemapper.json`))
.default,
...(
await import(`./public/static/locales/${locale}/treemapperAnalytics.json`)
).default,
};

const defaultMessages = {
...(await import(`./public/static/locales/en/bulkCodes.json`)).default,
...(await import(`./public/static/locales/en/common.json`)).default,
...(await import(`./public/static/locales/en/country.json`)).default,
...(await import(`./public/static/locales/en/donate.json`)).default,
...(await import(`./public/static/locales/en/donationLink.json`)).default,
...(await import(`./public/static/locales/en/editProfile.json`)).default,
...(await import(`./public/static/locales/en/giftfunds.json`)).default,
...(await import(`./public/static/locales/en/leaderboard.json`)).default,
...(await import(`./public/static/locales/en/managePayouts.json`)).default,
...(await import(`./public/static/locales/en/manageProjects.json`)).default,
...(await import(`./public/static/locales/en/maps.json`)).default,
...(await import(`./public/static/locales/en/me.json`)).default,
...(await import(`./public/static/locales/en/planet.json`)).default,
...(await import(`./public/static/locales/en/planetcash.json`)).default,
...(await import(`./public/static/locales/en/profile.json`)).default,
...(await import(`./public/static/locales/en/redeem.json`)).default,
...(await import(`./public/static/locales/en/registerTrees.json`)).default,
...(await import(`./public/static/locales/en/tenants.json`)).default,
...(await import(`./public/static/locales/en/treemapper.json`)).default,
...(await import(`./public/static/locales/en/treemapperAnalytics.json`))
.default,
};

const messages: IntlMessages = deepmerge(defaultMessages, userMessages);

Check notice on line 65 in i18n.ts

View check run for this annotation

codefactor.io / CodeFactor

i18n.ts#L65

'IntlMessages' is not defined. (no-undef)

// Single file, no fallback
// messages: (await import(`./messages/${locale}.json`)).default,

return { messages };
});
Loading
Loading