Skip to content

Commit

Permalink
docs: Link to ButterCMS article [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed May 10, 2023
1 parent 4d28ece commit b2e863e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/pages/blog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Failed attempts at writing docs that somehow turned into blog posts.

## Community links

Resources on `next-intl` created by and for the community.

<div className="flex flex-col gap-4 py-8">
<CommunityLink
href="https://www.smashingmagazine.com/2023/03/internationalization-nextjs-13-react-server-components/"
Expand All @@ -24,6 +26,14 @@ Failed attempts at writing docs that somehow turned into blog posts.
target="_blank"
type="article"
/>
<CommunityLink
href="https://buttercms.com/blog/nextjs-localization/"
title="Next.js Localization: How to Build a Multilingual Website with next-intl"
date="Nov 4, 2021"
author="By Nirmalya Ghosh for ButterCMS"
target="_blank"
type="article"
/>
<CommunityLink
href="https://www.thisdot.co/blog/next-js-adding-localization-with-next-intl"
title="Next.js: Adding Localization with next-intl"
Expand Down
10 changes: 6 additions & 4 deletions docs/pages/blog/translations-outside-of-react-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: How (not) to use translations outside of React components

Have you ever wondered why `next-intl` doesn’t provide an API to consume translations outside of React components?

The traditional way is to use the `useTranslations` hook.
The traditional way to internationalize your app with `next-intl` is to use the `useTranslations` hook:

```tsx
import {useTranslations} from 'next-intl';
Expand Down Expand Up @@ -34,8 +34,10 @@ import {addMinutes} from 'date-fns';
function sendFeedback() {
// ❌ Bad implementation: Returns formatted messages
API.sendFeedback().catch((error) => {
// In case of a gateway timeout, notify the
// user that we'll try again in 5 minutes
if (error.status === 504) {
// Notify the user that we'll try again in 5 minutes
// (let's assume `t` is defined here for the sake of the example)
return t('timeout', {nextAttempt: addMinutes(new Date(), 5)});
}
});
Expand Down Expand Up @@ -107,7 +109,7 @@ Additionally, this approach is more robust to possibly unexpected states, like t

## The exception that proves the rule

If you’re working with Next.js, you might like to translate i18n messages in [API routes](https://nextjs.org/docs/api-routes/introduction), [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers) or the [Metadata API](https://beta.nextjs.org/docs/api-reference/metadata).
If you’re working with Next.js, you might want to translate i18n messages in [API routes](https://nextjs.org/docs/api-routes/introduction), [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers) or the [Metadata API](https://beta.nextjs.org/docs/api-reference/metadata).

`next-intl` provides a [core library](/docs/usage/core-library) that is agnostic from React and can be used for these cases.

Expand All @@ -133,6 +135,6 @@ There's currently a proposal to further simplify this use case, by offering a se

If you’ve been working with React for a longer time, you might have experienced the change [from `component{DidMount,DidUpdate,WillUnmount}` to `useEffect`](https://legacy.reactjs.org/docs/hooks-effect.html#explanation-why-effects-run-on-each-update). The reason why `useEffect` is superior is because it nudges the developer into a direction where the app is always in sync and by doing this, a whole array of potential issues just magically disappear.

By limiting ourselves to only format messages during render, we're in a similar situation: The rendered output of translated messages is always in sync with app state.
By limiting ourselves to only format messages during render, we're in a similar situation: The rendered output of translated messages is always in sync with app state and we can rely on the app being consistent.

Related: ["How can I reuse messages?" in the structuring messages docs](/docs/usage/messages#structuring-messages)
2 changes: 2 additions & 0 deletions docs/pages/docs/next-13/server-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ import {
} from 'next-intl/server';
```

Note however that the `useTranslations` hook is the primary API to translate messages in your app. Related: [How (not) to use translations outside of React components](/blog/translations-outside-of-react-components)

## CDN caching

Since `next-intl` is currently SSR-only, it's a good idea to use [CDN caching](https://vercel.com/docs/concepts/edge-network/caching#stale-while-revalidate) via [`headers`](https://nextjs.org/docs/api-reference/next.config.js/headers) in `next.config.js` to get the same level of performance from dynamic rendering as you'd get from static rendering ([learn more](https://youtu.be/bfLFHp7Sbkg?t=490)). Also note that [the Next.js Cache](https://nextjs.org/blog/next-13-2#nextjs-cache) improves the performance for dynamically rendered pages.
Expand Down

3 comments on commit b2e863e

@vercel
Copy link

@vercel vercel bot commented on b2e863e May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-intl-docs – ./docs

next-intl-docs.vercel.app
next-intl-docs-amannn.vercel.app
next-intl-docs-git-main-amannn.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b2e863e May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-intl-example-next-13 – ./examples/example-next-13

next-intl-example-next-13-git-main-amannn.vercel.app
next-intl-example-next-13-amannn.vercel.app
next-intl-example-next-13.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b2e863e May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

example-next-13-next-auth – ./examples/example-next-13-next-auth

example-next-13-next-auth-git-main-amannn.vercel.app
example-next-13-next-auth.vercel.app
example-next-13-next-auth-amannn.vercel.app

Please sign in to comment.