@intlayer/docs 7.5.12 → 7.5.13
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/uk/compiler_vs_declarative_i18n.md +224 -0
- package/blog/uk/i18n_using_next-i18next.md +1086 -0
- package/blog/uk/i18n_using_next-intl.md +760 -0
- package/blog/uk/index.md +69 -0
- package/blog/uk/internationalization_and_SEO.md +273 -0
- package/blog/uk/intlayer_with_i18next.md +211 -0
- package/blog/uk/intlayer_with_next-i18next.md +202 -0
- package/blog/uk/intlayer_with_next-intl.md +203 -0
- package/blog/uk/intlayer_with_react-i18next.md +200 -0
- package/blog/uk/intlayer_with_react-intl.md +202 -0
- package/blog/uk/intlayer_with_vue-i18n.md +206 -0
- package/blog/uk/l10n_platform_alternative/Lokalise.md +80 -0
- package/blog/uk/l10n_platform_alternative/crowdin.md +80 -0
- package/blog/uk/l10n_platform_alternative/phrase.md +78 -0
- package/blog/uk/list_i18n_technologies/CMS/drupal.md +143 -0
- package/blog/uk/list_i18n_technologies/CMS/wix.md +167 -0
- package/blog/uk/list_i18n_technologies/CMS/wordpress.md +189 -0
- package/blog/uk/list_i18n_technologies/frameworks/angular.md +125 -0
- package/blog/uk/list_i18n_technologies/frameworks/flutter.md +128 -0
- package/blog/uk/list_i18n_technologies/frameworks/react-native.md +217 -0
- package/blog/uk/list_i18n_technologies/frameworks/react.md +155 -0
- package/blog/uk/list_i18n_technologies/frameworks/svelte.md +145 -0
- package/blog/uk/list_i18n_technologies/frameworks/vue.md +144 -0
- package/blog/uk/next-i18next_vs_next-intl_vs_intlayer.md +1499 -0
- package/blog/uk/nextjs-multilingual-seo-comparison.md +360 -0
- package/blog/uk/rag_powered_documentation_assistant.md +288 -0
- package/blog/uk/react-i18next_vs_react-intl_vs_intlayer.md +164 -0
- package/blog/uk/vue-i18n_vs_intlayer.md +279 -0
- package/blog/uk/what_is_internationalization.md +167 -0
- package/dist/cjs/generated/frequentQuestions.entry.cjs +20 -0
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +20 -0
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/types/generated/frequentQuestions.entry.d.ts +1 -0
- package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/docs/ar/configuration.md +6 -1
- package/docs/ar/dictionary/content_file.md +6 -1
- package/docs/de/configuration.md +6 -1
- package/docs/de/dictionary/content_file.md +6 -1
- package/docs/en/configuration.md +6 -1
- package/docs/en/dictionary/content_file.md +6 -1
- package/docs/en-GB/configuration.md +6 -1
- package/docs/en-GB/dictionary/content_file.md +3 -1
- package/docs/es/configuration.md +6 -1
- package/docs/es/dictionary/content_file.md +6 -1
- package/docs/fr/configuration.md +6 -1
- package/docs/fr/dictionary/content_file.md +3 -1
- package/docs/hi/configuration.md +6 -1
- package/docs/hi/dictionary/content_file.md +3 -1
- package/docs/id/configuration.md +6 -1
- package/docs/id/dictionary/content_file.md +3 -1
- package/docs/it/configuration.md +6 -1
- package/docs/it/dictionary/content_file.md +3 -1
- package/docs/ja/configuration.md +6 -1
- package/docs/ja/dictionary/content_file.md +3 -1
- package/docs/ko/configuration.md +6 -1
- package/docs/ko/dictionary/content_file.md +3 -1
- package/docs/pl/configuration.md +3 -1
- package/docs/pl/dictionary/content_file.md +3 -1
- package/docs/pt/configuration.md +6 -1
- package/docs/pt/dictionary/content_file.md +3 -1
- package/docs/ru/configuration.md +6 -1
- package/docs/ru/dictionary/content_file.md +6 -1
- package/docs/tr/configuration.md +6 -1
- package/docs/tr/dictionary/content_file.md +3 -1
- package/docs/uk/CI_CD.md +198 -0
- package/docs/uk/autoFill.md +307 -0
- package/docs/uk/bundle_optimization.md +185 -0
- package/docs/uk/cli/build.md +64 -0
- package/docs/uk/cli/ci.md +137 -0
- package/docs/uk/cli/configuration.md +63 -0
- package/docs/uk/cli/debug.md +46 -0
- package/docs/uk/cli/doc-review.md +43 -0
- package/docs/uk/cli/doc-translate.md +132 -0
- package/docs/uk/cli/editor.md +28 -0
- package/docs/uk/cli/fill.md +130 -0
- package/docs/uk/cli/index.md +190 -0
- package/docs/uk/cli/init.md +84 -0
- package/docs/uk/cli/list.md +90 -0
- package/docs/uk/cli/list_projects.md +128 -0
- package/docs/uk/cli/live.md +41 -0
- package/docs/uk/cli/login.md +157 -0
- package/docs/uk/cli/pull.md +78 -0
- package/docs/uk/cli/push.md +98 -0
- package/docs/uk/cli/sdk.md +71 -0
- package/docs/uk/cli/test.md +76 -0
- package/docs/uk/cli/transform.md +65 -0
- package/docs/uk/cli/version.md +24 -0
- package/docs/uk/cli/watch.md +37 -0
- package/docs/uk/configuration.md +742 -0
- package/docs/uk/dictionary/condition.md +237 -0
- package/docs/uk/dictionary/content_file.md +1134 -0
- package/docs/uk/dictionary/enumeration.md +245 -0
- package/docs/uk/dictionary/file.md +232 -0
- package/docs/uk/dictionary/function_fetching.md +212 -0
- package/docs/uk/dictionary/gender.md +273 -0
- package/docs/uk/dictionary/insertion.md +187 -0
- package/docs/uk/dictionary/markdown.md +383 -0
- package/docs/uk/dictionary/nesting.md +273 -0
- package/docs/uk/dictionary/translation.md +332 -0
- package/docs/uk/formatters.md +595 -0
- package/docs/uk/how_works_intlayer.md +256 -0
- package/docs/uk/index.md +175 -0
- package/docs/uk/interest_of_intlayer.md +297 -0
- package/docs/uk/intlayer_CMS.md +569 -0
- package/docs/uk/intlayer_visual_editor.md +292 -0
- package/docs/uk/intlayer_with_angular.md +710 -0
- package/docs/uk/intlayer_with_astro.md +256 -0
- package/docs/uk/intlayer_with_create_react_app.md +1258 -0
- package/docs/uk/intlayer_with_express.md +429 -0
- package/docs/uk/intlayer_with_fastify.md +446 -0
- package/docs/uk/intlayer_with_lynx+react.md +548 -0
- package/docs/uk/intlayer_with_nestjs.md +283 -0
- package/docs/uk/intlayer_with_next-i18next.md +640 -0
- package/docs/uk/intlayer_with_next-intl.md +456 -0
- package/docs/uk/intlayer_with_nextjs_page_router.md +1541 -0
- package/docs/uk/intlayer_with_nuxt.md +711 -0
- package/docs/uk/intlayer_with_react_router_v7.md +600 -0
- package/docs/uk/intlayer_with_react_router_v7_fs_routes.md +669 -0
- package/docs/uk/intlayer_with_svelte_kit.md +579 -0
- package/docs/uk/intlayer_with_tanstack.md +818 -0
- package/docs/uk/intlayer_with_vite+preact.md +1748 -0
- package/docs/uk/intlayer_with_vite+react.md +1449 -0
- package/docs/uk/intlayer_with_vite+solid.md +302 -0
- package/docs/uk/intlayer_with_vite+svelte.md +520 -0
- package/docs/uk/intlayer_with_vite+vue.md +1113 -0
- package/docs/uk/introduction.md +222 -0
- package/docs/uk/locale_mapper.md +242 -0
- package/docs/uk/mcp_server.md +211 -0
- package/docs/uk/packages/express-intlayer/t.md +465 -0
- package/docs/uk/packages/intlayer/getEnumeration.md +159 -0
- package/docs/uk/packages/intlayer/getHTMLTextDir.md +121 -0
- package/docs/uk/packages/intlayer/getLocaleLang.md +81 -0
- package/docs/uk/packages/intlayer/getLocaleName.md +135 -0
- package/docs/uk/packages/intlayer/getLocalizedUrl.md +338 -0
- package/docs/uk/packages/intlayer/getMultilingualUrls.md +359 -0
- package/docs/uk/packages/intlayer/getPathWithoutLocale.md +75 -0
- package/docs/uk/packages/intlayer/getPrefix.md +213 -0
- package/docs/uk/packages/intlayer/getTranslation.md +190 -0
- package/docs/uk/packages/intlayer/getTranslationContent.md +189 -0
- package/docs/uk/packages/next-intlayer/t.md +365 -0
- package/docs/uk/packages/next-intlayer/useDictionary.md +276 -0
- package/docs/uk/packages/next-intlayer/useIntlayer.md +263 -0
- package/docs/uk/packages/next-intlayer/useLocale.md +166 -0
- package/docs/uk/packages/react-intlayer/t.md +311 -0
- package/docs/uk/packages/react-intlayer/useDictionary.md +295 -0
- package/docs/uk/packages/react-intlayer/useI18n.md +250 -0
- package/docs/uk/packages/react-intlayer/useIntlayer.md +251 -0
- package/docs/uk/packages/react-intlayer/useLocale.md +210 -0
- package/docs/uk/per_locale_file.md +345 -0
- package/docs/uk/plugins/sync-json.md +398 -0
- package/docs/uk/readme.md +265 -0
- package/docs/uk/releases/v6.md +305 -0
- package/docs/uk/releases/v7.md +624 -0
- package/docs/uk/roadmap.md +346 -0
- package/docs/uk/testing.md +204 -0
- package/docs/vi/configuration.md +6 -1
- package/docs/vi/dictionary/content_file.md +6 -1
- package/docs/zh/configuration.md +6 -1
- package/docs/zh/dictionary/content_file.md +6 -1
- package/frequent_questions/ar/error-vite-env-only.md +77 -0
- package/frequent_questions/de/error-vite-env-only.md +77 -0
- package/frequent_questions/en/error-vite-env-only.md +77 -0
- package/frequent_questions/en-GB/error-vite-env-only.md +77 -0
- package/frequent_questions/es/error-vite-env-only.md +76 -0
- package/frequent_questions/fr/error-vite-env-only.md +77 -0
- package/frequent_questions/hi/error-vite-env-only.md +77 -0
- package/frequent_questions/id/error-vite-env-only.md +77 -0
- package/frequent_questions/it/error-vite-env-only.md +77 -0
- package/frequent_questions/ja/error-vite-env-only.md +77 -0
- package/frequent_questions/ko/error-vite-env-only.md +77 -0
- package/frequent_questions/pl/error-vite-env-only.md +77 -0
- package/frequent_questions/pt/error-vite-env-only.md +77 -0
- package/frequent_questions/ru/error-vite-env-only.md +77 -0
- package/frequent_questions/tr/error-vite-env-only.md +77 -0
- package/frequent_questions/uk/SSR_Next_no_[locale].md +104 -0
- package/frequent_questions/uk/array_as_content_declaration.md +72 -0
- package/frequent_questions/uk/build_dictionaries.md +58 -0
- package/frequent_questions/uk/build_error_CI_CD.md +74 -0
- package/frequent_questions/uk/bun_set_up.md +53 -0
- package/frequent_questions/uk/customized_locale_list.md +64 -0
- package/frequent_questions/uk/domain_routing.md +113 -0
- package/frequent_questions/uk/error-vite-env-only.md +77 -0
- package/frequent_questions/uk/esbuild_error.md +29 -0
- package/frequent_questions/uk/get_locale_cookie.md +142 -0
- package/frequent_questions/uk/intlayer_command_undefined.md +155 -0
- package/frequent_questions/uk/locale_incorect_in_url.md +73 -0
- package/frequent_questions/uk/package_version_error.md +181 -0
- package/frequent_questions/uk/static_rendering.md +44 -0
- package/frequent_questions/uk/translated_path_url.md +55 -0
- package/frequent_questions/uk/unknown_command.md +97 -0
- package/frequent_questions/vi/error-vite-env-only.md +77 -0
- package/frequent_questions/zh/error-vite-env-only.md +77 -0
- package/legal/uk/privacy_notice.md +83 -0
- package/legal/uk/terms_of_service.md +55 -0
- package/package.json +6 -6
- package/src/generated/frequentQuestions.entry.ts +20 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-08-23
|
|
3
|
+
updatedAt: 2025-08-23
|
|
4
|
+
title: Документація хуку useI18n | react-intlayer
|
|
5
|
+
description: Дізнайтесь, як використовувати хук useI18n у пакеті react-intlayer
|
|
6
|
+
keywords:
|
|
7
|
+
- useI18n
|
|
8
|
+
- i18n
|
|
9
|
+
- переклад
|
|
10
|
+
- словник
|
|
11
|
+
- Intlayer
|
|
12
|
+
- інтернаціоналізація
|
|
13
|
+
- документація
|
|
14
|
+
- Next.js
|
|
15
|
+
- JavaScript
|
|
16
|
+
- React
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- packages
|
|
20
|
+
- react-intlayer
|
|
21
|
+
- useI18n
|
|
22
|
+
history:
|
|
23
|
+
- version: 6.0.0
|
|
24
|
+
date: 2025-06-29
|
|
25
|
+
changes: Початкове написання документації для хука `useI18n`
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Інтеграція з React: Документація хуку `useI18n`
|
|
29
|
+
|
|
30
|
+
Цей розділ містить детальні вказівки щодо використання хука `useI18n` у React-застосунках для ефективної локалізації контенту.
|
|
31
|
+
|
|
32
|
+
## Імпорт `useI18n` у React
|
|
33
|
+
|
|
34
|
+
Хук `useI18n` можна імпортувати та інтегрувати в React-застосунки залежно від контексту наступним чином:
|
|
35
|
+
|
|
36
|
+
- **Клієнтські компоненти:**
|
|
37
|
+
|
|
38
|
+
```typescript codeFormat="typescript"
|
|
39
|
+
import { useI18n } from "react-intlayer"; // Використовується в клієнтських React-компонентах
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```javascript codeFormat="esm"
|
|
43
|
+
import { useI18n } from "react-intlayer"; // Використовується в клієнтських React-компонентах
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```javascript codeFormat="commonjs"
|
|
47
|
+
const { useI18n } = require("react-intlayer"); // Використовується в клієнтських React-компонентах
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Серверні компоненти:**
|
|
51
|
+
|
|
52
|
+
```typescript codeFormat="commonjs"
|
|
53
|
+
import { useI18n } from "react-intlayer/server"; // Використовується в серверних React-компонентах
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```javascript codeFormat="esm"
|
|
57
|
+
import { useI18n } from "react-intlayer/server"; // Використовується у серверних React-компонентах
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```javascript codeFormat="commonjs"
|
|
61
|
+
const { useI18n } = require("react-intlayer/server"); // Використовується у серверних React-компонентах
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Параметри
|
|
65
|
+
|
|
66
|
+
Цей хук приймає два параметри:
|
|
67
|
+
|
|
68
|
+
1. **`namespace`**: Простір імен словника для обмеження області ключів перекладу.
|
|
69
|
+
2. **`locale`** (необов'язково): Бажана локаль. Якщо не вказано, за замовчуванням буде використано локаль з контексту.
|
|
70
|
+
|
|
71
|
+
## Словник
|
|
72
|
+
|
|
73
|
+
Усі ключі словника повинні бути оголошені у файлах декларації вмісту, щоб підвищити типобезпеку та запобігти помилкам. [Інструкції з конфігурації можна знайти тут](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/dictionary/content_file.md).
|
|
74
|
+
|
|
75
|
+
## Приклади використання в React
|
|
76
|
+
|
|
77
|
+
Приклади використання хуку `useI18n` у React-компонентах:
|
|
78
|
+
|
|
79
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
80
|
+
import type { FC } from "react";
|
|
81
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
82
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
83
|
+
import { useI18n, IntlayerServerProvider } from "react-intlayer/server";
|
|
84
|
+
import { Locales } from "intlayer";
|
|
85
|
+
|
|
86
|
+
const App: FC<{ locale: Locales }> = ({ locale }) => {
|
|
87
|
+
const t = useI18n("home-page", locale);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<p>{t("introduction")}</p>
|
|
92
|
+
<IntlayerProvider locale={locale}>
|
|
93
|
+
<ClientComponentExample />
|
|
94
|
+
</IntlayerProvider>
|
|
95
|
+
<IntlayerServerProvider locale={locale}>
|
|
96
|
+
<ServerComponentExample />
|
|
97
|
+
</IntlayerServerProvider>
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```jsx fileName="src/app.jsx" codeFormat="esm"
|
|
104
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
105
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
106
|
+
import { IntlayerServerProvider, useI18n } from "react-intlayer/server";
|
|
107
|
+
|
|
108
|
+
const App = ({ locale }) => {
|
|
109
|
+
const t = useI18n("home-page", locale);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<p>{t("introduction")}</p>
|
|
114
|
+
<IntlayerProvider locale={locale}>
|
|
115
|
+
<ClientComponentExample />
|
|
116
|
+
</IntlayerProvider>
|
|
117
|
+
<IntlayerServerProvider locale={locale}>
|
|
118
|
+
<ServerComponentExample />
|
|
119
|
+
</IntlayerServerProvider>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```jsx fileName="src/app.cjs" codeFormat="commonjs"
|
|
126
|
+
const { IntlayerProvider } = require("react-intlayer");
|
|
127
|
+
const { IntlayerServerProvider, useI18n } = require("react-intlayer/server");
|
|
128
|
+
|
|
129
|
+
const App = ({ locale }) => {
|
|
130
|
+
const t = useI18n("home-page", locale);
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<p>{t("introduction")}</p>
|
|
135
|
+
<IntlayerProvider locale={locale}>
|
|
136
|
+
<ClientComponentExample />
|
|
137
|
+
</IntlayerProvider>
|
|
138
|
+
<IntlayerServerProvider locale={locale}>
|
|
139
|
+
<ServerComponentExample />
|
|
140
|
+
</IntlayerServerProvider>
|
|
141
|
+
</>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript"
|
|
147
|
+
import type { FC } from "react";
|
|
148
|
+
import { useI18n } from "react-intlayer";
|
|
149
|
+
|
|
150
|
+
const ComponentExample: FC = () => {
|
|
151
|
+
const t = useI18n("component-example");
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div>
|
|
155
|
+
<h1>{t("title")}</h1> {/* Відобразити заголовок */}
|
|
156
|
+
<p>{t("description")}</p> {/* Відобразити опис */}
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```jsx fileName="src/components/ComponentExample.jsx" codeFormat="esm"
|
|
163
|
+
import { useI18n } from "react-intlayer";
|
|
164
|
+
|
|
165
|
+
const ComponentExample = () => {
|
|
166
|
+
const t = useI18n("component-example");
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div>
|
|
170
|
+
<h1>{t("title")}</h1> {/* Відобразити заголовок */}
|
|
171
|
+
<p>{t("description")}</p> {/* Відобразити опис */}
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```jsx fileName="src/components/ComponentExample.cjs" codeFormat="commonjs"
|
|
178
|
+
const { useI18n } = require("react-intlayer");
|
|
179
|
+
|
|
180
|
+
const ComponentExample = () => {
|
|
181
|
+
const t = useI18n("component-example");
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div>
|
|
185
|
+
<h1>{t("title")}</h1> {/* Відобразити заголовок */}
|
|
186
|
+
<p>{t("description")}</p> {/* Відобразити опис */}
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript"
|
|
193
|
+
import { useI18n } from "react-intlayer/server";
|
|
194
|
+
|
|
195
|
+
const ServerComponentExample = () => {
|
|
196
|
+
const t = useI18n("server-component");
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div>
|
|
200
|
+
<h1>{t("title")}</h1> {/* Відображає заголовок */}
|
|
201
|
+
<p>{t("description")}</p> {/* Відображає опис */}
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
```jsx fileName="src/components/ServerComponentExample.jsx" codeFormat="esm"
|
|
208
|
+
import { useI18n } from "react-intlayer/server";
|
|
209
|
+
|
|
210
|
+
const ServerComponentExample = () => {
|
|
211
|
+
const t = useI18n("server-component");
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div>
|
|
215
|
+
<h1>{t("title")}</h1> {/* Відображає заголовок */}
|
|
216
|
+
<p>{t("description")}</p> {/* Відображає опис */}
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```jsx fileName="src/components/ServerComponentExample.cjs" codeFormat="commonjs"
|
|
223
|
+
const { useI18n } = require("react-intlayer/server");
|
|
224
|
+
|
|
225
|
+
const ServerComponentExample = () => {
|
|
226
|
+
const t = useI18n("server-component");
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<div>
|
|
230
|
+
<h1>{t("title")}</h1>
|
|
231
|
+
<p>{t("description")}</p>
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Обробка атрибутів
|
|
238
|
+
|
|
239
|
+
При локалізації атрибутів правильно звертайтеся до значень перекладу:
|
|
240
|
+
|
|
241
|
+
```jsx
|
|
242
|
+
<!-- Для атрибутів доступності (наприклад, aria-label) використовуйте .value, оскільки потрібні чисті рядки -->
|
|
243
|
+
<button aria-label={t("button.ariaLabel").value}>{t("button.text")}</button>
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Додаткові ресурси
|
|
247
|
+
|
|
248
|
+
- **Intlayer Visual Editor**: Для більш інтуїтивного керування контентом зверніться до документації візуального редактора [тут](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_visual_editor.md).
|
|
249
|
+
|
|
250
|
+
У цьому розділі докладно розглядається інтеграція хука `useI18n` у React-застосунки, що спрощує процес локалізації та забезпечує узгодженість контенту між різними локалями.
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-08-23
|
|
3
|
+
updatedAt: 2025-08-23
|
|
4
|
+
title: Документація хуку useIntlayer | react-intlayer
|
|
5
|
+
description: Дізнайтеся, як використовувати хук useIntlayer у пакеті react-intlayer
|
|
6
|
+
keywords:
|
|
7
|
+
- useIntlayer
|
|
8
|
+
- dictionary
|
|
9
|
+
- key
|
|
10
|
+
- Intlayer
|
|
11
|
+
- Internationalization
|
|
12
|
+
- Documentation
|
|
13
|
+
- Next.js
|
|
14
|
+
- JavaScript
|
|
15
|
+
- React
|
|
16
|
+
slugs:
|
|
17
|
+
- doc
|
|
18
|
+
- packages
|
|
19
|
+
- react-intlayer
|
|
20
|
+
- useIntlayer
|
|
21
|
+
history:
|
|
22
|
+
- version: 5.5.10
|
|
23
|
+
date: 2025-06-29
|
|
24
|
+
changes: Init history
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Інтеграція з React: документація хуку `useIntlayer`
|
|
28
|
+
|
|
29
|
+
У цьому розділі наведено докладні вказівки щодо використання хука `useIntlayer` у React-застосунках, що дозволяє ефективно локалізувати вміст.
|
|
30
|
+
|
|
31
|
+
## Імпорт хуку `useIntlayer` у React
|
|
32
|
+
|
|
33
|
+
Хук `useIntlayer` можна інтегрувати в React-застосунки, імпортуючи його залежно від контексту:
|
|
34
|
+
|
|
35
|
+
- **Клієнтський компонент:**
|
|
36
|
+
|
|
37
|
+
```typescript codeFormat="typescript"
|
|
38
|
+
import { useIntlayer } from "react-intlayer"; // Використовується в клієнтських React компонентах
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```javascript codeFormat="esm"
|
|
42
|
+
import { useIntlayer } from "react-intlayer"; // Використовується в клієнтських React компонентах
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```javascript codeFormat="commonjs"
|
|
46
|
+
const { useIntlayer } = require("react-intlayer"); // Використовується в клієнтських React компонентах
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **Серверний компонент:**
|
|
50
|
+
|
|
51
|
+
```typescript codeFormat="commonjs"
|
|
52
|
+
import { useIntlayer } from "react-intlayer/server"; // Використовується в серверних React компонентах
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```javascript codeFormat="esm"
|
|
56
|
+
import { useIntlayer } from "react-intlayer/server"; // Використовується в серверних React-компонентах
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```javascript codeFormat="commonjs"
|
|
60
|
+
const { useIntlayer } = require("react-intlayer/server"); // Використовується в серверних React-компонентах
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Параметри
|
|
64
|
+
|
|
65
|
+
Хук приймає два параметри:
|
|
66
|
+
|
|
67
|
+
1. **`key`**: Ключ словника для отримання локалізованого вмісту.
|
|
68
|
+
2. **`locale`** (необов'язковий): Бажана локаль. За замовчуванням використовується локаль контексту, якщо не вказано.
|
|
69
|
+
|
|
70
|
+
## Словник
|
|
71
|
+
|
|
72
|
+
Усі ключі словника повинні бути оголошені у файлах декларації контенту, щоб підвищити безпеку типів і уникнути помилок. Інструкцію з налаштування можна знайти [тут](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/dictionary/content_file.md).
|
|
73
|
+
|
|
74
|
+
## Приклад використання в React
|
|
75
|
+
|
|
76
|
+
Приклад використання хука `useIntlayer` у React-компоненті:
|
|
77
|
+
|
|
78
|
+
```tsx fileName="src/app.tsx" codeFormat="typescript"
|
|
79
|
+
import type { FC } from "react";
|
|
80
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
81
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
82
|
+
import { useIntlayer, IntlayerServerProvider } from "react-intlayer/server";
|
|
83
|
+
import { Locales } from "intlayer";
|
|
84
|
+
|
|
85
|
+
const App: FC<{ locale: Locales }> = ({ locale }) => {
|
|
86
|
+
const content = useIntlayer("homepage", locale);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<p>{content.introduction}</p>
|
|
91
|
+
<IntlayerProvider locale={locale}>
|
|
92
|
+
<ClientComponentExample />
|
|
93
|
+
</IntlayerProvider>
|
|
94
|
+
<IntlayerServerProvider locale={locale}>
|
|
95
|
+
<ServerComponentExample />
|
|
96
|
+
</IntlayerServerProvider>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```jsx fileName="src/app.mjx" codeFormat="esm"
|
|
103
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
104
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
105
|
+
import { IntlayerServerProvider, useIntlayer } from "react-intlayer/server";
|
|
106
|
+
|
|
107
|
+
const App = ({ locale }) => {
|
|
108
|
+
const content = useIntlayer("homepage", locale);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<p>{content.introduction}</p>
|
|
113
|
+
<IntlayerProvider locale={locale}>
|
|
114
|
+
<ClientComponentExample />
|
|
115
|
+
</IntlayerProvider>
|
|
116
|
+
<IntlayerServerProvider locale={locale}>
|
|
117
|
+
<ServerComponentExample />
|
|
118
|
+
</IntlayerServerProvider>
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```jsx fileName="src/app.csx" codeFormat="commonjs"
|
|
125
|
+
const { IntlayerProvider } = require("react-intlayer");
|
|
126
|
+
const {
|
|
127
|
+
IntlayerServerProvider,
|
|
128
|
+
useIntlayer,
|
|
129
|
+
} = require("react-intlayer/server");
|
|
130
|
+
|
|
131
|
+
const App = ({ locale }) => {
|
|
132
|
+
const content = useIntlayer("homepage", locale);
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<>
|
|
136
|
+
<p>{content.introduction}</p>
|
|
137
|
+
<IntlayerProvider locale={locale}>
|
|
138
|
+
<ClientComponentExample />
|
|
139
|
+
</IntlayerProvider>
|
|
140
|
+
<IntlayerServerProvider locale={locale}>
|
|
141
|
+
<ServerComponentExample />
|
|
142
|
+
</IntlayerServerProvider>
|
|
143
|
+
</>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript"
|
|
149
|
+
import type { FC } from "react";
|
|
150
|
+
import { useIntlayer } from "react-intlayer";
|
|
151
|
+
|
|
152
|
+
const ComponentExample: FC = () => {
|
|
153
|
+
const content = useIntlayer("component-example");
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<h1>{content.title}</h1>
|
|
158
|
+
<p>{content.description}</p>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```jsx fileName="src/components/ComponentExample.mjx" codeFormat="esm"
|
|
165
|
+
import { useIntlayer } from "react-intlayer";
|
|
166
|
+
|
|
167
|
+
const ComponentExample = () => {
|
|
168
|
+
const content = useIntlayer("component-example");
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div>
|
|
172
|
+
<h1>{content.title}</h1>
|
|
173
|
+
<p>{content.description}</p>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
```jsx fileName="src/components/ComponentExample.csx" codeFormat="commonjs"
|
|
180
|
+
const { useIntlayer } = require("react-intlayer");
|
|
181
|
+
|
|
182
|
+
const ComponentExample = () => {
|
|
183
|
+
const content = useIntlayer("component-example");
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div>
|
|
187
|
+
<h1>{content.title}</h1>
|
|
188
|
+
<p>{content.description}</p>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript"
|
|
195
|
+
import { useIntlayer } from "react-intlayer/server";
|
|
196
|
+
|
|
197
|
+
const ServerComponentExample = () => {
|
|
198
|
+
const content = useIntlayer("server-component");
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<div>
|
|
202
|
+
<h1>{content.title}</h1>
|
|
203
|
+
<p>{content.description}</p>
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```jsx fileName="src/components/ServerComponentExample.mjx" codeFormat="esm"
|
|
210
|
+
import { useIntlayer } from "react-intlayer/server";
|
|
211
|
+
|
|
212
|
+
const ServerComponentExample = () => {
|
|
213
|
+
const content = useIntlayer("server-component");
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<div>
|
|
217
|
+
<h1>{content.title}</h1>
|
|
218
|
+
<p>{content.description}</p>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```jsx fileName="src/components/ServerComponentExample.csx" codeFormat="commonjs"
|
|
225
|
+
const { useIntlayer } = require("react-intlayer/server");
|
|
226
|
+
|
|
227
|
+
const ServerComponentExample = () => {
|
|
228
|
+
const content = useIntlayer("server-component");
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<div>
|
|
232
|
+
<h1>{content.title}</h1>
|
|
233
|
+
<p>{content.description}</p>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Обробка атрибутів
|
|
240
|
+
|
|
241
|
+
При локалізації атрибутів звертайтеся до значень контенту відповідним чином:
|
|
242
|
+
|
|
243
|
+
```jsx
|
|
244
|
+
<button title={content.buttonTitle.value}>{content.buttonText}</button>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Додаткові ресурси
|
|
248
|
+
|
|
249
|
+
- **Intlayer Visual Editor**: Для інтуїтивнішого управління контентом зверніться до документації візуального редактора [тут](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_visual_editor.md).
|
|
250
|
+
|
|
251
|
+
Цей розділ спеціально присвячений інтеграції хука `useIntlayer` у React-застосунках, що спрощує процес локалізації та забезпечує узгодженість контенту між різними локалями.
|