@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: React 및 Next.js에서 컴포넌트를 다국어(i18n)로 만들기
5
+ description: Intlayer를 사용하여 다국어 React 또는 Next.js 컴포넌트를 만들기 위해 현지화된 콘텐츠를 선언하고 가져오는 방법을 배우세요.
6
+ keywords:
7
+ - i18n
8
+ - 컴포넌트
9
+ - react
10
+ - 다국어
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
+ # Intlayer로 컴포넌트를 다국어(i18n)로 만드는 방법
22
+
23
+ 이 가이드는 두 가지 일반적인 환경에서 UI 컴포넌트를 다국어로 만드는 최소 단계를 보여줍니다:
24
+
25
+ - React (Vite/SPA)
26
+ - Next.js (App Router)
27
+
28
+ 먼저 콘텐츠를 선언한 후 컴포넌트에서 이를 가져옵니다.
29
+
30
+ ## 1) 콘텐츠 선언하기 (React 및 Next.js 공통)
31
+
32
+ 컴포넌트 근처에 콘텐츠 선언 파일을 만드세요. 이렇게 하면 번역이 사용되는 위치와 가까워지고 타입 안전성을 보장할 수 있습니다.
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도 지원됩니다.
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": "다국어 React 컴포넌트",
71
+ "fr": "Un composant React multilingue",
72
+ "es": "Un componente React multilingüe"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## 2) 콘텐츠를 가져오기
80
+
81
+ ### 경우 A — React 앱 (Vite/SPA)
82
+
83
+ 기본 접근법: 키로 검색하기 위해 `useIntlayer`를 사용합니다. 이렇게 하면 컴포넌트가 간결하고 타입이 지정됩니다.
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
+ 서버 사이드 렌더링 또는 프로바이더 외부에서: 필요할 때 명시적인 `locale`을 전달하며 `react-intlayer/server`를 사용하세요.
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
+ 대안: 호출 위치에서 구조를 함께 배치하는 것을 선호한다면 `useDictionary`를 사용하여 전체 선언된 객체를 읽을 수 있습니다.
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
+ ### 사례 B — Next.js (앱 라우터)
133
+
134
+ 데이터 안전성과 성능을 위해 서버 컴포넌트를 선호하세요. 서버 파일에서는 `next-intlayer/server`에서 `useIntlayer`를 사용하고, 클라이언트 컴포넌트에서는 `next-intlayer`에서 `useIntlayer`를 사용하세요.
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
+ 팁: 페이지 메타데이터 및 SEO를 위해 `getIntlayer`를 사용하여 콘텐츠를 가져오고 `getMultilingualUrls`를 통해 다국어 URL을 생성할 수도 있습니다.
167
+
168
+ ## 왜 Intlayer의 컴포넌트 접근법이 최선인가
169
+
170
+ - **콜로케이션(Collocation)**: 콘텐츠 선언이 컴포넌트 근처에 위치하여 분산을 줄이고 디자인 시스템 전반에서 재사용성을 향상시킵니다.
171
+ - **타입 안전성(Type safety)**: 키와 구조가 강력하게 타입 지정되어 있으며, 누락된 번역은 런타임이 아닌 빌드 타임에 감지됩니다.
172
+ - **서버 우선(Server-first)**: 보안성과 성능 향상을 위해 서버 컴포넌트에서 네이티브로 작동하며, 클라이언트 훅은 여전히 사용하기 편리합니다.
173
+ - **트리 쉐이킹(Tree-shaking)**: 컴포넌트에서 사용하는 콘텐츠만 번들에 포함되어 대규모 앱에서도 페이로드를 작게 유지합니다.
174
+ - **개발자 경험(DX) 및 도구**: 내장 미들웨어, SEO 도우미, 선택적 비주얼 에디터/AI 번역 기능이 일상 작업을 간소화합니다.
175
+
176
+ Next.js 중심 비교 및 패턴은 다음 링크에서 확인하세요: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
177
+
178
+ ## 관련 가이드 및 참고 자료
179
+
180
+ - React 설정 (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 시작: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
183
+ - Next.js 설정: https://intlayer.org/doc/environment/nextjs
184
+ - Intlayer vs. next-intl vs. next-i18next 비교: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
185
+
186
+ 이 페이지들은 엔드 투 엔드 설정, 프로바이더, 라우팅, SEO 도우미를 포함합니다.
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  createdAt: 2025-03-17
3
- updatedAt: 2025-09-22
3
+ updatedAt: 2025-09-30
4
4
  title: 공식 VS 코드 확장
5
- description: VS 코드에서 Intlayer 확장을 사용하여 개발 워크플로를 향상시키는 방법을 알아보세요. 현지화된 콘텐츠 간을 빠르게 탐색하고 사전을 효율적으로 관리할 수 있습니다.
5
+ description: VS 코드에서 Intlayer 확장을 사용하여 개발 워크플로우를 향상시키는 방법을 알아보세요. 현지화된 콘텐츠 빠른 탐색과 사전 관리를 효율적으로 수행할 수 있습니다.
6
6
  keywords:
7
7
  - VS 코드 확장
8
8
  - Intlayer
@@ -23,161 +23,100 @@ slugs:
23
23
 
24
24
  [**Intlayer**](https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension)는 프로젝트에서 현지화된 콘텐츠 작업 시 개발자 경험을 향상시키기 위해 설계된 **Intlayer**의 공식 Visual Studio Code 확장입니다.
25
25
 
26
- ![Intlayer VS 코드 확장](https://github.com/aymericzip/intlayer/blob/main/docs/assets/vs_code_extension_demo.gif)
26
+ ![Intlayer VS 코드 확장](https://github.com/aymericzip/intlayer/blob/main/docs/assets/vs_code_extension_demo.gif?raw=true)
27
27
 
28
28
  확장 링크: [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
  ## 기능
31
31
 
32
- ### 즉시 탐색
32
+ ![사전 채우기](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_fill_active_dictionary.gif?raw=true)
33
33
 
34
- **정의로 이동 지원** – `useIntlayer` 키에서 `⌘ + 클릭`(Mac) 또는 `Ctrl + 클릭`(Windows/Linux)을 사용하여 해당 콘텐츠 파일을 즉시 엽니다.
35
- **원활한 통합** – **react-intlayer** 및 **next-intlayer** 프로젝트와 문제없이 작동합니다.
36
- **다국어 지원** – 다양한 언어의 현지화된 콘텐츠를 지원합니다.
37
- **VS 코드 통합** – VS 코드의 탐색 및 명령 팔레트와 원활하게 통합됩니다.
38
-
39
- ### 사전 관리 명령어
40
-
41
- VS 코드에서 직접 콘텐츠 사전을 관리하세요:
42
-
43
- - **사전 빌드** – 프로젝트 구조를 기반으로 콘텐츠 파일을 생성합니다.
44
- - **사전 푸시** – 최신 사전 콘텐츠를 저장소에 업로드합니다.
45
- - **사전 풀** – 저장소에서 최신 사전 콘텐츠를 로컬 환경으로 동기화합니다.
34
+ - **즉시 탐색** – `useIntlayer` 키를 클릭하면 올바른 콘텐츠 파일로 빠르게 이동합니다.
46
35
  - **사전 채우기** – 프로젝트의 콘텐츠로 사전을 채웁니다.
47
- - **사전 테스트** – 누락되었거나 불완전한 번역을 식별합니다.
48
-
49
- ### 콘텐츠 선언 생성기
50
-
51
- 다양한 형식으로 구조화된 사전 파일을 쉽게 생성할 수 있습니다:
52
36
 
53
- 현재 컴포넌트 작업 중이라면 `.content.{ts,tsx,js,jsx,mjs,cjs,json}` 파일을 자동으로 생성합니다.
37
+ ![명령어 목록](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_list_commands.gif?raw=true)
54
38
 
55
- 컴포넌트 예시:
39
+ - **Intlayer 명령어에 쉽게 접근** – 콘텐츠 사전을 빌드, 푸시, 풀, 채우기, 테스트를 손쉽게 수행합니다.
56
40
 
57
- ```tsx fileName="src/components/MyComponent/index.tsx"
58
- const MyComponent = () => {
59
- const { myTranslatedContent } = useIntlayer("my-component");
41
+ ![콘텐츠 파일 생성](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
- TypeScript 형식으로 생성된 파일:
43
+ - **콘텐츠 선언 생성기** – 다양한 형식(`.ts`, `.esm`, `.cjs`, `.json`)으로 사전 콘텐츠 파일을 생성합니다.
66
44
 
67
- ```tsx fileName="src/components/MyComponent/index.content.ts"
68
- import { t, type Dictionary } from "intlayer";
45
+ ![사전 테스트](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
+ - **사전 테스트** – 누락된 번역이 있는지 사전을 테스트합니다.
80
48
 
81
- export default componentContent;
82
- ```
49
+ ![사전 재구성](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_rebuild_dictionary.gif?raw=true)
83
50
 
84
- 사용 가능한 형식:
51
+ - **사전을 최신 상태로 유지** – 프로젝트의 최신 콘텐츠로 사전을 최신 상태로 유지합니다.
85
52
 
86
- - **TypeScript (`.ts`)**
87
- - **ES 모듈 (`.esm`)**
88
- - **CommonJS (`.cjs`)**
89
- - **JSON (`.json`)**
90
-
91
- ### Intlayer 탭 (활동 표시줄)
53
+ ![Intlayer (활동 표시줄)](https://github.com/aymericzip/intlayer-vs-code-extension/blob/master/assets/vscode_extention_search_dictionary.gif?raw=true)
92
54
 
93
- VS Code 활동 표시줄에서 Intlayer 아이콘을 클릭하여 Intlayer 탭을 엽니다. 탭에는 가지 뷰가 포함되어 있습니다:
94
-
95
- - **검색(Search)**: 사전과 그 내용을 빠르게 필터링할 수 있는 실시간 검색 바입니다. 입력할 때마다 결과가 즉시 업데이트됩니다.
96
- - **사전(Dictionaries)**: 환경/프로젝트, 사전 키, 그리고 항목을 기여하는 파일들의 트리 뷰입니다. 다음 작업을 할 수 있습니다:
97
- - 파일을 클릭하여 편집기에서 엽니다.
98
- - 툴바를 사용하여 다음 작업을 실행합니다: 빌드(Build), 풀(Pull), 푸시(Push), 채우기(Fill), 새로고침(Refresh), 테스트(Test), 사전 파일 생성(Create Dictionary File).
99
- - 항목별 작업을 위한 컨텍스트 메뉴를 사용합니다:
100
- - 사전에서는: 풀(Pull) 또는 푸시(Push)
101
- - 파일에서는: 사전 채우기(Fill Dictionary)
102
- - 편집기를 전환할 때, 해당 파일이 사전에 속해 있으면 트리가 일치하는 파일을 표시합니다.
103
-
104
- ## 설치
105
-
106
- **Intlayer**를 VS Code 마켓플레이스에서 직접 설치할 수 있습니다:
107
-
108
- 1. **VS Code**를 엽니다.
109
- 2. **확장 마켓플레이스**로 이동합니다.
110
- 3. **"Intlayer"**를 검색합니다.
111
- 4. **설치**를 클릭합니다.
55
+ - **Intlayer 탭 (활동 표시줄)** 전용 사이드 탭에서 도구 모음과 컨텍스트 작업(빌드, 풀, 푸시, 채우기, 새로 고침, 테스트, 파일 생성)과 함께 사전을 탐색하고 검색합니다.
112
56
 
113
57
  ## 사용법
114
58
 
115
59
  ### 빠른 탐색
116
60
 
117
61
  1. **react-intlayer**를 사용하는 프로젝트를 엽니다.
118
- 2. `useIntlayer()` 호출을 찾습니다. 예를 들어:
62
+ 2. 다음과 같이 `useIntlayer()` 호출을 찾습니다:
119
63
 
120
64
  ```tsx
121
65
  const content = useIntlayer("app");
122
66
  ```
123
67
 
124
- 3. 키(예: `"app"`)에서 **Command-클릭**(`⌘+Click`, macOS) 또는 **Ctrl-클릭**(Windows/Linux)합니다.
125
- 4. VS Code가 자동으로 해당 사전 파일(예: `src/app.content.ts`)을 엽니다.
126
-
127
- ### 콘텐츠 사전 관리
68
+ 3. 키(예: `"app"`)에서 **명령-클릭**(`⌘+클릭` macOS) 또는 **Ctrl+클릭**(Windows/Linux)합니다.
69
+ 4. VS Code가 자동으로 해당 사전 파일을 엽니다. 예: `src/app.content.ts`.
128
70
 
129
71
  ### Intlayer 탭 (활동 표시줄)
130
72
 
131
- 사전을 탐색하고 관리하려면 사이드 탭을 사용하세요:
73
+ 사이드 탭을 사용하여 사전을 탐색하고 관리하세요:
132
74
 
133
75
  - 활동 표시줄에서 Intlayer 아이콘을 엽니다.
134
- - **검색(Search)**에서 실시간으로 사전과 항목을 필터링하려면 입력하세요.
135
- - **사전(Dictionaries)**에서는 환경, 사전, 파일을 탐색할 수 있습니다. 툴바를 사용하여 빌드(Build), 풀(Pull), 푸시(Push), 채우기(Fill), 새로고침(Refresh), 테스트(Test), 사전 파일 생성(Create Dictionary File)을 수행하세요. 사전에서 풀/푸시, 파일에서 채우기 등의 컨텍스트 작업은 마우스 오른쪽 버튼 클릭으로 실행할 수 있습니다. 현재 편집 중인 파일은 해당되는 경우 트리에서 자동으로 표시됩니다.
76
+ - **검색**에서 입력하여 사전과 항목을 실시간으로 필터링합니다.
77
+ - **사전**에서 환경, 사전, 파일을 탐색합니다. 툴바를 사용하여 빌드(Build), 풀(Pull), 푸시(Push), 채우기(Fill), 새로고침(Refresh), 테스트(Test), 사전 파일 생성(Create Dictionary File)을 수행할 있습니다. 마우스 오른쪽 버튼 클릭으로 컨텍스트 작업(사전에서 풀/푸시, 파일에서 채우기)을 사용할 수 있습니다. 현재 편집 중인 파일은 해당되는 경우 트리에서 자동으로 표시됩니다.
136
78
 
137
- #### 사전 빌드하기
79
+ ### 명령어 접근
138
80
 
139
- 모든 사전 콘텐츠 파일을 생성하려면:
81
+ 명령어는 **명령 팔레트**에서 접근할 수 있습니다.
140
82
 
141
83
  ```sh
142
84
  Cmd + Shift + P (macOS) / Ctrl + Shift + P (Windows/Linux)
143
85
  ```
144
86
 
145
- **Build Dictionaries**를 검색하여 명령을 실행하세요.
146
-
147
- #### 사전 푸시하기
148
-
149
- 최신 사전 콘텐츠를 업로드하려면:
150
-
151
- 1. **명령 팔레트(Command Palette)**를 엽니다.
152
- 2. **Push Dictionaries**를 검색합니다.
153
- 3. 푸시할 사전을 선택하고 확인합니다.
154
-
155
- #### 사전 풀하기
87
+ - **사전 빌드(Build Dictionaries)**
88
+ - **사전 푸시(Push Dictionaries)**
89
+ - **사전 풀(Pull Dictionaries)**
90
+ - **사전 채우기(Fill Dictionaries)**
91
+ - **사전 테스트(Test Dictionaries)**
92
+ - **사전 파일 생성(Create Dictionary File)**
156
93
 
157
- 최신 사전 콘텐츠 동기화:
94
+ ### 환경 변수 로딩
158
95
 
159
- 1. **명령 팔레트**를 엽니다.
160
- 2. **Pull Dictionaries**를 검색합니다.
161
- 3. 가져올 사전을 선택합니다.
96
+ Intlayer는 AI API 키와 Intlayer 클라이언트 ID 및 시크릿을 환경 변수에 저장할 것을 권장합니다.
162
97
 
163
- #### 사전 채우기
98
+ 확장 프로그램은 작업 공간에서 환경 변수를 로드하여 올바른 컨텍스트로 Intlayer 명령을 실행할 수 있습니다.
164
99
 
165
- 프로젝트의 콘텐츠로 사전을 채웁니다:
100
+ - **로드 순서(우선순위)**: `.env.<env>.local` → `.env.<env>` → `.env.local` → `.env`
101
+ - **비파괴적**: 기존의 `process.env` 값은 덮어쓰지 않습니다.
102
+ - **범위**: 파일은 구성된 기본 디렉터리(기본값은 작업 공간 루트)에서 해석됩니다.
166
103
 
167
- 1. **명령 팔레트**를 엽니다.
168
- 2. **Fill Dictionaries**를 검색합니다.
169
- 3. 사전을 채우기 위해 명령을 실행합니다.
104
+ #### 활성 환경 선택
170
105
 
171
- #### 사전 테스트
106
+ - **명령 팔레트**: 팔레트를 열고 `Intlayer: Select Environment` 명령을 실행한 후 환경(예: `development`, `staging`, `production`)을 선택합니다. 확장 기능은 위 우선순위 목록에서 첫 번째로 사용 가능한 파일을 로드하려 시도하며, “Loaded env from .env.<env>.local”과 같은 알림을 표시합니다.
107
+ - **설정**: `설정 → 확장 기능 → Intlayer`로 이동하여 다음을 설정합니다:
108
+ - **환경(Environment)**: `.env.<env>*` 파일을 해석하는 데 사용되는 환경 이름입니다.
109
+ - (선택 사항) **Env 파일**: 명시적인 `.env` 파일 경로입니다. 제공되면 추론된 목록보다 우선합니다.
172
110
 
173
- 사전을 검증하고 누락된 번역을 찾습니다:
111
+ #### 모노레포 사용자 지정 디렉토리
174
112
 
175
- 1. **명령 팔레트**를 엽니다.
176
- 2. **Test Dictionaries**를 검색합니다.
177
- 3. 보고된 문제를 검토하고 필요에 따라 수정합니다.
113
+ 워크스페이스 루트 외부에 `.env` 파일이 있는 경우, `설정 → 확장 기능 → Intlayer`에서 **기본 디렉터리**를 설정하세요. 로더는 해당 디렉터리를 기준으로 `.env` 파일을 찾습니다.
178
114
 
179
115
  ## 문서 이력
180
116
 
181
- | 버전 | 날짜 | 변경 사항 |
182
- | ------ | ---------- | ----------- |
183
- | 5.5.10 | 2025-06-29 | 이력 초기화 |
117
+ | 버전 | 날짜 | 변경 사항 |
118
+ | ------ | ---------- | ---------------------------------------- |
119
+ | 6.1.5 | 2025-09-30 | 데모 GIF 추가 |
120
+ | 6.1.0 | 2025-09-24 | 환경 선택 섹션 추가 |
121
+ | 6.0.0 | 2025-09-22 | Intlayer 탭 / 채우기 및 테스트 명령 추가 |
122
+ | 5.5.10 | 2025-06-29 | 초기 이력 |
@@ -0,0 +1,186 @@
1
+ ---
2
+ createdAt: 2024-03-07
3
+ updatedAt: 2025-09-30
4
+ title: Tornar um componente multilíngue (biblioteca i18n) em React e Next.js
5
+ description: Aprenda como declarar e recuperar conteúdo localizado para construir um componente multilíngue em React ou Next.js com Intlayer.
6
+ keywords:
7
+ - i18n
8
+ - componente
9
+ - react
10
+ - multilíngue
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
+ # Como tornar um componente multilíngue (i18n) com Intlayer
22
+
23
+ Este guia mostra os passos mínimos para tornar um componente de interface multilíngue em duas configurações comuns:
24
+
25
+ - React (Vite/SPA)
26
+ - Next.js (App Router)
27
+
28
+ Você primeiro declarará seu conteúdo, depois o recuperará no seu componente.
29
+
30
+ ## 1) Declare seu conteúdo (compartilhado para React e Next.js)
31
+
32
+ Crie um arquivo de declaração de conteúdo próximo ao seu componente. Isso mantém as traduções próximas de onde são usadas e permite segurança 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
+ JSON também é suportado se você preferir arquivos de configuração.
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) Recupere seu conteúdo
80
+
81
+ ### Caso A — Aplicação React (Vite/SPA)
82
+
83
+ Abordagem padrão: use `useIntlayer` para recuperar pelo key. Isso mantém os componentes enxutos e 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
+ Renderização do lado servidor ou fora do provider: use `react-intlayer/server` e passe um `locale` explícito quando necessário.
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` pode ler um objeto declarado inteiro se você preferir colocar a estrutura no local da chamada.
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
+ Prefira componentes de servidor para segurança dos dados e desempenho. Use `useIntlayer` de `next-intlayer/server` em arquivos de servidor, e `useIntlayer` de `next-intlayer` em 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
+ Dica: Para metadados de página e SEO, você também pode buscar conteúdo usando `getIntlayer` e gerar URLs multilíngues via `getMultilingualUrls`.
167
+
168
+ ## Por que a abordagem de componentes do Intlayer é a melhor
169
+
170
+ - **Colocação**: Declarações de conteúdo ficam próximas aos componentes, reduzindo desvios e melhorando o reuso em sistemas de design.
171
+ - **Segurança de tipos**: Chaves e estruturas são fortemente tipadas; traduções ausentes aparecem em tempo de build, e não em tempo de execução.
172
+ - **Server-first**: Funciona nativamente em componentes de servidor para melhor segurança e desempenho; hooks do cliente permanecem ergonômicos.
173
+ - **Tree-shaking**: Apenas o conteúdo usado pelo componente é incluído no pacote, mantendo os tamanhos pequenos em grandes aplicações.
174
+ - **DX & ferramentas**: Middleware embutido, auxiliares de SEO e traduções opcionais via Editor Visual/IA agilizam o trabalho diário.
175
+
176
+ Veja as comparações e padrões no resumo focado em Next.js: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
177
+
178
+ ## Guias e referências relacionadas
179
+
180
+ - Configuração React (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
+ - Início TanStack: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
183
+ - Configuração do Next.js: https://intlayer.org/doc/environment/nextjs
184
+ - Por que Intlayer vs. next-intl vs. next-i18next: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
185
+
186
+ Estas páginas incluem configuração completa, provedores, roteamento e auxiliares de SEO.