Skip to content

Commit 5502984

Browse files
committed
update more docs regarding getRequestConfig
1 parent 0e984bd commit 5502984

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

docs/pages/docs/usage/configuration.mdx

+18-18
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ That being said, `next-intl` is agnostic to how you store messages and allows yo
225225
```tsx filename="i18n/request.ts"
226226
import {getRequestConfig} from 'next-intl/server';
227227

228-
export default getRequestConfig(async ({locale}) => {
229-
// ...
230-
228+
export default getRequestConfig(async () => {
231229
return {
232230
messages: (await import(`../../messages/${locale}.json`)).default
231+
// ...
233232
};
234233
});
235234
```
@@ -329,14 +328,14 @@ Specifying a time zone affects the rendering of dates and times. By default, the
329328
```tsx filename="i18n/request.ts"
330329
import {getRequestConfig} from 'next-intl/server';
331330

332-
export default getRequestConfig(async ({locale}) => {
333-
// ...
334-
331+
export default getRequestConfig(async () => {
335332
return {
336333
// The time zone can either be statically defined, read from the
337334
// user profile if you store such a setting, or based on dynamic
338335
// request information like the locale or a cookie.
339336
timeZone: 'Europe/Vienna'
337+
338+
// ...
340339
};
341340
});
342341
```
@@ -387,15 +386,15 @@ If you prefer to override the default, you can provide an explicit value for `no
387386
```tsx filename="i18n/request.ts"
388387
import {getRequestConfig} from 'next-intl/server';
389388

390-
export default getRequestConfig(async ({locale}) => {
391-
// ...
392-
389+
export default getRequestConfig(async () => {
393390
return {
394391
// This is the default, a single date instance will be
395392
// used by all Server Components to ensure consistency.
396393
// Tip: This value can be mocked to a constant value
397394
// for consistent results in end-to-end-tests.
398395
now: new Date()
396+
397+
// ...
399398
};
400399
});
401400
```
@@ -439,9 +438,7 @@ To achieve consistent date, time, number and list formatting, you can define a s
439438
```tsx filename="i18n/request.ts"
440439
import {getRequestConfig} from 'next-intl/server';
441440

442-
export default getRequestConfig(async ({locale}) => {
443-
// ...
444-
441+
export default getRequestConfig(async () => {
445442
return {
446443
formats: {
447444
dateTime: {
@@ -463,6 +460,8 @@ export default getRequestConfig(async ({locale}) => {
463460
}
464461
}
465462
}
463+
464+
// ...
466465
};
467466
});
468467
```
@@ -552,14 +551,14 @@ To achieve consistent usage of translation values and reduce redundancy, you can
552551
```tsx filename="i18n/request.tsx"
553552
import {getRequestConfig} from 'next-intl/server';
554553

555-
export default getRequestConfig(async ({locale}) => {
556-
// ...
557-
554+
export default getRequestConfig(async () => {
558555
return {
559556
defaultTranslationValues: {
560557
important: (chunks) => <b>{chunks}</b>,
561558
value: 123
562559
}
560+
561+
// ...
563562
};
564563
});
565564
```
@@ -598,9 +597,7 @@ This behavior can be customized with the `onError` and `getMessageFallback` conf
598597
import {getRequestConfig} from 'next-intl/server';
599598
import {IntlErrorCode} from 'next-intl';
600599

601-
export default getRequestConfig(async ({locale}) => {
602-
// ...
603-
600+
export default getRequestConfig(async () => {
604601
return {
605602
onError(error) {
606603
if (error.code === IntlErrorCode.MISSING_MESSAGE) {
@@ -611,6 +608,7 @@ export default getRequestConfig(async ({locale}) => {
611608
reportToErrorTracking(error);
612609
}
613610
},
611+
614612
getMessageFallback({namespace, key, error}) {
615613
const path = [namespace, key].filter((part) => part != null).join('.');
616614

@@ -620,6 +618,8 @@ export default getRequestConfig(async ({locale}) => {
620618
return 'Dear developer, please fix this message: ' + path;
621619
}
622620
}
621+
622+
// ...
623623
};
624624
});
625625
```

docs/pages/docs/workflows/typescript.mdx

+1-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function Component() {
7171
To enable this validation, export the formats that you're using in your request configuration:
7272

7373
```ts filename="i18n/request.ts"
74-
import {getRequestConfig} from 'next-intl/server';
7574
import {Formats} from 'next-intl';
7675

7776
export const formats = {
@@ -95,13 +94,7 @@ export const formats = {
9594
}
9695
} satisfies Formats;
9796

98-
export default getRequestConfig(async ({locale}) => {
99-
// ...
100-
101-
return {
102-
formats
103-
}
104-
});
97+
// ...
10598
```
10699

107100
Now, a global type definition file in the root of your project can pick up the shape of your formats and use them for declaring the `IntlFormats` interface:

0 commit comments

Comments
 (0)