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: docs/basic-features/typescript.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ Next.js will automatically configure this file with default values. Providing yo
23
23
24
24
> Next.js uses Babel to handle TypeScript, which has some [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats), and some [compiler options are handled differently](https://babeljs.io/docs/en/babel-plugin-transform-typescript#typescript-compiler-options).
25
25
26
-
Then, run `next` (normally `npm run dev`) and Next.js will guide you through the installation of the required packages to finish the setup:
26
+
Then, run `next` (normally `npm run dev` or `yarn dev`) and Next.js will guide you through the installation of the required packages to finish the setup:
This example app shows how to integrate [React Intl][] with Next.
3
+
This example app shows how to integrate [React Intl][] with Next.js.
4
4
5
5
## How to use
6
6
7
-
### Using `create-next-app`
8
-
9
7
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-react-intl
23
-
cd with-react-intl
24
-
```
25
-
26
-
Install it and run:
27
-
28
-
```bash
29
-
npm install
30
-
npm run dev
31
-
# or
32
-
yarn
33
-
yarn dev
34
-
```
35
-
36
15
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
37
16
38
-
###Features of this example app
17
+
## Features of this example app
39
18
40
19
- Server-side language negotiation
41
20
- React Intl locale data loading via `pages/_document.js` customization
42
21
- React Intl integration with [custom App](https://github.com/vercel/next.js#custom-app) component
43
22
-`<IntlProvider>` creation with `locale`, `messages` props
44
-
- Default message extraction via `babel-plugin-react-intl` integration
23
+
- Default message extraction via `@formatjs/cli` integration
24
+
- Pre-compile messages into AST with `babel-plugin-react-intl` for performance
45
25
- Translation management via build script and customized Next server
46
26
47
27
### Translation Management
48
28
49
-
This app stores translations and default strings in the `lang/` dir. This dir has `.messages/` subdir which is where React Intl's Babel plugin outputs the default messages it extracts from the source code. The default messages (`en.json` in this example app) is also generated by the build script. This file can then be sent to a translation service to perform localization for the other locales the app should support.
29
+
This app stores translations and default strings in the `lang/` dir. The default messages (`en.json` in this example app) is also generated by the build script. This file can then be sent to a translation service to perform localization for the other locales the app should support.
50
30
51
31
The translated messages files that exist at `lang/*.json` are only used during production, and are automatically provided to the `<IntlProvider>`. During development the `defaultMessage`s defined in the source code are used. To prepare the example app for localization and production run the build script and start the server in production mode:
52
32
@@ -57,21 +37,4 @@ $ npm start
57
37
58
38
You can then switch your browser's language preferences to French and refresh the page to see the UI update accordingly.
59
39
60
-
### FormattedHTMLMessage support (react-intl pre-v4)
61
-
62
-
Out of the box, this example does not support the use of the `FormattedHTMLMessage` component on the server due to `DOMParser` not being present in a Node environment.
63
-
This functionality is deprecated and has been removed as of react-intl 4.0
64
-
If you still want to enable this feature, you should install a `DOMParser` implementation (e.g. `xmldom` or `jsdom`) and enable the polyfill in `server.js`:
65
-
66
-
```js
67
-
// Polyfill Node with `DOMParser` required by formatjs.
According to [react-intl docs](https://github.com/formatjs/react-intl/blob/53f2c826c7b1e50ad37215ce46b5e1c6f5d142cc/docs/Getting-Started.md#esm-build), react-intl and its underlying libraries must be transpiled to support older browsers (eg IE11). This is done by [next-transpile-modules](https://www.npmjs.com/package/next-transpile-modules) in next.config.js.
0 commit comments