@intlayer/docs 6.1.5 → 6.1.6-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md +404 -173
  2. package/blog/de/next-i18next_vs_next-intl_vs_intlayer.md +262 -113
  3. package/blog/en/intlayer_with_next-i18next.mdx +431 -0
  4. package/blog/en/intlayer_with_next-intl.mdx +335 -0
  5. package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +403 -140
  6. package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  7. package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +185 -71
  8. package/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  9. package/blog/it/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  10. package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  11. package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  12. package/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  13. package/blog/ru/next-i18next_vs_next-intl_vs_intlayer.md +36 -28
  14. package/blog/tr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
  15. package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
  16. package/dist/cjs/generated/docs.entry.cjs +16 -0
  17. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  18. package/dist/esm/generated/docs.entry.mjs +16 -0
  19. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  20. package/dist/types/generated/docs.entry.d.ts +1 -0
  21. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  22. package/docs/ar/component_i18n.md +186 -0
  23. package/docs/ar/vs_code_extension.md +48 -109
  24. package/docs/de/component_i18n.md +186 -0
  25. package/docs/de/vs_code_extension.md +46 -107
  26. package/docs/en/component_i18n.md +186 -0
  27. package/docs/en/intlayer_with_nextjs_14.md +18 -1
  28. package/docs/en/intlayer_with_nextjs_15.md +18 -1
  29. package/docs/en/vs_code_extension.md +24 -114
  30. package/docs/en-GB/component_i18n.md +186 -0
  31. package/docs/en-GB/vs_code_extension.md +42 -103
  32. package/docs/es/component_i18n.md +182 -0
  33. package/docs/es/vs_code_extension.md +53 -114
  34. package/docs/fr/component_i18n.md +186 -0
  35. package/docs/fr/vs_code_extension.md +50 -111
  36. package/docs/hi/component_i18n.md +186 -0
  37. package/docs/hi/vs_code_extension.md +49 -110
  38. package/docs/it/component_i18n.md +186 -0
  39. package/docs/it/vs_code_extension.md +50 -111
  40. package/docs/ja/component_i18n.md +186 -0
  41. package/docs/ja/vs_code_extension.md +50 -111
  42. package/docs/ko/component_i18n.md +186 -0
  43. package/docs/ko/vs_code_extension.md +48 -109
  44. package/docs/pt/component_i18n.md +186 -0
  45. package/docs/pt/vs_code_extension.md +46 -107
  46. package/docs/ru/component_i18n.md +186 -0
  47. package/docs/ru/vs_code_extension.md +48 -109
  48. package/docs/tr/component_i18n.md +186 -0
  49. package/docs/tr/vs_code_extension.md +54 -115
  50. package/docs/zh/component_i18n.md +186 -0
  51. package/docs/zh/vs_code_extension.md +51 -105
  52. package/package.json +11 -11
  53. package/src/generated/docs.entry.ts +16 -0
