@intlayer/docs 7.5.12 → 7.5.14

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