Files
payloadcms/examples/localization
Jacob Fletcher 355bd12c61 chore: infer React context providers and prefer use (#11669)
As of [React 19](https://react.dev/blog/2024/12/05/react-19), context
providers no longer require the `<MyContext.Provider>` syntax and can be
rendered as `<MyContext>` directly. This will be deprecated in future
versions of React, which is now being caught by the
[`@eslint-react/no-context-provider`](https://eslint-react.xyz/docs/rules/no-context-provider)
ESLint rule.

Similarly, the [`use`](https://react.dev/reference/react/use) API is now
preferred over `useContext` because it is more flexible, for example
they can be called within loops and conditional statements. See the
[`@eslint-react/no-use-context`](https://eslint-react.xyz/docs/rules/no-use-context)
ESLint rule for more details.
2025-03-12 15:48:20 -04:00
..

Payload Localization Example (i18n)

This example is built based on an old version of the website template.

The objective is to show how to implement localization in a website. There is no guarantee that it will be kept up to date with the website template or the latest Payload enhancements.

To facilitate the localization process, this example uses the next-intl library.

## Setup

  1. Run the following command to create a project from the example:
  • npx create-payload-app --example localization
  1. cp .env.example .env (copy the .env.example file to .env)
  2. pnpm install
  3. pnpm run dev
  4. Seed your database in the admin panel (see below)

Seed

To seed the database with a few pages, posts, and projects you can click the 'seed database' link from the admin panel.

The seed script will also create a demo user for demonstration purposes only:

  • Demo Author
    • Email: demo-author@payloadcms.com
    • Password: password

NOTICE: seeding the database is destructive because it drops your current database to populate a fresh one from the seed template. Only run this command if you are starting a new project or can afford to lose your current data.

Important!

The seed script only creates translations in English and Spanish, so you will not see the website translated to other languages even if you see them in the dropdown menu.

You can translate documents to other languages from the admin panel.