Skip to content

Commit

Permalink
update more docs regarding getRequestConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Oct 10, 2024
1 parent 0e984bd commit 5502984
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
36 changes: 18 additions & 18 deletions docs/pages/docs/usage/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,10 @@ That being said, `next-intl` is agnostic to how you store messages and allows yo
```tsx filename="i18n/request.ts"
import {getRequestConfig} from 'next-intl/server';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
messages: (await import(`../../messages/${locale}.json`)).default
// ...
};
});
```
Expand Down Expand Up @@ -329,14 +328,14 @@ Specifying a time zone affects the rendering of dates and times. By default, the
```tsx filename="i18n/request.ts"
import {getRequestConfig} from 'next-intl/server';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
// The time zone can either be statically defined, read from the
// user profile if you store such a setting, or based on dynamic
// request information like the locale or a cookie.
timeZone: 'Europe/Vienna'

// ...
};
});
```
Expand Down Expand Up @@ -387,15 +386,15 @@ If you prefer to override the default, you can provide an explicit value for `no
```tsx filename="i18n/request.ts"
import {getRequestConfig} from 'next-intl/server';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
// This is the default, a single date instance will be
// used by all Server Components to ensure consistency.
// Tip: This value can be mocked to a constant value
// for consistent results in end-to-end-tests.
now: new Date()

// ...
};
});
```
Expand Down Expand Up @@ -439,9 +438,7 @@ To achieve consistent date, time, number and list formatting, you can define a s
```tsx filename="i18n/request.ts"
import {getRequestConfig} from 'next-intl/server';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
formats: {
dateTime: {
Expand All @@ -463,6 +460,8 @@ export default getRequestConfig(async ({locale}) => {
}
}
}

// ...
};
});
```
Expand Down Expand Up @@ -552,14 +551,14 @@ To achieve consistent usage of translation values and reduce redundancy, you can
```tsx filename="i18n/request.tsx"
import {getRequestConfig} from 'next-intl/server';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
defaultTranslationValues: {
important: (chunks) => <b>{chunks}</b>,
value: 123
}

// ...
};
});
```
Expand Down Expand Up @@ -598,9 +597,7 @@ This behavior can be customized with the `onError` and `getMessageFallback` conf
import {getRequestConfig} from 'next-intl/server';
import {IntlErrorCode} from 'next-intl';

export default getRequestConfig(async ({locale}) => {
// ...

export default getRequestConfig(async () => {
return {
onError(error) {
if (error.code === IntlErrorCode.MISSING_MESSAGE) {
Expand All @@ -611,6 +608,7 @@ export default getRequestConfig(async ({locale}) => {
reportToErrorTracking(error);
}
},

getMessageFallback({namespace, key, error}) {
const path = [namespace, key].filter((part) => part != null).join('.');

Expand All @@ -620,6 +618,8 @@ export default getRequestConfig(async ({locale}) => {
return 'Dear developer, please fix this message: ' + path;
}
}

// ...
};
});
```
Expand Down
9 changes: 1 addition & 8 deletions docs/pages/docs/workflows/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function Component() {
To enable this validation, export the formats that you're using in your request configuration:

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

export const formats = {
Expand All @@ -95,13 +94,7 @@ export const formats = {
}
} satisfies Formats;

export default getRequestConfig(async ({locale}) => {
// ...

return {
formats
}
});
// ...
```

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:
Expand Down

0 comments on commit 5502984

Please sign in to comment.