You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-17Lines changed: 6 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -74,19 +74,8 @@ It's recommended to export this `NextI18Next` instance from a single file in you
74
74
After creating and exporting your `NextI18Next` instance, you need to take the following steps to get things working:
75
75
76
76
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).
90
79
91
80
Note: You can pass `shallowRender: true` into config options to avoid triggering getInitialProps when `changeLanguage` method is invoked.
92
81
@@ -138,6 +127,8 @@ new NextI18Next({
138
127
})
139
128
```
140
129
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
+
141
132
The `localeSubpaths` option is a key/value mapping, where keys are the locale itself (case sensitive) and values are the subpath without slashes.
142
133
143
134
Now, all your page routes will be duplicated across all your locale subpaths. Here's an example:
@@ -158,7 +149,7 @@ myapp.com/german
158
149
myapp.com/eng
159
150
```
160
151
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.
162
153
163
154
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:
164
155
@@ -183,8 +174,7 @@ const SomeLink = () => (
183
174
)
184
175
```
185
176
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.
188
178
189
179
```jsx
190
180
importReactfrom'react'
@@ -259,7 +249,6 @@ _This table contains options which are specific to next-i18next. All other [i18n
259
249
## Notes
260
250
261
251
-[`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).
263
252
-[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)
264
253
-[Localising `next/head` requires special consideration due to NextJs internals](https://github.com/isaachinman/next-i18next/issues/251#issuecomment-479421852).
0 commit comments