@intlayer/docs 7.0.4-canary.0 → 7.0.4
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.
- package/blog/ar/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +36 -1638
- package/blog/en/intlayer_with_next-i18next.md +22 -847
- package/blog/en/intlayer_with_next-intl.md +32 -1053
- package/blog/en/intlayer_with_react-i18next.md +38 -764
- package/blog/en/intlayer_with_react-intl.md +42 -1018
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/en/intlayer_cli.md +25 -0
- package/docs/en/intlayer_with_nextjs_14.md +2 -0
- package/docs/en/intlayer_with_nextjs_15.md +2 -0
- package/docs/en/intlayer_with_nextjs_16.md +2 -0
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
|
@@ -1,392 +1,133 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title: Intlayer
|
|
5
|
-
description:
|
|
6
|
-
keywords:
|
|
7
|
-
- next-intl
|
|
8
|
-
- Intlayer
|
|
9
|
-
- 국제화
|
|
10
|
-
- 문서화
|
|
11
|
-
- Next.js
|
|
12
|
-
- JavaScript
|
|
13
|
-
- React
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Intlayer를 사용하여 next-intl JSON 번역 자동화하는 방법
|
|
5
|
+
description: Next.js 애플리케이션에서 향상된 국제화를 위해 Intlayer와 next-intl을 사용하여 JSON 번역을 자동화하세요.
|
|
14
6
|
slugs:
|
|
15
7
|
- blog
|
|
16
8
|
- intlayer-with-next-intl
|
|
9
|
+
history:
|
|
10
|
+
- version: 7.0.0
|
|
11
|
+
date: 2025-10-29
|
|
12
|
+
changes: syncJSON 플러그인으로 변경
|
|
17
13
|
---
|
|
18
14
|
|
|
19
|
-
#
|
|
15
|
+
# Intlayer를 사용하여 next-intl JSON 번역 자동화하는 방법
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
## Intlayer란 무엇인가요?
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
**Intlayer**는 기존 i18n 솔루션의 한계를 극복하기 위해 설계된 혁신적이고 오픈 소스인 국제화 라이브러리입니다. Next.js 애플리케이션에서 콘텐츠 관리를 위한 현대적인 접근 방식을 제공합니다.
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
- Intlayer에서 `content declaration file`이라고 불리는 이 파일은 구조화된 데이터를 내보내는 JSON, JS 또는 TS 파일이 될 수 있습니다. 자세한 내용은 [Intlayer 문서](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/concept/content)에서 확인하세요.
|
|
27
|
-
- next-intl에서는 일반적으로 JSON 파일에서 `messages` 또는 `locale messages`라고 불립니다. 자세한 내용은 [next-intl 문서](https://github.com/amannn/next-intl)에서 확인하세요.
|
|
21
|
+
next-intl과의 구체적인 비교는 저희 [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md) 블로그 게시물을 참고하세요.
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
## 왜 Intlayer와 next-intl을 함께 사용해야 하나요?
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
Intlayer는 훌륭한 독립형 i18n 솔루션을 제공하지만(자세한 내용은 저희 [Next.js 통합 가이드](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/intlayer_with_nextjs_16.md)를 참조), 다음과 같은 여러 이유로 next-intl과 함께 사용하고자 할 수 있습니다:
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
1. **기존 코드베이스**: 이미 구축된 next-intl 구현이 있으며 Intlayer의 향상된 개발자 경험으로 점진적으로 이전하고자 할 때.
|
|
28
|
+
2. **레거시 요구사항**: 프로젝트가 기존 next-intl 플러그인이나 워크플로우와의 호환성을 필요로 할 때.
|
|
29
|
+
3. **팀 친숙도**: 팀이 next-intl에 익숙하지만 더 나은 콘텐츠 관리를 원할 때.
|
|
34
30
|
|
|
35
|
-
Intlayer
|
|
31
|
+
**이를 위해 Intlayer는 next-intl의 어댑터로 구현되어 CLI 또는 CI/CD 파이프라인에서 JSON 번역 자동화, 번역 테스트 등 다양한 작업을 지원할 수 있습니다.**
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
이 가이드는 next-intl과의 호환성을 유지하면서 Intlayer의 우수한 콘텐츠 선언 시스템을 활용하는 방법을 보여줍니다.
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
## 목차
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
<TOC/>
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
## next-intl과 함께 Intlayer 설정 단계별 가이드
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
### 1단계: 의존성 설치
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
└── src
|
|
50
|
-
└── components
|
|
51
|
-
└── MyComponent
|
|
52
|
-
├── index.content.ts # 콘텐츠 선언 파일
|
|
53
|
-
└── index.tsx
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
```bash codeFormat="esm"
|
|
57
|
-
.
|
|
58
|
-
└── src
|
|
59
|
-
└── components
|
|
60
|
-
└── MyComponent
|
|
61
|
-
├── index.content.mjs # 콘텐츠 선언 파일
|
|
62
|
-
└── index.mjx
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
```bash codeFormat="cjs"
|
|
66
|
-
.
|
|
67
|
-
└── src
|
|
68
|
-
└── components
|
|
69
|
-
└── MyComponent
|
|
70
|
-
├── index.content.cjs # 콘텐츠 선언 파일
|
|
71
|
-
└── index.cjx
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
```bash codeFormat="json"
|
|
75
|
-
.
|
|
76
|
-
└── src
|
|
77
|
-
└── components
|
|
78
|
-
└── MyComponent
|
|
79
|
-
├── index.content.json # 콘텐츠 선언 파일
|
|
80
|
-
└── index.jsx
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
2. **중앙집중식 번역**: Intlayer는 모든 번역을 하나의 콘텐츠 선언에 저장하여 아무런 번역도 누락되지 않도록 합니다. TypeScript 프로젝트에서는 누락된 번역이 자동으로 타입 오류로 표시되어 개발자가 즉각적으로 피드백을 받을 수 있습니다.
|
|
84
|
-
|
|
85
|
-
### 설치
|
|
86
|
-
|
|
87
|
-
Intlayer와 next-intl을 함께 사용하려면 두 라이브러리를 모두 설치해야 합니다:
|
|
43
|
+
필요한 패키지를 설치하세요:
|
|
88
44
|
|
|
89
45
|
```bash packageManager="npm"
|
|
90
|
-
npm install intlayer
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
```bash packageManager="yarn"
|
|
94
|
-
yarn add intlayer next-intl
|
|
46
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
95
47
|
```
|
|
96
48
|
|
|
97
49
|
```bash packageManager="pnpm"
|
|
98
|
-
pnpm add intlayer
|
|
50
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
99
51
|
```
|
|
100
52
|
|
|
101
|
-
|
|
53
|
+
```bash packageManager="yarn"
|
|
54
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
55
|
+
```
|
|
102
56
|
|
|
103
|
-
|
|
57
|
+
**패키지 설명:**
|
|
104
58
|
|
|
105
|
-
|
|
59
|
+
- **intlayer**: 국제화 관리, 콘텐츠 선언 및 빌드를 위한 핵심 라이브러리
|
|
60
|
+
- **@intlayer/sync-json-plugin**: Intlayer 콘텐츠 선언을 next-intl 호환 JSON 형식으로 내보내는 플러그인
|
|
106
61
|
|
|
107
|
-
|
|
108
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
62
|
+
### 2단계: JSON을 래핑하기 위한 Intlayer 플러그인 구현
|
|
109
63
|
|
|
110
|
-
|
|
111
|
-
internationalization: {
|
|
112
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
113
|
-
defaultLocale: Locales.ENGLISH,
|
|
114
|
-
},
|
|
115
|
-
content: {
|
|
116
|
-
dictionaryOutput: ["next-intl"], // next-intl 출력을 사용
|
|
117
|
-
nextIntlMessagesDir: "./intl/messages", // next-intl 메시지를 저장할 위치
|
|
118
|
-
},
|
|
119
|
-
};
|
|
64
|
+
지원하는 로케일을 정의하기 위해 Intlayer 구성 파일을 만듭니다:
|
|
120
65
|
|
|
121
|
-
|
|
122
|
-
```
|
|
66
|
+
**next-intl용 JSON 사전도 내보내고 싶다면**, `syncJSON` 플러그인을 추가하세요:
|
|
123
67
|
|
|
124
|
-
```
|
|
125
|
-
import { Locales } from "intlayer";
|
|
68
|
+
```typescript fileName="intlayer.config.ts"
|
|
69
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
70
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
126
71
|
|
|
127
|
-
|
|
128
|
-
const config = {
|
|
72
|
+
const config: IntlayerConfig = {
|
|
129
73
|
internationalization: {
|
|
130
74
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
131
75
|
defaultLocale: Locales.ENGLISH,
|
|
132
76
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
77
|
+
plugins: [
|
|
78
|
+
syncJSON({
|
|
79
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
137
82
|
};
|
|
138
83
|
|
|
139
84
|
export default config;
|
|
140
85
|
```
|
|
141
86
|
|
|
142
|
-
|
|
143
|
-
const { Locales } = require("intlayer");
|
|
144
|
-
|
|
145
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
146
|
-
const config = {
|
|
147
|
-
internationalization: {
|
|
148
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
149
|
-
defaultLocale: Locales.ENGLISH,
|
|
150
|
-
},
|
|
151
|
-
content: {
|
|
152
|
-
dictionaryOutput: ["next-intl"],
|
|
153
|
-
nextIntlMessagesDir: "./intl/messages",
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
module.exports = config;
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### 콘텐츠 선언
|
|
87
|
+
`syncJSON` 플러그인은 JSON을 자동으로 래핑합니다. 콘텐츠 구조를 변경하지 않고 JSON 파일을 읽고 씁니다.
|
|
161
88
|
|
|
162
|
-
|
|
89
|
+
만약 JSON과 intlayer 콘텐츠 선언 파일(`.content` 파일)을 공존시키고 싶다면, Intlayer는 다음과 같이 처리합니다:
|
|
163
90
|
|
|
164
|
-
|
|
165
|
-
import { t, type Dictionary } from "intlayer";
|
|
91
|
+
1. JSON과 콘텐츠 선언 파일을 모두 불러와 intlayer 사전으로 변환합니다.
|
|
166
92
|
|
|
167
|
-
|
|
168
|
-
key: "my-component",
|
|
169
|
-
content: {
|
|
170
|
-
helloWorld: t({
|
|
171
|
-
en: "Hello World",
|
|
172
|
-
es: "Hola Mundo",
|
|
173
|
-
fr: "Bonjour le monde",
|
|
174
|
-
}),
|
|
175
|
-
},
|
|
176
|
-
} satisfies Dictionary;
|
|
177
|
-
|
|
178
|
-
export default content;
|
|
179
|
-
```
|
|
93
|
+
2. JSON과 콘텐츠 선언 파일 간에 충돌이 있는 경우, Intlayer는 모든 사전을 병합하는 과정을 진행합니다. 이는 플러그인의 우선순위와 콘텐츠 선언 파일의 우선순위에 따라 달라지며(모두 구성 가능) 처리됩니다.
|
|
180
94
|
|
|
181
|
-
|
|
182
|
-
import { t } from "intlayer";
|
|
183
|
-
|
|
184
|
-
/** @type {import('intlayer').Dictionary} */
|
|
185
|
-
const content = {
|
|
186
|
-
key: "my-component",
|
|
187
|
-
content: {
|
|
188
|
-
helloWorld: t({
|
|
189
|
-
en: "Hello World",
|
|
190
|
-
es: "Hola Mundo",
|
|
191
|
-
fr: "Bonjour le monde",
|
|
192
|
-
}),
|
|
193
|
-
},
|
|
194
|
-
};
|
|
95
|
+
CLI를 사용하여 JSON을 번역하거나 CMS를 통해 변경 사항이 발생하면, Intlayer는 새로운 번역으로 JSON 파일을 업데이트합니다.
|
|
195
96
|
|
|
196
|
-
|
|
197
|
-
```
|
|
97
|
+
## Git 구성
|
|
198
98
|
|
|
199
|
-
|
|
200
|
-
const { t } = require("intlayer");
|
|
99
|
+
자동 생성된 Intlayer 파일은 무시하는 것이 권장됩니다:
|
|
201
100
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
helloWorld: t({
|
|
206
|
-
en: "Hello World",
|
|
207
|
-
es: "Hola Mundo",
|
|
208
|
-
fr: "Bonjour le monde",
|
|
209
|
-
}),
|
|
210
|
-
},
|
|
211
|
-
};
|
|
101
|
+
```plaintext fileName=".gitignore"
|
|
102
|
+
# Intlayer에서 생성된 파일 무시
|
|
103
|
+
.intlayer
|
|
212
104
|
```
|
|
213
105
|
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
217
|
-
"key": "my-component",
|
|
218
|
-
"content": {
|
|
219
|
-
"helloWorld": {
|
|
220
|
-
"nodeType": "translation",
|
|
221
|
-
"translation": {
|
|
222
|
-
"en": "Hello World",
|
|
223
|
-
"fr": "Bonjour le monde",
|
|
224
|
-
"es": "Hola Mundo"
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
106
|
+
이 파일들은 빌드 과정 중에 다시 생성될 수 있으므로 버전 관리에 커밋할 필요가 없습니다.
|
|
230
107
|
|
|
231
|
-
###
|
|
108
|
+
### VS Code 확장 프로그램
|
|
232
109
|
|
|
233
|
-
|
|
110
|
+
개발자 경험 향상을 위해 공식 **Intlayer VS Code 확장 프로그램**을 설치하세요:
|
|
234
111
|
|
|
235
|
-
|
|
236
|
-
npx intlayer dictionaries build
|
|
237
|
-
```
|
|
112
|
+
[VS Code 마켓플레이스에서 설치](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
238
113
|
|
|
239
|
-
|
|
240
|
-
yarn intlayer build
|
|
241
|
-
```
|
|
114
|
+
2. JSON과 콘텐츠 선언 파일 간에 충돌이 있는 경우, Intlayer는 모든 사전을 병합하여 처리합니다. 플러그인의 우선순위와 콘텐츠 선언 파일의 우선순위에 따라 달라집니다(모두 구성 가능합니다).
|
|
242
115
|
|
|
243
|
-
|
|
244
|
-
pnpm intlayer build
|
|
245
|
-
```
|
|
116
|
+
CLI를 사용하여 JSON 번역을 변경하거나 CMS를 사용하여 변경하면, Intlayer는 새로운 번역으로 JSON 파일을 업데이트합니다.
|
|
246
117
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```bash
|
|
250
|
-
.
|
|
251
|
-
└── intl
|
|
252
|
-
└── messages
|
|
253
|
-
└── ko
|
|
254
|
-
└── my-content.json
|
|
255
|
-
└── fr
|
|
256
|
-
└── my-content.json
|
|
257
|
-
└── es
|
|
258
|
-
└── my-content.json
|
|
259
|
-
```
|
|
118
|
+
## Git 구성
|
|
260
119
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### 다음.js 앱에서 next-intl 사용하기
|
|
264
|
-
|
|
265
|
-
> 더 자세한 내용은 공식 [next-intl 사용 문서](https://github.com/amannn/next-intl#readme)를 참조하세요.
|
|
266
|
-
|
|
267
|
-
1. **미들웨어 생성 (선택 사항):**
|
|
268
|
-
자동 언어 감지 또는 리디렉션을 관리하려면 next-intl의 [createMiddleware](https://github.com/amannn/next-intl#createMiddleware)를 사용하세요.
|
|
269
|
-
|
|
270
|
-
```typescript fileName="middleware.ts"
|
|
271
|
-
import createMiddleware from "next-intl/middleware";
|
|
272
|
-
import { NextResponse } from "next/server";
|
|
273
|
-
|
|
274
|
-
export default createMiddleware({
|
|
275
|
-
locales: ["en", "fr", "es"],
|
|
276
|
-
defaultLocale: "en",
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
export const config = {
|
|
280
|
-
matcher: ["/((?!api|_next|.*\\..*).*)"],
|
|
281
|
-
};
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
2. **메시지를 로드하기 위한 `layout.tsx` 또는 `_app.tsx` 생성:**
|
|
285
|
-
App Router(Next.js 13+)를 사용하는 경우 레이아웃을 생성하세요:
|
|
286
|
-
|
|
287
|
-
```typescript fileName="app/[locale]/layout.tsx"
|
|
288
|
-
import { NextIntlClientProvider } from 'next-intl';
|
|
289
|
-
import { notFound } from 'next/navigation';
|
|
290
|
-
import React, { ReactNode } from 'react';
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
export default async function RootLayout({
|
|
294
|
-
children,
|
|
295
|
-
params
|
|
296
|
-
}: {
|
|
297
|
-
children: ReactNode;
|
|
298
|
-
params: { locale: string };
|
|
299
|
-
}) {
|
|
300
|
-
let messages;
|
|
301
|
-
try {
|
|
302
|
-
messages = (await import(`../../intl/messages/${params.locale}.json`)).default;
|
|
303
|
-
} catch (error) {
|
|
304
|
-
notFound();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return (
|
|
308
|
-
<html lang={params.locale}>
|
|
309
|
-
<body>
|
|
310
|
-
<NextIntlClientProvider locale={params.locale} messages={messages}>
|
|
311
|
-
{children}
|
|
312
|
-
</NextIntlClientProvider>
|
|
313
|
-
</body>
|
|
314
|
-
</html>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
페이지 라우터(Next.js 12 이하)를 사용하는 경우 `_app.tsx`에서 메시지를 로드하세요:
|
|
320
|
-
|
|
321
|
-
```typescript fileName="pages/_app.tsx"
|
|
322
|
-
import type { AppProps } from 'next/app';
|
|
323
|
-
import { NextIntlProvider } from 'next-intl';
|
|
324
|
-
|
|
325
|
-
function MyApp({ Component, pageProps }: AppProps) {
|
|
326
|
-
return (
|
|
327
|
-
<NextIntlProvider locale={pageProps.locale} messages={pageProps.messages}>
|
|
328
|
-
<Component {...pageProps} />
|
|
329
|
-
</NextIntlProvider>
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export default MyApp;
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
3. **서버 측에서 메시지 가져오기 (페이지 라우터 예시):**
|
|
337
|
-
|
|
338
|
-
```typescript fileName="pages/index.tsx"
|
|
339
|
-
import { GetServerSideProps } from "next";
|
|
340
|
-
import HomePage from "../components/HomePage";
|
|
341
|
-
|
|
342
|
-
export default HomePage;
|
|
343
|
-
|
|
344
|
-
export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
|
|
345
|
-
const messages = (await import(`../intl/messages/${locale}.json`)).default;
|
|
346
|
-
|
|
347
|
-
return {
|
|
348
|
-
props: {
|
|
349
|
-
locale,
|
|
350
|
-
messages,
|
|
351
|
-
},
|
|
352
|
-
};
|
|
353
|
-
};
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Next.js 구성 요소에서 콘텐츠 사용하기
|
|
357
|
-
|
|
358
|
-
메시지가 next-intl에 로드된 후, `useTranslations()` 후크를 통해 구성 요소에서 사용할 수 있습니다:
|
|
359
|
-
|
|
360
|
-
```typescript fileName="src/components/MyComponent/index.tsx" codeFormat="typescript"
|
|
361
|
-
import type { FC } from "react";
|
|
362
|
-
import { useTranslations } from 'next-intl';
|
|
363
|
-
|
|
364
|
-
const MyComponent: FC = () => {
|
|
365
|
-
const t = useTranslations('my-component');
|
|
366
|
-
// 'my-component'는 Intlayer의 콘텐츠 키에 해당합니다.
|
|
367
|
-
|
|
368
|
-
return (
|
|
369
|
-
<div>
|
|
370
|
-
<h1>{t('helloWorld')}</h1>
|
|
371
|
-
</div>
|
|
372
|
-
);
|
|
373
|
-
};
|
|
120
|
+
자동 생성된 Intlayer 파일을 무시하는 것이 권장됩니다:
|
|
374
121
|
|
|
375
|
-
|
|
122
|
+
```plaintext fileName=".gitignore"
|
|
123
|
+
# Intlayer에서 생성된 파일 무시
|
|
124
|
+
.intlayer
|
|
376
125
|
```
|
|
377
126
|
|
|
378
|
-
|
|
379
|
-
import { useTranslations } from "next-intl";
|
|
127
|
+
이 파일들은 빌드 과정에서 다시 생성될 수 있으므로 버전 관리에 커밋할 필요가 없습니다.
|
|
380
128
|
|
|
381
|
-
|
|
382
|
-
const t = useTranslations("my-component");
|
|
129
|
+
### VS Code 확장 프로그램
|
|
383
130
|
|
|
384
|
-
|
|
385
|
-
<div>
|
|
386
|
-
<h1>{t("helloWorld")}</h1>
|
|
387
|
-
</div>
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
```
|
|
131
|
+
개발자 경험 향상을 위해 공식 **Intlayer VS Code 확장 프로그램**을 설치하세요:
|
|
391
132
|
|
|
392
|
-
|
|
133
|
+
[VS Code 마켓플레이스에서 설치하기](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|