Skip to content

Commit ba7baed

Browse files
committed
docs: Update README
1 parent 5f2845b commit ba7baed

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

README.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,8 @@ It's recommended to export this `NextI18Next` instance from a single file in you
7474
After creating and exporting your `NextI18Next` instance, you need to take the following steps to get things working:
7575

7676
1. Create an `_app.js` file inside your `pages` directory, and wrap it with the `NextI18Next.appWithTranslation` higher order component (HOC). You can see this approach in the [examples/simple/pages/_app.js](./examples/simple/pages/_app.js).
77-
Your app component must either extend `App` if it's a class component or define a `getInitialProps` if it's a function component [(explanation here)](https://github.com/isaachinman/next-i18next/issues/615#issuecomment-575578375).
78-
2. Create a `server.js` file inside your root directory, initialise an [express](https://www.npmjs.com/package/express) server, and use the `nextI18NextMiddleware` middleware with your `nextI18Next` instance passed in. You can see this approach in the [examples/simple/server.js](./examples/simple/server.js).
79-
3. Update the scripts in `package.json` to:
80-
```
81-
{
82-
"scripts": {
83-
"dev": "node server.js",
84-
"build": "next build",
85-
"start": "NODE_ENV=production node server.js"
86-
}
87-
}
88-
```
89-
For more info, see [the NextJs section on custom servers](https://github.com/zeit/next.js#custom-server-and-routing).
77+
Your app component must either extend `App` if it's a class component or define a `getInitialProps` if it's a functional component [(explanation here)](https://github.com/isaachinman/next-i18next/issues/615#issuecomment-575578375).
78+
2. Create a `next.config.js` file inside your root directory if you want to use locale subpaths. You can see this approach in the [examples/simple/next.config.js](./examples/simple/next.config.js).
9079

9180
Note: You can pass `shallowRender: true` into config options to avoid triggering getInitialProps when `changeLanguage` method is invoked.
9281

@@ -138,6 +127,8 @@ new NextI18Next({
138127
})
139128
```
140129

130+
The `localeSubpaths` object must also be passed into `next.config.js`, via the `nextI18NextRewrites` util, which you can import from `next-i18next/rewrites`.
131+
141132
The `localeSubpaths` option is a key/value mapping, where keys are the locale itself (case sensitive) and values are the subpath without slashes.
142133

143134
Now, all your page routes will be duplicated across all your locale subpaths. Here's an example:
@@ -158,7 +149,7 @@ myapp.com/german
158149
myapp.com/eng
159150
```
160151

161-
When using the localeSubpaths option, our middleware may redirect without calling any subsequent middleware. Therefore, if there are any critical middleware that must run before this redirect, ensure that you place it before the `nextI18NextMiddleware` middleware.
152+
When using the localeSubpaths option, our middleware will redirect as needed in the wrapped `getInitialProps` one level above your `_app`, so none of your code will be called.
162153

163154
The main "gotcha" with locale subpaths is routing. We want to be able to route to "naked" routes, and not have to worry about the locale subpath part of the route:
164155

@@ -183,8 +174,7 @@ const SomeLink = () => (
183174
)
184175
```
185176

186-
We can also navigate imperatively with locale subpaths by importing `Router` from your `NextI18Next` instance.
187-
The exported Router shares the same API as the native Next Router. The push, replace, and prefetch functions will automatically prepend locale subpaths.
177+
We can also navigate imperatively with locale subpaths by importing `Router` from your `NextI18Next` instance. The exported Router shares the same API as the native Next Router. The push, replace, and prefetch functions will automatically prepend locale subpaths.
188178

189179
```jsx
190180
import React from 'react'
@@ -259,7 +249,6 @@ _This table contains options which are specific to next-i18next. All other [i18n
259249
## Notes
260250

261251
- [`next export` will result in a _client-side only_ React application.](https://github.com/isaachinman/next-i18next/issues/10)
262-
- [Serverless (e.g. Now 2.0) is not currently supported](https://github.com/isaachinman/next-i18next/issues/274).
263252
- [To add a `lang` attribute to your top-level html DOM node, you must create a `_document.js` file.](https://github.com/isaachinman/next-i18next/issues/20#issuecomment-443461652)
264253
- [Localising `next/head` requires special consideration due to NextJs internals](https://github.com/isaachinman/next-i18next/issues/251#issuecomment-479421852).
265254

0 commit comments

Comments
 (0)