Skip to content

Commit 064c692

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
# Conflicts: # docs/pages/docs/usage/messages.mdx
2 parents ccf3810 + de285f6 commit 064c692

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

docs/pages/docs/routing/navigation.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,16 @@ const pathname = usePathname();
401401
const router = useRouter();
402402
const params = useParams();
403403

404-
router.replace({pathname, params}, {locale: 'de'});
404+
router.replace(
405+
{
406+
pathname,
407+
// TypeScript will validate that only known `params` are used in combination
408+
// with a given `pathname`. Since the two will always match for the current
409+
// route, we can skip runtime checks.
410+
params: params as any
411+
},
412+
{locale: 'de'}
413+
);
405414
```
406415

407416
</details>

docs/pages/docs/usage/messages.mdx

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,80 @@ You can format rich text with custom tags and map them to React components:
263263

264264
```json filename="en.json"
265265
{
266-
"richText": "This is <important><very>very</very> important</important>"
266+
"message": "Please refer to <guidelines>the guidelines</guidelines>."
267267
}
268268
```
269269

270270
```js
271-
// Returns `<>This is <b><i>very</i> important</b></>`
272-
t.rich('richText', {
273-
important: (chunks) => <b>{chunks}</b>,
274-
very: (chunks) => <i>{chunks}</i>
271+
// Returns `<>Please refer to <a href="/guidelines">the guidelines</a>.</>`
272+
t.rich('message', {
273+
guidelines: (chunks) => <a href="/guidelines">{chunks}</a>
275274
});
276275
```
277276

278-
If you want to use the same tag across your app, you can configure it via the [default translation values](/docs/usage/configuration#default-translation-values).
277+
Tags can be arbitrarily nested (e.g. `This is <important><very>very</very> important</important>`).
279278

280-
Note that the ICU parser doesn't support self-closing tags at this point, therefore you have to use syntax like `<br></br>` if your rich text function doesn't intend to receive any `chunks` (e.g. `br: () => <br />`).
279+
<details>
280+
<summary>How can I reuse a tag across my app?</summary>
281+
282+
If you want to use the same tag across your app, you can configure it via [default translation values](/docs/configuration#default-translation-values).
283+
284+
</details>
285+
286+
<details>
287+
<summary>How can I use "self-closing" tags without any chunks?</summary>
288+
289+
Messages can use tags without any chunks as children, but syntax-wise, a closing tag is required by the ICU parser:
290+
291+
```json filename="en.json"
292+
{
293+
"message": "Hello,<br></br>how are you?"
294+
}
295+
```
296+
297+
```js
298+
t.rich('message', {
299+
br: (chunks) => <br />
300+
});
301+
```
302+
303+
</details>
304+
305+
<details>
306+
<summary>How can I pass attributes to tags?</summary>
307+
308+
Attributes can only be set on the call site, not within messages:
281309

310+
```json filename="en.json"
311+
{
312+
"message": "Go to <profile>my profile</profile>"
313+
}
314+
```
315+
316+
```js
317+
t.rich('message', {
318+
profile: (chunks) => <Link href="/profile">{chunks}</Link>
319+
});
320+
```
321+
322+
For the use case of localizing pathnames, consider using [`createLocalizedPathnamesNavigation`](/docs/routing/navigation#localized-pathnames).
323+
324+
In case you have attribute values that are required to be configured as part of your messages, you can retrieve them from a separate message and pass them to another one as an attribute:
325+
326+
```json filename="en.json"
327+
{
328+
"message": "See this <partner>partner website</partner>.",
329+
"partnerHref": "https://partner.example.com"
330+
}
331+
```
332+
333+
```js
334+
t.rich('message', {
335+
partner: (chunks) => <a href={t('partnerHref')}>{chunks}</a>
336+
});
337+
```
338+
339+
</details>
282340

283341
## HTML markup
284342

0 commit comments

Comments
 (0)