Skip to content

Commit 6b31c64

Browse files
committed
refactor: remove redundant importance explanations in i18n documentation for clarity and conciseness
1 parent 7c76e45 commit 6b31c64

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

docs/blog/en/i18n_using_next-i18next.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ yarn add i18next react-i18next i18next-resources-to-backend
125125

126126
Create a configuration file to define your supported locales, default locale, and helper functions for URL localization. This file serves as the single source of truth for your i18n setup and ensures type safety throughout your application.
127127

128-
**Why this step is important**: Centralizing your locale configuration prevents inconsistencies and makes it easier to add or remove locales in the future. The helper functions ensure consistent URL generation for SEO and routing.
128+
Centralizing your locale configuration prevents inconsistencies and makes it easier to add or remove locales in the future. The helper functions ensure consistent URL generation for SEO and routing.
129129

130130
```ts fileName="i18n.config.ts"
131131
// Define supported locales as a const array for type safety
@@ -210,7 +210,7 @@ export type AboutTranslator = TFunction<"about">;
210210

211211
Create a server-side initialization function that loads translations for server components. This function creates a separate i18next instance for server-side rendering, ensuring that translations are loaded before rendering.
212212

213-
**Why this step is important**: Server components need their own i18next instance because they run in a different context than client components. Pre-loading translations on the server prevents flash of untranslated content and improves SEO by ensuring search engines see translated content.
213+
Server components need their own i18next instance because they run in a different context than client components. Pre-loading translations on the server prevents flash of untranslated content and improves SEO by ensuring search engines see translated content.
214214

215215
```ts fileName="src/app/i18n/server.ts"
216216
import { createInstance } from "i18next";
@@ -265,7 +265,7 @@ export async function initI18next(
265265

266266
Create a client component provider that wraps your application with i18next context. This provider receives pre-loaded translations from the server to prevent flash of untranslated content (FOUC) and avoid duplicate fetching.
267267

268-
**Why this step is important**: Client components need their own i18next instance that runs in the browser. By accepting pre-loaded resources from the server, we ensure seamless hydration and prevent content flashing. The provider also manages locale changes and namespace loading dynamically.
268+
Client components need their own i18next instance that runs in the browser. By accepting pre-loaded resources from the server, we ensure seamless hydration and prevent content flashing. The provider also manages locale changes and namespace loading dynamically.
269269

270270
```tsx fileName="src/components/I18nProvider.tsx"
271271
"use client";
@@ -348,7 +348,7 @@ export default function I18nProvider({
348348

349349
Set up dynamic routing for locales by creating a `[locale]` directory in your app folder. This allows Next.js to handle locale-based routing where each locale becomes a URL segment (e.g., `/en/about`, `/fr/about`).
350350

351-
**Why this step is important**: Using dynamic routes enables Next.js to generate static pages for all locales at build time, improving performance and SEO. The layout component sets the HTML `lang` and `dir` attributes based on the locale, which is crucial for accessibility and search engine understanding.
351+
Using dynamic routes enables Next.js to generate static pages for all locales at build time, improving performance and SEO. The layout component sets the HTML `lang` and `dir` attributes based on the locale, which is crucial for accessibility and search engine understanding.
352352

353353
```tsx fileName="src/app/[locale]/layout.tsx"
354354
import type { ReactNode } from "react";
@@ -400,7 +400,7 @@ export default function LocaleLayout({
400400

401401
Create JSON files for each locale and namespace. This structure allows you to organize translations logically and load only what you need for each page.
402402

403-
**Why this step is important**: Organizing translations by namespace (e.g., `common.json`, `about.json`) enables code splitting and reduces bundle size. You only load the translations needed for each page, improving performance.
403+
Organizing translations by namespace (e.g., `common.json`, `about.json`) enables code splitting and reduces bundle size. You only load the translations needed for each page, improving performance.
404404

405405
```json fileName="src/locales/en/common.json"
406406
{
@@ -442,7 +442,7 @@ Create JSON files for each locale and namespace. This structure allows you to or
442442

443443
Create a page component that initializes i18next on the server and passes translations to both server and client components. This ensures that translations are loaded before rendering and prevents content flashing.
444444

445-
**Why this step is important**: Server-side initialization loads translations before the page renders, improving SEO and preventing FOUC. By passing pre-loaded resources to the client provider, we avoid duplicate fetching and ensure smooth hydration.
445+
Server-side initialization loads translations before the page renders, improving SEO and preventing FOUC. By passing pre-loaded resources to the client provider, we avoid duplicate fetching and ensure smooth hydration.
446446

447447
```tsx fileName="src/app/[locale]/about.tsx"
448448
import I18nProvider from "@/components/I18nProvider";
@@ -502,7 +502,7 @@ export default async function AboutPage({
502502

503503
Client components can use the `useTranslation` hook to access translations. This hook provides access to the translation function and the i18n instance, allowing you to translate content and access locale information.
504504

505-
**Why this step is important**: Client components need React hooks to access translations. The `useTranslation` hook integrates seamlessly with i18next and provides reactive updates when the locale changes.
505+
Client components need React hooks to access translations. The `useTranslation` hook integrates seamlessly with i18next and provides reactive updates when the locale changes.
506506

507507
> Ensure the page/provider includes only the namespaces you need (e.g., `about`).
508508
> If you use React < 19, memoize heavy formatters like `Intl.NumberFormat`.
@@ -549,7 +549,7 @@ export default ClientComponent;
549549

550550
Server components cannot use React hooks, so they receive translations via props from their parent components. This approach keeps server components synchronous and allows them to be nested inside client components.
551551

552-
**Why this step is important**: Server components that might be nested under client boundaries need to be synchronous. By passing translated strings and locale information as props, we avoid async operations and ensure proper rendering.
552+
Server components that might be nested under client boundaries need to be synchronous. By passing translated strings and locale information as props, we avoid async operations and ensure proper rendering.
553553

554554
```tsx fileName="src/components/ServerComponent.tsx"
555555
import type { TFunction } from "react-i18next";
@@ -591,7 +591,7 @@ export default ServerComponent;
591591

592592
To change the language of your content in Next.js, the recommended way is to use locale-prefixed URLs and Next.js links. The example below reads the current locale from the route, strips it from the pathname, and renders one link per available locale.
593593

594-
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
594+
```tsx fileName="src/components/LocaleSwitcher.tsx"
595595
"use client";
596596

597597
import { useMemo } from "react";
@@ -656,7 +656,7 @@ export default function LocaleSwitcher() {
656656

657657
Reusing localized URLs across your app keeps navigation consistent and SEO-friendly. Wrap `next/link` in a small helper that prefixes internal routes with the active locale while leaving external URLs untouched.
658658

659-
```tsx fileName="src/components/LocalizedLink.tsx" codeFormat="typescript"
659+
```tsx fileName="src/components/LocalizedLink.tsx"
660660
"use client";
661661

662662
import type { PropsWithChildren } from "react";
@@ -707,7 +707,7 @@ export default function LocalizedLink({
707707

708708
Server Actions often need the current locale for emails, logging, or third-party integrations. Combine the locale cookie set by your proxy with the `Accept-Language` header as a fallback.
709709

710-
```ts fileName="src/app/actions/get-current-locale.ts" codeFormat="typescript"
710+
```ts fileName="src/app/actions/get-current-locale.ts"
711711
"use server";
712712

713713
import { cookies, headers } from "next/headers";
@@ -745,7 +745,7 @@ export async function stuffFromServer(formData: FormData) {
745745

746746
Translating content is important, but the main goal of internationalization is to make your website more visible to the world. I18n is an incredible lever to improve your website visibility through proper SEO.
747747

748-
**Why this step is important**: Properly internationalized metadata helps search engines understand what languages are available on your pages. This includes setting hreflang meta tags, translating titles and descriptions, and ensuring canonical URLs are correctly set for each locale.
748+
Properly internationalized metadata helps search engines understand what languages are available on your pages. This includes setting hreflang meta tags, translating titles and descriptions, and ensuring canonical URLs are correctly set for each locale.
749749

750750
Here's a list of good practices regarding multilingual SEO:
751751

@@ -812,7 +812,7 @@ export default async function AboutPage() {
812812

813813
Generate a sitemap that includes all locale versions of your pages. This helps search engines discover and index all language versions of your content.
814814

815-
**Why this step is important**: A properly internationalized sitemap ensures search engines can find and index all language versions of your pages. This improves visibility in international search results.
815+
A properly internationalized sitemap ensures search engines can find and index all language versions of your pages. This improves visibility in international search results.
816816

817817
```ts fileName="src/app/sitemap.ts"
818818
import type { MetadataRoute } from "next";
@@ -866,7 +866,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
866866

867867
Create a robots.txt file that properly handles all locale versions of your protected routes. This ensures that search engines don't index admin or dashboard pages in any language.
868868

869-
**Why this step is important**: Properly configuring robots.txt for all locales prevents search engines from indexing sensitive pages in any language. This is crucial for security and privacy.
869+
Properly configuring robots.txt for all locales prevents search engines from indexing sensitive pages in any language. This is crucial for security and privacy.
870870

871871
```ts fileName="src/app/robots.ts"
872872
import type { MetadataRoute } from "next";
@@ -897,7 +897,7 @@ export default function robots(): MetadataRoute.Robots {
897897

898898
Create a proxy to automatically detect the user's preferred locale and redirect them to the appropriate locale-prefixed URL. This improves user experience by showing content in their preferred language.
899899

900-
**Why this step is important**: Middleware ensures that users are automatically redirected to their preferred language when they visit your site. It also saves the user's preference in a cookie for future visits.
900+
Middleware ensures that users are automatically redirected to their preferred language when they visit your site. It also saves the user's preference in a cookie for future visits.
901901

902902
```ts fileName="src/proxy.ts"
903903
import { NextResponse, type NextRequest } from "next/server";
@@ -986,7 +986,7 @@ export const config = {
986986

987987
Intlayer is a **free** and **open-source** library designed to assist the localization process in your application. While i18next handles the translation loading and management, Intlayer helps automate the translation workflow.
988988

989-
**Why this step is important**: Managing translations manually can be time-consuming and error-prone. Intlayer automates translation testing, generation, and management, saving you time and ensuring consistency across your application.
989+
Managing translations manually can be time-consuming and error-prone. Intlayer automates translation testing, generation, and management, saving you time and ensuring consistency across your application.
990990

991991
Intlayer will allows your to:
992992

0 commit comments

Comments
 (0)