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

Conversation

mohitb35
Copy link
Collaborator

@mohitb35 mohitb35 commented Jan 30, 2024

Changes

  1. Updates translation handling across the app to use next-intl instead of next-i18next. Key changes are
    a. Replaces useTranslation hook with useTranslations, and only 1 namespace can be referred to at a time.
    b. Replaces Trans component with t.rich
    c. Replaces language with locale from the useLocale hook provided by next-intl.
    d. Removes usage of ready, as it was not needed
  2. Updates file structure for pages, and import paths to include [locale] in order to support internationalization
  3. Updates middleware to detect locale, set in local storage as a cookie, and handle urls without a locale. This logic is customized and does not use createMiddleware from next-intl, as the necessary folder structure (due to multitenancy) was not supported out of the box.
  4. Updates translation files to use syntax of next-intl - key changes are
    a. Replaces {{}} with {} syntax to interpolate variables
    b. Changes complex translation strings (formerly used by the Trans component) as per next-intl syntax, which allows us to format rich text with custom tags and map them to React components
    c. Updates pluralization syntax
    d. Adds external namespace to wrap strings within the file
    e. Removes arrays from existing json as they are not supported by next-intl.
  5. Passed only necessary translation Namespaces in to page via getStaticProps.
  6. Sets up autocomplete based on selected namespace.
  7. Populates translation files for all languages
  8. Updates route comparison logic in several places to make sure we are comparing the appropriate values (due to file structure changes).
  9. Minor refactors to routing for readability - e.g. not destructuring router to make code clearer, using next/link instead of click handler for regular routing

Reason for change

  1. next-i18next does not support the app router, which prevents us from a gradual migration from pages to app router. While there is a workaround, it would need custom helpers to be set up to handle translation strings. next-intl can support both routers.

Summary by CodeRabbit

  • New Features

    • Enhanced internationalization support with improved logic for currency and language settings based on user preferences.
    • New API endpoints for fetching distinct species data, detailed plant location information, and site data in GeoJSON format.
    • Enhanced caching mechanisms using Redis for various data endpoints.
  • Improvements

    • Updated user authentication and redirection logic.
    • Improved error handling and logging for data fetching processes.
  • Bug Fixes

    • Fixed issues related to static path generation and message fetching based on locale.
  • Refactor

    • Reorganized import paths and modules for better project structure.
    • Transitioned from using useTranslation to useLocale for better locale management.
  • Documentation

    • Updated JSON structures in locale files for better data organization and accessibility.

Copy link

vercel bot commented Jan 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
planet-webapp ✅ Ready (Inspect) Visit Preview Apr 17, 2024 10:15am
planet-webapp-multi-tenancy-setup ✅ Ready (Inspect) Visit Preview Apr 17, 2024 10:15am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
planet-webapp-temp ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2024 10:15am

@mohitb35 mohitb35 changed the base branch from develop to feature/my_forest January 30, 2024 11:44
- detects locale from browser settings and adds locale to url (if missing)
- sets NEXT_LOCALE cookie for detected language
- sets up static paths for index route
- also uses a standard arrow function for getStaticProps throughout
@norbertschuler
Copy link
Collaborator

norbertschuler commented Apr 16, 2024

I think there is an issue trying to switch the language. When I switch the language with

Bildschirmfoto 2024-04-16 um 10 04 16

and continue using the application I get displayed pages with the former language. Reloading the page with the new language in the URL helps to really switch to the new language.
(Testing with latest Firefox on latest MacOS.)

@mohitb35
Copy link
Collaborator Author

mohitb35 commented Apr 16, 2024

I think there is an issue trying to switch the language. When I switch the language with

Bildschirmfoto 2024-04-16 um 10 04 16 and continue using the application I get displayed pages with the former language. Reloading the page with the new language in the URL helps to really switch to the new language. (Testing with latest Firefox on latest MacOS.)

From what I can tell, there seems to be some caching mechanism. Let's say I visited en/profile/history and en/profile/register-trees, followed by en/profile.

After changing the language to German (de) on en/profile, the links visited before changing the language seem to have a cached locale on the vercel deployment.

Perhaps b7714f3 fixes this?

Copy link
Contributor

@mariahosfeld mariahosfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After switching to another language, the back button within the project or the browser (to go back to main map) just triggers a change of language, back to the original one, instead of the expected functionality, only second click takes the user back. Language stays now again the original one.
To replicate:
Go to WebApp -> Select any project -> switch to another language -> use any back button

@mohitb35
Copy link
Collaborator Author

After switching to another language, the back button within the project or the browser (to go back to main map) just triggers a change of language, back to the original one, instead of the expected functionality, only second click takes the user back. Language stays now again the original one. To replicate: Go to WebApp -> Select any project -> switch to another language -> use any back button

aac6bb4 will take care of the back button within the project snippet. The browser back action is part of a larger issue seen even on www1.plant-for-the-planet.org, and not related to translations. We'll need to think about how we want to resolve that without breaking the loading of site data / map on the project details page.

Copy link
Contributor

@mariahosfeld mariahosfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While now the issue of not directly going back to the main map has been resolved for the included button (for the browser it still remains), the language still changes back.
How to replicate:
Select any project -> Switch language -> hit the back button provided by the App (not the browser)

Copy link
Contributor

@mariahosfeld mariahosfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks good for me now.

Copy link
Contributor

@sunilsabatp sunilsabatp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mariahosfeld mariahosfeld merged commit 7287107 into develop Apr 19, 2024
8 checks passed
@mariahosfeld mariahosfeld deleted the feature/migrate-nexti18next-to-nextintl branch April 19, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants