@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,579 @@
1
+ ---
2
+ createdAt: 2025-11-20
3
+ updatedAt: 2025-12-30
4
+ title: Як перекласти свій додаток SvelteKit – керівництво з i18n 2026
5
+ description: Дізнайтеся, як зробити ваш вебсайт на SvelteKit багатомовним. Дотримуйтесь документації, щоб інтернаціоналізувати (i18n) та перекласти його з використанням Server-Side Rendering (SSR).
6
+ keywords:
7
+ - Інтернаціоналізація (i18n)
8
+ - Документація
9
+ - Intlayer
10
+ - SvelteKit
11
+ - JavaScript
12
+ - SSR
13
+ slugs:
14
+ - doc
15
+ - environment
16
+ - sveltekit
17
+ applicationTemplate: https://github.com/aymericzip/intlayer-sveltekit-template
18
+ history:
19
+ - version: 7.5.9
20
+ date: 2025-12-30
21
+ changes: Додано команду init
22
+ - version: 7.1.10
23
+ date: 2025-11-20
24
+ changes: Ініціалізація історії
25
+ ---
26
+
27
+ # Перекладіть свій сайт на SvelteKit із Intlayer | Інтернаціоналізація (i18n)
28
+
29
+ ## Зміст
30
+
31
+ <TOC/>
32
+
33
+ ## Що таке Intlayer?
34
+
35
+ **Intlayer** — інноваційна, відкрита бібліотека для інтернаціоналізації (i18n), створена для спрощення підтримки кількох мов у сучасних вебзастосунках. Вона безшовно працює з можливостями Server-Side Rendering (SSR) у **SvelteKit**.
36
+
37
+ За допомогою Intlayer ви можете:
38
+
39
+ - **Легко керувати перекладами**, використовуючи декларативні словники на рівні компонентів.
40
+ - **Динамічно локалізувати метадані**, маршрути та вміст.
41
+ - **Забезпечити підтримку TypeScript** за допомогою автогенерованих типів.
42
+ - **Використовувати SSR SvelteKit** для SEO‑дружньої інтернаціоналізації.
43
+
44
+ ---
45
+
46
+ ## Покроковий посібник із налаштування Intlayer у застосунку SvelteKit
47
+
48
+ <iframe
49
+ src="https://stackblitz.com/github/aymericzip/intlayer-sveltekit-template?embed=1&ctl=1&file=intlayer.config.ts"
50
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
51
+ title="Demo CodeSandbox - Як інтернаціоналізувати ваш застосунок за допомогою Intlayer"
52
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
53
+ loading="lazy"
54
+ />
55
+
56
+ Див. [Шаблон застосунку](https://github.com/aymericzip/intlayer-sveltekit-template) на GitHub.
57
+
58
+ Щоб почати, створіть новий проєкт SvelteKit. Ось кінцева структура, яку ми створимо:
59
+
60
+ ```bash
61
+ .
62
+ ├── intlayer.config.ts
63
+ ├── package.json
64
+ ├── src
65
+ │ ├── app.d.ts
66
+ │   ├── app.html
67
+ │   ├── hooks.server.ts
68
+ │   ├── lib
69
+ │   │   ├── getLocale.ts
70
+ │   │   ├── LocaleSwitcher.svelte
71
+ │   │   └── LocalizedLink.svelte
72
+ │   ├── params
73
+ │   │   └── locale.ts
74
+ │   └── routes
75
+ │   ├── [[locale=locale]]
76
+ │   │   ├── +layout.svelte
77
+ │   │   ├── +layout.ts
78
+ │   │   ├── +page.svelte
79
+ │   │   ├── +page.ts
80
+ │   │   ├── about
81
+ │   │   │   ├── +page.svelte
82
+ │   │   │   ├── +page.ts
83
+ │   │   │   └── page.content.ts
84
+ │   │   ├── Counter.content.ts
85
+ │   │   ├── Counter.svelte
86
+ │   │   ├── Header.content.ts
87
+ │   │   ├── Header.svelte
88
+ │   │   ├── home.content.ts
89
+ │   │   └── layout.content.ts
90
+ │   ├── +layout.svelte
91
+ │   └── layout.css
92
+ ├── static
93
+ │   ├── favicon.svg
94
+ │   └── robots.txt
95
+ ├── svelte.config.js
96
+ ├── tsconfig.json
97
+ └── vite.config.ts
98
+ ```
99
+
100
+ ### Крок 1: Встановлення залежностей
101
+
102
+ Встановіть необхідні пакети за допомогою npm:
103
+
104
+ ```bash packageManager="npm"
105
+ npm install intlayer svelte-intlayer
106
+ npm install vite-intlayer --save-dev
107
+ npx intlayer init
108
+ ```
109
+
110
+ ```bash packageManager="pnpm"
111
+ pnpm add intlayer svelte-intlayer
112
+ pnpm add vite-intlayer --save-dev
113
+ pnpm intlayer init
114
+ ```
115
+
116
+ ```bash packageManager="yarn"
117
+ yarn add intlayer svelte-intlayer
118
+ yarn add vite-intlayer --save-dev
119
+ yarn intlayer init
120
+ ```
121
+
122
+ ```bash packageManager="bun"
123
+ bun add intlayer svelte-intlayer
124
+ bun add vite-intlayer --save-dev
125
+ bunx intlayer init
126
+ ```
127
+
128
+ - **intlayer**: Основний пакет i18n.
129
+ - **svelte-intlayer**: Надає провайдери контексту та stores для Svelte/SvelteKit.
130
+ - **vite-intlayer**: Плагін Vite для інтеграції декларацій контенту в процес збірки.
131
+
132
+ ### Крок 2: Налаштування вашого проєкту
133
+
134
+ Створіть файл конфігурації в корені вашого проєкту:
135
+
136
+ ```typescript fileName="intlayer.config.ts"
137
+ import { Locales, type IntlayerConfig } from "intlayer";
138
+
139
+ const config: IntlayerConfig = {
140
+ internationalization: {
141
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
142
+ defaultLocale: Locales.ENGLISH,
143
+ },
144
+ };
145
+
146
+ export default config;
147
+ ```
148
+
149
+ ### Крок 3: Інтеграція Intlayer у вашу Vite конфігурацію
150
+
151
+ Оновіть ваш `vite.config.ts`, щоб додати плагін Intlayer. Цей плагін обробляє транспіляцію ваших файлів вмісту.
152
+
153
+ ```typescript fileName="vite.config.ts"
154
+ import { sveltekit } from "@sveltejs/kit/vite";
155
+ import { defineConfig } from "vite";
156
+ import { intlayer } from "vite-intlayer";
157
+
158
+ export default defineConfig({
159
+ plugins: [intlayer(), sveltekit()], // порядок важливий: Intlayer має стояти перед SvelteKit
160
+ });
161
+ ```
162
+
163
+ ### Крок 4: Оголосіть ваш вміст
164
+
165
+ Створюйте файли декларацій контенту в будь-якому місці вашої папки `src` (наприклад, `src/lib/content` або поруч із компонентами). Ці файли визначають перекладний контент для вашого застосунку, використовуючи функцію `t()` для кожної локалі.
166
+
167
+ ```ts fileName="src/features/hero/hero.content.ts" contentDeclarationFormat="typescript"
168
+ import { t, type Dictionary } from "intlayer";
169
+
170
+ const heroContent = {
171
+ key: "hero-section",
172
+ content: {
173
+ title: t({
174
+ uk: "Ласкаво просимо в SvelteKit",
175
+ en: "Welcome to SvelteKit",
176
+ fr: "Bienvenue sur SvelteKit",
177
+ es: "Bienvenido a SvelteKit",
178
+ }),
179
+ },
180
+ } satisfies Dictionary;
181
+
182
+ export default heroContent;
183
+ ```
184
+
185
+ ### Крок 5: Використання Intlayer у ваших компонентах
186
+
187
+ Тепер ви можете використовувати функцію `useIntlayer` у будь-якому Svelte-компоненті. Вона повертає реактивний store, який автоматично оновлюється при зміні локалі. Функція автоматично враховує поточну локаль (як під час SSR, так і під час навігації на боці клієнта).
188
+
189
+ > **Примітка:** `useIntlayer` повертає Svelte-store, тому потрібно використовувати префікс `$` для доступу до його реактивного значення (наприклад, `$content.title`).
190
+
191
+ ```svelte fileName="src/lib/components/Component.svelte"
192
+ <script lang="ts">
193
+ import { useIntlayer } from "svelte-intlayer";
194
+
195
+ // "hero-section" відповідає ключу, визначеному в кроці 4
196
+ const content = useIntlayer("hero-section");
197
+ </script>
198
+
199
+ <!-- Відобразити контент у простому вигляді -->
200
+ <h1>{$content.title}</h1>
201
+ <!-- Щоб зробити контент редагованим за допомогою редактора -->
202
+ <h1><svelte:component this={$content.title} /></h1>
203
+ <!-- Щоб відобразити вміст як рядок -->
204
+ <div aria-label={$content.title.value}></div>
205
+ ```
206
+
207
+ ### (Необов'язково) Крок 6: Налаштування маршрутизації
208
+
209
+ Нижче наведено кроки для налаштування маршрутизації на основі локалі в SvelteKit. Це дозволяє додавати префікс локалі до ваших URL (наприклад, `/en/about`, `/fr/about`) для кращого SEO та зручності користувача.
210
+
211
+ ```bash
212
+ .
213
+ └─── src
214
+ ├── app.d.ts # Визначте тип локалі
215
+ ├── hooks.server.ts # Керує маршрутизацією локалей
216
+ ├── lib
217
+ │   └── getLocale.ts # Перевіряє локаль у заголовках та cookie
218
+ ├── params
219
+ │   └── locale.ts # Визначає параметр локалі
220
+ └── routes
221
+ ├── [[locale=locale]] # Обгорнути в групу маршрутів для встановлення локалі
222
+ │   ├── +layout.svelte # Локальний layout для маршруту
223
+ │   ├── +layout.ts
224
+ │   ├── +page.svelte
225
+ │   ├── +page.ts
226
+ │   └── about
227
+ │      ├── +page.svelte
228
+ │      └── +page.ts
229
+ └── +layout.svelte # Root layout для шрифтів і глобальних стилів
230
+ ```
231
+
232
+ ### Крок 7: Обробка визначення локалі на сервері (Hooks)
233
+
234
+ У SvelteKit сервер повинен знати локаль користувача, щоб відрендерити правильний вміст під час SSR. Ми використовуємо `hooks.server.ts` для виявлення локалі з URL або cookies.
235
+
236
+ Створіть або змініть `src/hooks.server.ts`:
237
+
238
+ ```typescript fileName="src/hooks.server.ts"
239
+ import type { Handle } from "@sveltejs/kit";
240
+ import { getLocalizedUrl } from "intlayer";
241
+ import { getLocale } from "$lib/getLocale";
242
+
243
+ export const handle: Handle = async ({ event, resolve }) => {
244
+ const detectedLocale = getLocale(event);
245
+
246
+ // Перевіряємо, чи поточний шлях вже починається з локалі (наприклад, /fr, /en)
247
+ const pathname = event.url.pathname;
248
+ const targetPathname = getLocalizedUrl(pathname, detectedLocale);
249
+
250
+ // Якщо в URL немає локалі (наприклад, користувач відвідує "/"), перенаправляємо його
251
+ if (targetPathname !== pathname) {
252
+ return new Response(undefined, {
253
+ headers: { Location: targetPathname },
254
+ status: 307, // Тимчасове перенаправлення
255
+ });
256
+ }
257
+
258
+ return resolve(event, {
259
+ transformPageChunk: ({ html }) => html.replace("%lang%", detectedLocale),
260
+ });
261
+ };
262
+ ```
263
+
264
+ Потім створіть допоміжну функцію для отримання локалі користувача з події запиту:
265
+
266
+ ```typescript fileName="src/lib/getLocale.ts"
267
+ import {
268
+ configuration,
269
+ getLocaleFromStorage,
270
+ localeDetector,
271
+ type Locale,
272
+ } from "intlayer";
273
+ import type { RequestEvent } from "@sveltejs/kit";
274
+
275
+ /**
276
+ * Отримати локаль користувача з події запиту.
277
+ * Ця функція використовується в хуку `handle` у `src/hooks.server.ts`.
278
+ *
279
+ * Спочатку вона намагається отримати локаль із сховища Intlayer (кукі або користувацькі заголовки).
280
+ * Якщо локаль не знайдено, відбувається відкат до переговору браузера через заголовок `Accept-Language`.
281
+ *
282
+ * @param event - подія запиту від SvelteKit
283
+ * @returns локаль користувача
284
+ */
285
+ export const getLocale = (event: RequestEvent): Locale => {
286
+ const defaultLocale = configuration?.internationalization?.defaultLocale;
287
+
288
+ // Спроба отримати локаль зі сховища Intlayer (кукі або заголовки)
289
+ const storedLocale = getLocaleFromStorage({
290
+ // Доступ до cookie SvelteKit
291
+ getCookie: (name: string) => event.cookies.get(name) ?? null,
292
+ // Доступ до заголовків SvelteKit
293
+ getHeader: (name: string) => event.request.headers.get(name) ?? null,
294
+ });
295
+
296
+ if (storedLocale) {
297
+ return storedLocale;
298
+ }
299
+
300
+ // Відкат до погодження браузера по заголовку "Accept-Language"
301
+ const negotiatorHeaders: Record<string, string> = {};
302
+
303
+ // Перетворити об'єкт Headers SvelteKit у простий Record<string, string>
304
+ event.request.headers.forEach((value, key) => {
305
+ negotiatorHeaders[key] = value;
306
+ });
307
+
308
+ // Перевірити локаль із заголовка `Accept-Language`
309
+ const userFallbackLocale = localeDetector(negotiatorHeaders);
310
+
311
+ if (userFallbackLocale) {
312
+ return userFallbackLocale;
313
+ }
314
+
315
+ // Повернути локаль за замовчуванням, якщо відповідність не знайдено
316
+ return defaultLocale;
317
+ };
318
+ ```
319
+
320
+ > `getLocaleFromStorage` перевірятиме локаль у заголовку або cookie залежно від вашої конфігурації. Див. розділ [Configuration](https://intlayer.org/doc/configuration) для детальнішої інформації.
321
+
322
+ > Функція `localeDetector` обробляє заголовок `Accept-Language` і повертає найкраще співпадіння.
323
+
324
+ Якщо локаль не налаштована, ми хочемо повернути помилку 404. Щоб спростити це, ми можемо створити функцію `match`, яка перевіряє, чи є локаль валідною:
325
+
326
+ ```ts fileName="/src/params/locale.ts"
327
+ import { configuration, type Locale } from "intlayer";
328
+
329
+ export const match = (
330
+ param: Locale = configuration.internationalization.defaultLocale
331
+ ): boolean => {
332
+ return configuration.internationalization.locales.includes(param);
333
+ };
334
+ ```
335
+
336
+ > **Примітка:** Переконайтеся, що у вашому `src/app.d.ts` міститься визначення локалі:
337
+ >
338
+ > ```typescript
339
+ > declare global {
340
+ > namespace App {
341
+ > interface Locals {
342
+ > locale: import("intlayer").Locale;
343
+ > }
344
+ > }
345
+ > }
346
+ > ```
347
+
348
+ Для файлу `+layout.svelte` ми можемо видалити все, залишивши лише статичний вміст, не пов'язаний із i18n:
349
+
350
+ ```svelte fileName="src/+layout.svelte"
351
+ <script lang="ts">
352
+ import './layout.css';
353
+
354
+ let { children } = $props();
355
+ </script>
356
+
357
+ <div class="app">
358
+ {@render children()}
359
+ </div>
360
+
361
+ <style>
362
+ .app {
363
+ /* */
364
+ }
365
+ </style>
366
+ ```
367
+
368
+ Потім створіть нову сторінку та layout у групі `[[locale=locale]]`:
369
+
370
+ ```ts fileName="src/routes/[[locale=locale]]/+layout.ts"
371
+ import type { Load } from "@sveltejs/kit";
372
+ import { configuration, type Locale } from "intlayer";
373
+
374
+ export const prerender = true;
375
+
376
+ // Використовуйте загальний тип Load
377
+ export const load: Load = ({ params }) => {
378
+ const locale: Locale =
379
+ (params.locale as Locale) ??
380
+ configuration.internationalization.defaultLocale;
381
+
382
+ return {
383
+ locale,
384
+ };
385
+ };
386
+ ```
387
+
388
+ ```svelte fileName="src/routes/[[locale=locale]]/+layout.svelte"
389
+ <script lang="ts">
390
+ import type { Snippet } from 'svelte';
391
+ import { useIntlayer, setupIntlayer } from 'svelte-intlayer';
392
+ import Header from './Header.svelte';
393
+ import type { LayoutData } from './$types';
394
+
395
+ let { children, data }: { children: Snippet, data: LayoutData } = $props();
396
+
397
+ // Ініціалізує Intlayer з локаллю з маршруту
398
+ $effect(() => {
399
+ setupIntlayer(data.locale);
400
+ });
401
+ // Використовує словник вмісту layout
402
+ const layoutContent = useIntlayer('layout');
403
+ </script>
404
+
405
+ <Header />
406
+
407
+ <main>
408
+ {@render children()}
409
+ </main>
410
+
411
+ <footer>
412
+ <p>
413
+ {$layoutContent.footer.prefix.value}{' '}
414
+ <a href="https://svelte.dev/docs/kit">{$layoutContent.footer.linkLabel.value}</a>{' '}
415
+ {$layoutContent.footer.suffix.value}
416
+ </p>
417
+ </footer>
418
+
419
+ <style>
420
+ /* */
421
+ </style>
422
+ ```
423
+
424
+ ```ts fileName="src/routes/[[locale=locale]]/+page.ts"
425
+ export const prerender = true;
426
+ ```
427
+
428
+ ```svelte fileName="src/routes/[[locale=locale]]/+page.svelte"
429
+ <script lang="ts">
430
+ import { useIntlayer } from 'svelte-intlayer';
431
+
432
+ // Використовувати словник контенту для home
433
+ const homeContent = useIntlayer('home');
434
+ </script>
435
+
436
+ <svelte:head>
437
+ <title>{$homeContent.title.value}</title>
438
+ </svelte:head>
439
+
440
+ <section>
441
+ <h1>
442
+ {$homeContent.title}
443
+ </h1>
444
+ </section>
445
+
446
+ <style>
447
+ /* */
448
+ </style>
449
+ ```
450
+
451
+ ### (Необов'язково) Крок 8: Інтернаціоналізовані посилання
452
+
453
+ Для SEO рекомендується додавати префікс локалі до маршрутів (наприклад, `/en/about`, `/fr/about`). Цей компонент автоматично додає префікс поточної локалі до будь-якого посилання.
454
+
455
+ ```svelte fileName="src/lib/components/LocalizedLink.svelte"
456
+ <script lang="ts">
457
+ import { getLocalizedUrl } from "intlayer";
458
+ import { useLocale } from 'svelte-intlayer';
459
+
460
+ let { href = "" } = $props();
461
+ const { locale } = useLocale();
462
+
463
+ // Допоміжна функція для додавання префікса локалі до URL
464
+ $: localizedHref = getLocalizedUrl(href, $locale);
465
+ </script>
466
+
467
+ <a href={localizedHref}>
468
+ <slot />
469
+ </a>
470
+ ```
471
+
472
+ Якщо ви використовуєте `goto` з SvelteKit, ви можете застосувати ту саму логіку з `getLocalizedUrl`, щоб перейти на локалізований URL:
473
+
474
+ ```typescript
475
+ import { goto } from "$app/navigation";
476
+ import { getLocalizedUrl } from "intlayer";
477
+ import { useLocale } from "svelte-intlayer";
478
+
479
+ const { locale } = useLocale();
480
+ const localizedPath = getLocalizedUrl("/about", $locale);
481
+ goto(localizedPath); // Переходить на /en/about або /fr/about залежно від локалі
482
+ ```
483
+
484
+ ### (Необов'язково) Крок 9: Перемикач мови
485
+
486
+ Щоб дозволити користувачам переключати мову, оновіть URL.
487
+
488
+ ```svelte fileName="src/lib/components/LanguageSwitcher.svelte"
489
+ <script lang="ts">
490
+ import { getLocalizedUrl, getLocaleName } from 'intlayer';
491
+ import { useLocale } from 'svelte-intlayer';
492
+ import { page } from '$app/stores';
493
+ import { goto } from '$app/navigation';
494
+
495
+ const { locale, setLocale, availableLocales } = useLocale({
496
+ onLocaleChange: (newLocale) => {
497
+ const localizedPath = getLocalizedUrl($page.url.pathname, newLocale);
498
+ goto(localizedPath);
499
+ },
500
+ });
501
+ </script>
502
+
503
+ <ul class="locale-list">
504
+ {#each availableLocales as localeEl}
505
+ <li>
506
+ <a
507
+ href={getLocalizedUrl($page.url.pathname, localeEl)}
508
+ onclick={(e) => {
509
+ e.preventDefault();
510
+ setLocale(localeEl); // Встановить локаль у store та викличе onLocaleChange
511
+ }}
512
+ class:active={$locale === localeEl}
513
+ >
514
+ {getLocaleName(localeEl)}
515
+ </a>
516
+ </li>
517
+ {/each}
518
+ </ul>
519
+
520
+ <style>
521
+ /* */
522
+ </style>
523
+ ```
524
+
525
+ ### (Необов'язково) Крок 10: Додати backend proxy
526
+
527
+ Щоб додати backend proxy до вашого застосунку SvelteKit, ви можете використати функцію `intlayerProxy`, що надається плагіном `vite-intlayer`. Цей плагін автоматично визначатиме найкращу локаль для користувача на основі URL, cookies та мовних налаштувань браузера.
528
+
529
+ ```ts fileName="vite.config.ts"
530
+ import { defineConfig } from "vite";
531
+ import { intlayer, intlayerProxy } from "vite-intlayer";
532
+ import { sveltekit } from "@sveltejs/kit/vite";
533
+
534
+ // https://vitejs.dev/config/
535
+ export default defineConfig({
536
+ plugins: [intlayer(), intlayerProxy(), sveltekit()],
537
+ });
538
+ ```
539
+
540
+ ### (Необов'язково) Крок 11: Налаштування редактора intlayer / CMS
541
+
542
+ Щоб налаштувати редактор intlayer, дотримуйтесь [документації редактора intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_visual_editor.md).
543
+
544
+ Щоб налаштувати CMS intlayer, дотримуйтесь [документації CMS intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_CMS.md).
545
+
546
+ Щоб мати змогу візуалізувати селектор редактора intlayer, потрібно використовувати синтаксис компонента у вашому контенті intlayer.
547
+
548
+ ```svelte fileName="Component.svelte"
549
+ <script lang="ts">
550
+ import { useIntlayer } from "svelte-intlayer";
551
+
552
+ const content = useIntlayer("component");
553
+ </script>
554
+
555
+ <div>
556
+
557
+ <!-- Відобразити вміст як простий контент -->
558
+ <h1>{$content.title}</h1>
559
+
560
+ <!-- Відобразити вміст як компонент (вимагається редактором) -->
561
+ <svelte:component this={$content.component} />
562
+ </div>
563
+ ```
564
+
565
+ ### Налаштування Git
566
+
567
+ Рекомендується ігнорувати файли, згенеровані Intlayer.
568
+
569
+ ```plaintext fileName=".gitignore"
570
+ # Ігнорувати файли, згенеровані Intlayer
571
+ .intlayer
572
+ ```
573
+
574
+ ---
575
+
576
+ ### Далі
577
+
578
+ - **Visual Editor**: Інтегруйте [Intlayer Visual Editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_visual_editor.md), щоб редагувати переклади безпосередньо з UI.
579
+ - **CMS**: Виносьте керування вмістом назовні, використовуючи [Intlayer CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/uk/intlayer_CMS.md).