rsnext/examples/with-lingui
Joe Haddad 4a12fb0a5f
Normalize example gitignores (#13768)
This removes a bunch of unnecessary `.gitignore`s and fixes some CMS examples that don't ignore `node_modules` etc.
2020-06-04 20:39:52 +00:00
..
components Update Examples for Fast Refresh (#13068) 2020-05-18 17:44:18 -04:00
locale Add example using lingui.js (#6210) 2019-02-21 12:53:02 +01:00
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
.babelrc Add example using lingui.js (#6210) 2019-02-21 12:53:02 +01:00
.gitignore Normalize example gitignores (#13768) 2020-06-04 20:39:52 +00:00
next.config.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json Update package.json (#12865) 2020-05-14 21:07:13 +02:00
README.md Suggest npx over npm init (#13637) 2020-06-01 17:36:57 +00:00

With Lingui example

This example shows a way to use lingui.js with next.js.

It adds a webpack loader for the messages to avoid having to manually compile while developing as well as adds the compile step to the next build script for production builds.

The example also uses a Higher order Component which can be added to all pages which will be translated and that checks for a ?lang query string switch the language. Next.js will dynamically load in the messages for the locale when navigating using a Next.js <Link /> component.

Deploy your own

Deploy the example using Vercel:

Deploy with Vercel

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npx create-next-app --example with-lingui with-lingui-app
# or
yarn create next-app --example with-lingui with-lingui-app

Download manually

Download the example:

curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-lingui
cd with-lingui

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Deploy it to the cloud with Vercel (Documentation).

How to add more translated strings

To add new strings use the react component <Trans /> and then run yarn export to export the messages into locale/{language}/messages.po.

How to add another language

To add another language simply run yarn add-locale <locale ...> and it will create a new locale in the locale/messages/ directory.