@@ -0,0 +1,186 @@
1
+ ---
2
+ createdAt: 2024-03-07
3
+ updatedAt: 2025-09-30
4
+ title: Make a component multilingual (i18n library) in React and Next.js
5
+ description: Learn how to declare and retrieve localised content to build a multilingual React or Next.js component with Intlayer.
6
+ keywords:
7
+ - i18n
8
+ - component
9
+ - react
10
+ - multilingual
11
+ - next.js
12
+ - intlayer
13
+ slugs:
14
+ - doc
15
+ - component
16
+ - i18n
17
+ applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
18
+ youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
19
+ ---
20
+
21
+ # How to make a component multilingual (i18n) with Intlayer
22
+
23
+ This guide shows the minimal steps to make a UI component multilingual in two common setups:
24
+
25
+ - React (Vite/SPA)
26
+ - Next.js (App Router)
27
+
28
+ You will first declare your content, then retrieve it in your component.
29
+
30
+ ## 1) Declare your content (shared for React and Next.js)
31
+
32
+ Create a content declaration file near your component. This keeps translations close to where they are used and enables type safety.
33
+
34
+ ```ts fileName="component.content.ts"
35
+ import { t, type Dictionary } from "intlayer";
36
+
37
+ const componentContent = {
38
+ key: "component-example",
39
+ content: {
40
+ title: t({
41
+ en: "Hello",
42
+ fr: "Bonjour",
43
+ es: "Hola",
44
+ }),
45
+ description: t({
46
+ en: "A multilingual React component",
47
+ fr: "Un composant React multilingue",
48
+ es: "Un componente React multilingüe",
49
+ }),
50
+ },
51
+ } satisfies Dictionary;
52
+
53
+ export default componentContent;
54
+ ```
55
+
56
+ JSON is also supported if you prefer configuration files.
57
+
58
+ ```json fileName="component.content.json"
59
+ {
60
+ "$schema": "https://intlayer.org/schema.json",
61
+ "key": "component-example",
62
+ "content": {
63
+ "title": {
64
+ "nodeType": "translation",
65
+ "translation": { "en": "Hello", "fr": "Bonjour", "es": "Hola" }
66
+ },
67
+ "description": {
68
+ "nodeType": "translation",
69
+ "translation": {
70
+ "en": "A multilingual React component",
71
+ "fr": "Un composant React multilingue",
72
+ "es": "Un componente React multilingüe"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## 2) Retrieve your content
80
+
81
+ ### Case A — React app (Vite/SPA)
82
+
83
+ Default approach: use `useIntlayer` to retrieve by key. This keeps components lean and typed.
84
+
85
+ ```tsx fileName="ComponentExample.tsx"
86
+ import { useIntlayer } from "react-intlayer";
87
+
88
+ export function ComponentExample() {
89
+ const content = useIntlayer("component-example");
90
+ return (
91
+ <div>
92
+ <h1>{content.title}</h1>
93
+ <p>{content.description}</p>
94
+ </div>
95
+ );
96
+ }
97
+ ```
98
+
99
+ Server-side rendering or outside provider: use `react-intlayer/server` and pass an explicit `locale` when required.
100
+
101
+ ```tsx fileName="ServerRenderedExample.tsx"
102
+ import { useIntlayer } from "react-intlayer/server";
103
+
104
+ export function ServerRenderedExample({ locale }: { locale: string }) {
105
+ const content = useIntlayer("component-example", locale);
106
+ return (
107
+ <>
108
+ <h1>{content.title}</h1>
109
+ <p>{content.description}</p>
110
+ </>
111
+ );
112
+ }
113
+ ```
114
+
115
+ Alternative: `useDictionary` can read an entire declared object if you prefer collocating structure at the call site.
116
+
117
+ ```tsx fileName="ComponentWithDictionary.tsx"
118
+ import { useDictionary } from "react-intlayer";
119
+ import componentContent from "./component.content";
120
+
121
+ export function ComponentWithDictionary() {
122
+ const { title, description } = useDictionary(componentContent);
123
+ return (
124
+ <div>
125
+ <h1>{title}</h1>
126
+ <p>{description}</p>
127
+ </div>
128
+ );
129
+ }
130
+ ```
131
+
132
+ ### Case B — Next.js (App Router)
133
+
134
+ Prefer server components for data safety and performance. Use `useIntlayer` from `next-intlayer/server` in server files, and `useIntlayer` from `next-intlayer` in client components.
135
+
136
+ ```tsx fileName="app/[locale]/example/ServerComponent.tsx"
137
+ import { useIntlayer } from "next-intlayer/server";
138
+
139
+ export default function ServerComponent() {
140
+ const content = useIntlayer("component-example");
141
+ return (
142
+ <>
143
+ <h1>{content.title}</h1>
144
+ <p>{content.description}</p>
145
+ </>
146
+ );
147
+ }
148
+ ```
149
+
150
+ ```tsx fileName="app/[locale]/example/ClientComponent.tsx"
151
+ "use client";
152
+
153
+ import { useIntlayer } from "next-intlayer";
154
+
155
+ export function ClientComponent() {
156
+ const content = useIntlayer("component-example");
157
+ return (
158
+ <div>
159
+ <h1>{content.title}</h1>
160
+ <p>{content.description}</p>
161
+ </div>
162
+ );
163
+ }
164
+ ```
165
+
166
+ Tip: For page metadata and SEO, you can also fetch content using `getIntlayer` and generate multilingual URLs via `getMultilingualUrls`.
167
+
168
+ ## Why Intlayer’s component approach is best
169
+
170
+ - **Collocation**: Content declarations live near components, reducing drift and improving reuse across design systems.
171
+ - **Type safety**: Keys and structures are strongly typed; missing translations surface at build-time rather than at runtime.
172
+ - **Server-first**: Works natively in server components for better security and performance; client hooks remain ergonomic.
173
+ - **Tree-shaking**: Only content used by the component is bundled, keeping payloads small in large applications.
174
+ - **DX & tooling**: Built-in middleware, SEO helpers, and optional Visual Editor/AI translations streamline everyday work.
175
+
176
+ See the comparisons and patterns in the Next.js-focused roundup: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
177
+
178
+ ## Related guides and references
179
+
180
+ - React setup (Vite): https://intlayer.org/doc/environment/vite-and-react
181
+ - React Router v7: https://intlayer.org/doc/environment/vite-and-react/react-router-v7
182
+ - TanStack Start: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
183
+ - Next.js setup: https://intlayer.org/doc/environment/nextjs
184
+ - Why Intlayer vs. next-intl vs. next-i18next: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
185
+
186
+ These pages include end-to-end setup, providers, routing, and SEO helpers.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2025-03-17
3
- updatedAt: 2025-09-22
3
+ updatedAt: 2025-09-30
4
4
  title: Official VS Code Extension
5
5
  description: Learn how to use the Intlayer extension in VS Code to enhance your development workflow. Quickly navigate between localised content and manage your dictionaries efficiently.
6
6
  keywords:
@@ -23,92 +23,36 @@ slugs:
23
23
 
24
24
  [**Intlayer**](https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension) is the official Visual Studio Code extension for **Intlayer**, designed to improve the developer experience when working with localised content in your projects.
25
25
 
26
- ![Intlayer VS Code Extension](https://github.com/aymericzip/intlayer/blob/main/docs/assets/vs_code_extension_demo.gif)
26
+ ![Intlayer VS Code Extension](https://github.com/aymericzip/intlayer/blob/main/docs/assets/vs_code_extension_demo.gif?raw=true)
27
27
 
28
28
  Extension link: [https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension](https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension)
29
29
 
30
30
  ## Features
31
31
 
32
- ### Instant Navigation
32
+ ![Fill dictionaries](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_fill_active_dictionary.gif?raw=true)
33
33
 
34
- **Go to Definition Support** – Use `⌘ + Click` (Mac) or `Ctrl + Click` (Windows/Linux) on a `useIntlayer` key to open the corresponding content file instantly.
35
- **Seamless Integration** – Works effortlessly with **react-intlayer** and **next-intlayer** projects.
36
- **Multi-language Support** – Supports localised content across different languages.
37
- **VS Code Integration** – Smoothly integrates with VS Code’s navigation and command palette.
38
-
39
- ### Dictionary Management Commands
40
-
41
- Manage your content dictionaries directly from VS Code:
42
-
43
- - **Build Dictionaries** – Generate content files based on your project structure.
44
- - **Push Dictionaries** – Upload the latest dictionary content to your repository.
45
- - **Pull Dictionaries** – Synchronise the latest dictionary content from your repository to your local environment.
34
+ - **Instant Navigation** – Quickly jump to the correct content file when clicking on a `useIntlayer` key.
46
35
  - **Fill Dictionaries** – Populate dictionaries with content from your project.
47
- - **Test Dictionaries** – Identify missing or incomplete translations.
48
-
49
- ### Content Declaration Generator
50
-
51
- Easily generate structured dictionary files in different formats:
52
36
 
53
- If you are currently working on a component, it will generate the `.content.{ts,tsx,js,jsx,mjs,cjs,json}` file for you.
37
+ ![List commands](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_list_commands.gif?raw=true)
54
38
 
55
- Example of component:
39
+ - **Easy access to Intlayer Commands** – Build, push, pull, fill, test content dictionaries with ease.
56
40
 
57
- ```tsx fileName="src/components/MyComponent/index.tsx"
58
- const MyComponent = () => {
59
- const { myTranslatedContent } = useIntlayer("my-component");
41
+ ![Create content file](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_create_content_file.gif?raw=true)
60
42
 
61
- return <span>{myTranslatedContent}</span>;
62
- };
63
- ```
64
-
65
- Generated file in TypeScript format:
43
+ - **Content Declaration Generator** – Create dictionary content files in various formats (`.ts`, `.esm`, `.cjs`, `.json`).
66
44
 
67
- ```tsx fileName="src/components/MyComponent/index.content.ts"
68
- import { t, type Dictionary } from "intlayer";
45
+ ![Test dictionaties](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_test_missing_dictionary.gif?raw=true)
69
46
 
70
- const componentContent = {
71
- key: "my-component",
72
- content: {
73
- myTranslatedContent: t({
74
- en: "Hello World",
75
- es: "Hola Mundo",
76
- fr: "Bonjour le monde",
77
- }),
78
- },
79
- };
47
+ - **Test Dictionaries** – Test dictionaries for missing translations.
80
48
 
81
- export default componentContent;
82
- ```
49
+ ![Rebuild dictionary](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_rebuild_dictionary.gif?raw=true)
83
50
 
84
- Available formats:
51
+ - **Keep your dictionaries up to date** – Keep your dictionaries up to date with the latest content from your project.
85
52
 
86
- - **TypeScript (`.ts`)**
87
- - **ES Module (`.esm`)**
88
- - **CommonJS (`.cjs`)**
89
- - **JSON (`.json`)**
90
-
91
- ### Intlayer Tab (Activity Bar)
53
+ ![Intlayer Tab (Activity Bar)](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_search_dictionary.gif?raw=true)
92
54
 
93
- Open the Intlayer tab by clicking the Intlayer icon in the VS Code Activity Bar. It contains two views:
94
-
95
- - **Search**: A live search bar to quickly filter dictionaries and their content. Typing updates the results instantly.
96
- - **Dictionaries**: A tree view of your environments/projects, dictionary keys, and the files contributing entries. You can:
97
- - Click a file to open it in the editor.
98
- - Use the toolbar to run actions: Build, Pull, Push, Fill, Refresh, Test, and Create Dictionary File.
99
- - Use the context menu for item‑specific actions:
100
- - On a dictionary: Pull or Push
101
- - On a file: Fill Dictionary
102
- - When you switch editors, the tree will reveal the matching file if it belongs to a dictionary.
103
-
104
- ## Installation
105
-
106
- You can install **Intlayer** directly from the VS Code Marketplace:
107
-
108
- 1. Open **VS Code**.
109
- 2. Go to the **Extensions Marketplace**.
110
- 3. Search for **"Intlayer"**.
111
- 4. Click **Install**.
55
+ - **Intlayer Tab (Activity Bar)** Browse and search dictionaries from a dedicated side tab with toolbar and context actions (Build, Pull, Push, Fill, Refresh, Test, Create File).
112
56
 
113
57
  ## Usage
114
58
 
@@ -124,60 +68,55 @@ You can install **Intlayer** directly from the VS Code Marketplace:
124
68
  3. **Command-click** (`⌘+Click` on macOS) or **Ctrl+Click** (on Windows/Linux) on the key (e.g., `"app"`).
125
69
  4. VS Code will automatically open the corresponding dictionary file, e.g., `src/app.content.ts`.
126
70
 
127
- ### Managing Content Dictionaries
128
-
129
71
  ### Intlayer Tab (Activity Bar)
130
72
 
131
73
  Use the side tab to browse and manage dictionaries:
132
74
 
133
75
  - Open the Intlayer icon in the Activity Bar.
134
76
  - In **Search**, type to filter dictionaries and entries in real time.
135
- - In **Dictionaries**, browse environments, dictionaries, and files. Use the toolbar for Build, Pull, Push, Fill, Refresh, Test, and Create Dictionary File. Rightclick for context actions (Pull/Push on dictionaries, Fill on files). The current editor file autoreveals in the tree when applicable.
77
+ - In **Dictionaries**, browse environments, dictionaries, and files. Use the toolbar for Build, Pull, Push, Fill, Refresh, Test, and Create Dictionary File. Right-click for context actions (Pull/Push on dictionaries, Fill on files). The current editor file auto-reveals in the tree when applicable.
136
78
 
137
- #### Building Dictionaries
79
+ ### Accessing the commands
138
80
 
139
- Generate all dictionary content files with:
81
+ You can access the commands from the **Command Palette**.
140
82
 
141
83
  ```sh
142
84
  Cmd + Shift + P (macOS) / Ctrl + Shift + P (Windows/Linux)
143
85
  ```
144
86
 
145
- Search for **Build Dictionaries** and execute the command.
146
-
147
- #### Pushing Dictionaries
148
-
149
- Upload the latest dictionary content:
150
-
151
- 1. Open the **Command Palette**.
152
- 2. Search for **Push Dictionaries**.
153
- 3. Select the dictionaries to push and confirm.
154
-
155
- #### Pulling Dictionaries
87
+ - **Build Dictionaries**
88
+ - **Push Dictionaries**
89
+ - **Pull Dictionaries**
90
+ - **Fill Dictionaries**
91
+ - **Test Dictionaries**
92
+ - **Create Dictionary File**
156
93
 
157
- Sync the latest dictionary content:
94
+ ### Loading Environment Variables
158
95
 
159
- 1. Open the **Command Palette**.
160
- 2. Search for **Pull Dictionaries**.
161
- 3. Choose the dictionaries to pull.
96
+ Intlayer recommends storing your AI API keys, as well as the Intlayer client ID and secret, in environment variables.
162
97
 
163
- #### Filling Dictionaries
98
+ The extension can load environment variables from your workspace to run Intlayer commands with the correct context.
164
99
 
165
- Fill dictionaries with content from your project:
100
+ - **Load order (by priority)**: `.env.<env>.local` → `.env.<env>` → `.env.local` → `.env`
101
+ - **Non-destructive**: existing `process.env` values are not overridden.
102
+ - **Scope**: files are resolved from the configured base directory (defaults to the workspace root).
166
103
 
167
- 1. Open the **Command Palette**.
168
- 2. Search for **Fill Dictionaries**.
169
- 3. Run the command to populate dictionaries.
104
+ #### Selecting the active environment
170
105
 
171
- #### Testing Dictionaries
106
+ - **Command Palette**: open the palette and run `Intlayer: Select Environment`, then choose the environment (e.g., `development`, `staging`, `production`). The extension will attempt to load the first available file in the priority list above and show a notification like “Loaded env from .env.<env>.local”.
107
+ - **Settings**: go to `Settings → Extensions → Intlayer`, and set:
108
+ - **Environment**: the environment name used to resolve `.env.<env>*` files.
109
+ - (Optional) **Env File**: an explicit path to a `.env` file. When provided, it takes precedence over the inferred list.
172
110
 
173
- Validate dictionaries and find missing translations:
111
+ #### Monorepos and custom directories
174
112
 
175
- 1. Open the **Command Palette**.
176
- 2. Search for **Test Dictionaries**.
177
- 3. Review the reported issues and fix as needed.
113
+ If your `.env` files reside outside the workspace root, set the **Base Directory** in `Settings → Extensions → Intlayer`. The loader will search for `.env` files relative to that directory.
178
114
 
179
115
  ## Doc History
180
116
 
181
- | Version | Date | Changes |
182
- | ------- | ---------- | ------------ |
183
- | 5.5.10 | 2025-06-29 | Init history |
117
+ | Version | Date | Changes |
118
+ | ------- | ---------- | ----------------------------------- |
119
+ | 6.1.5 | 2025-09-30 | Added demo gif |
120
+ | 6.1.0 | 2025-09-24 | Added environment selection section |
121
+ | 6.0.0 | 2025-09-22 | Intlayer Tab / Fill & Test commands |
122
+ | 5.5.10 | 2025-06-29 | Initial history |
@@ -0,0 +1,182 @@
1
+ ---
2
+ createdAt: 2024-03-07
3
+ updatedAt: 2025-09-30
4
+ title: Hacer un componente multilingüe (biblioteca i18n) en React y Next.js
5
+ description: Aprende a declarar y recuperar contenido localizado para construir un componente multilingüe de React o Next.js con Intlayer.
6
+ keywords:
7
+ - i18n
8
+ - componente
9
+ - react
10
+ - multilingüe
11
+ - next.js
12
+ - intlayer
13
+ slugs:
14
+ - doc
15
+ - component
16
+ - i18n
17
+ applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
18
+ youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
19
+ ---
20
+
21
+ # Cómo hacer un componente multilingüe (i18n) con Intlayer
22
+
23
+ Esta guía muestra los pasos mínimos para hacer que un componente de interfaz sea multilingüe en dos configuraciones comunes:
24
+
25
+ - React (Vite/SPA)
26
+ - Next.js (App Router)
27
+
28
+ Primero declararás tu contenido y luego lo recuperarás en tu componente.
29
+
30
+ ## 1) Declara tu contenido (compartido para React y Next.js)
31
+
32
+ Crea un archivo de declaración de contenido cerca de tu componente. Esto mantiene las traducciones cerca del lugar donde se usan y habilita la seguridad de tipos.
33
+
34
+ ```ts fileName="component.content.ts"
35
+ import { t, type Dictionary } from "intlayer";
36
+
37
+ const componentContent = {
38
+ key: "component-example",
39
+ content: {
40
+ title: t({
41
+ en: "Hello",
42
+ fr: "Bonjour",
43
+ es: "Hola",
44
+ }),
45
+ description: t({
46
+ en: "A multilingual React component",
47
+ fr: "Un composant React multilingue",
48
+ es: "Un componente React multilingüe",
49
+ }),
50
+ },
51
+ } satisfies Dictionary;
52
+
53
+ export default componentContent;
54
+ ```
55
+
56
+ También se admite JSON si prefieres archivos de configuración.
57
+
58
+ ```json fileName="component.content.json"
59
+ {
60
+ "$schema": "https://intlayer.org/schema.json",
61
+ "key": "component-example",
62
+ "content": {
63
+ "title": {
64
+ "nodeType": "translation",
65
+ "translation": { "en": "Hello", "fr": "Bonjour", "es": "Hola" }
66
+ },
67
+ "description": {
68
+ "nodeType": "translation",
69
+ "translation": {
70
+ "en": "A multilingual React component",
71
+ "fr": "Un composant React multilingue",
72
+ "es": "Un componente React multilingüe"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## 2) Recupera tu contenido
80
+
81
+ ### Caso A — Aplicación React (Vite/SPA)
82
+
83
+ Enfoque por defecto: usa `useIntlayer` para recuperar por clave. Esto mantiene los componentes ligeros y tipados.
84
+
85
+ ```tsx fileName="ComponentExample.tsx"
86
+ import { useIntlayer } from "react-intlayer";
87
+
88
+ export function ComponentExample() {
89
+ const content = useIntlayer("component-example");
90
+ return (
91
+ <div>
92
+ <h1>{content.title}</h1>
93
+ <p>{content.description}</p>
94
+ </div>
95
+ );
96
+ }
97
+ ```
98
+
99
+ Renderizado en servidor o fuera del provider: usa `react-intlayer/server` y pasa un `locale` explícito cuando sea necesario.
100
+
101
+ ```tsx fileName="ServerRenderedExample.tsx"
102
+ import { useIntlayer } from "react-intlayer/server";
103
+
104
+ export function ServerRenderedExample({ locale }: { locale: string }) {
105
+ const content = useIntlayer("component-example", locale);
106
+ return (
107
+ <>
108
+ <h1>{content.title}</h1>
109
+ <p>{content.description}</p>
110
+ </>
111
+ );
112
+ }
113
+ ```
114
+
115
+ Alternativa: `useDictionary` puede leer un objeto declarado completo si prefieres colocar la estructura en el punto de uso.
116
+
117
+ ```tsx fileName="ComponentWithDictionary.tsx"
118
+ import { useDictionary } from "react-intlayer";
119
+ import componentContent from "./component.content";
120
+
121
+ export function ComponentWithDictionary() {
122
+ const { title, description } = useDictionary(componentContent);
123
+ return (
124
+ <div>
125
+ <h1>{title}</h1>
126
+ <p>{description}</p>
127
+ </div>
128
+ );
129
+ }
130
+ ```
131
+
132
+ ### Caso B — Next.js (App Router)
133
+
134
+ Prefiere componentes de servidor por seguridad y rendimiento. Usa `useIntlayer` de `next-intlayer/server` en archivos de servidor, y `useIntlayer` de `next-intlayer` en componentes cliente.
135
+
136
+ ```tsx fileName="app/[locale]/example/ServerComponent.tsx"
137
+ import { useIntlayer } from "next-intlayer/server";
138
+
139
+ export default function ServerComponent() {
140
+ const content = useIntlayer("component-example");
141
+ return (
142
+ <>
143
+ <h1>{content.title}</h1>
144
+ <p>{content.description}</p>
145
+ </>
146
+ );
147
+ }
148
+ ```
149
+
150
+ ```tsx fileName="app/[locale]/example/ClientComponent.tsx"
151
+ "use client";
152
+
153
+ import { useIntlayer } from "next-intlayer";
154
+
155
+ export function ClientComponent() {
156
+ const content = useIntlayer("component-example");
157
+ return (
158
+ <div>
159
+ <h1>{content.title}</h1>
160
+ <p>{content.description}</p>
161
+ </div>
162
+ );
163
+ }
164
+ ```
165
+
166
+ Consejo: Para metadatos de página y SEO, también puedes obtener contenido con `getIntlayer` y generar URLs multilingües con `getMultilingualUrls`.
167
+
168
+ ## Por qué el enfoque de componentes de Intlayer es el mejor
169
+
170
+ - Colocación: Las declaraciones de contenido viven cerca de los componentes, reduciendo la deriva y mejorando la reutilización en los sistemas de diseño.
171
+ - Seguridad de tipos: Las claves y estructuras están fuertemente tipadas; las traducciones faltantes aparecen en tiempo de build en lugar de en tiempo de ejecución.
172
+ - Server-first: Funciona de forma nativa en componentes de servidor para mejor seguridad y rendimiento; los hooks de cliente siguen siendo ergonómicos.
173
+ - Tree-shaking: Solo se incluye el contenido usado por el componente, manteniendo cargas pequeñas en aplicaciones grandes.
174
+ - DX y herramientas: Middleware incorporado, asistentes de SEO y traducciones opcionales mediante Editor Visual/IA agilizan el trabajo diario.
175
+
176
+ ## Guías y referencias relacionadas
177
+
178
+ - Configuración React (Vite): https://intlayer.org/doc/environment/vite-and-react
179
+ - React Router v7: https://intlayer.org/doc/environment/vite-and-react/react-router-v7
180
+ - TanStack Start: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
181
+ - Configuración Next.js: https://intlayer.org/doc/environment/nextjs
182
+ - Por qué Intlayer vs. next-intl vs. next-i18next: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer