@intlayer/docs 8.6.1 → 8.6.10
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/dist/cjs/doc.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +60 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/doc.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +60 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/doc.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +3 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/cli/index.md +54 -42
- package/docs/ar/cli/init.md +32 -20
- package/docs/ar/cli/standalone.md +91 -0
- package/docs/ar/configuration.md +39 -7
- package/docs/ar/custom_domains.md +250 -0
- package/docs/ar/intlayer_with_tanstack+solid.md +14 -33
- package/docs/ar/intlayer_with_tanstack.md +25 -16
- package/docs/ar/intlayer_with_vanilla.md +506 -0
- package/docs/bn/cli/index.md +195 -0
- package/docs/bn/cli/init.md +96 -0
- package/docs/bn/cli/standalone.md +91 -0
- package/docs/bn/configuration.md +46 -14
- package/docs/bn/custom_domains.md +250 -0
- package/docs/bn/intlayer_with_vanilla.md +506 -0
- package/docs/cs/cli/index.md +195 -0
- package/docs/cs/cli/init.md +96 -0
- package/docs/cs/cli/standalone.md +91 -0
- package/docs/cs/configuration.md +46 -7
- package/docs/cs/custom_domains.md +250 -0
- package/docs/cs/intlayer_with_vanilla.md +506 -0
- package/docs/de/cli/index.md +53 -41
- package/docs/de/cli/standalone.md +91 -0
- package/docs/de/configuration.md +46 -7
- package/docs/de/custom_domains.md +250 -0
- package/docs/de/intlayer_with_tanstack+solid.md +14 -33
- package/docs/de/intlayer_with_tanstack.md +25 -16
- package/docs/de/intlayer_with_vanilla.md +506 -0
- package/docs/en/bundle_optimization.md +288 -23
- package/docs/en/cli/index.md +6 -1
- package/docs/en/cli/init.md +13 -1
- package/docs/en/cli/standalone.md +91 -0
- package/docs/en/configuration.md +46 -7
- package/docs/en/custom_domains.md +245 -0
- package/docs/en/intlayer_with_tanstack+solid.md +14 -33
- package/docs/en/intlayer_with_tanstack.md +25 -16
- package/docs/en/intlayer_with_vanilla.md +506 -0
- package/docs/en-GB/cli/index.md +56 -44
- package/docs/en-GB/cli/init.md +28 -21
- package/docs/en-GB/cli/standalone.md +91 -0
- package/docs/en-GB/configuration.md +53 -14
- package/docs/en-GB/custom_domains.md +250 -0
- package/docs/en-GB/intlayer_with_tanstack+solid.md +14 -33
- package/docs/en-GB/intlayer_with_tanstack.md +25 -16
- package/docs/en-GB/intlayer_with_vanilla.md +506 -0
- package/docs/es/cli/index.md +65 -53
- package/docs/es/cli/init.md +33 -21
- package/docs/es/cli/standalone.md +91 -0
- package/docs/es/configuration.md +39 -1
- package/docs/es/custom_domains.md +250 -0
- package/docs/es/intlayer_with_tanstack+solid.md +14 -33
- package/docs/es/intlayer_with_tanstack.md +25 -16
- package/docs/es/intlayer_with_vanilla.md +506 -0
- package/docs/fr/cli/index.md +43 -31
- package/docs/fr/cli/init.md +37 -25
- package/docs/fr/cli/standalone.md +91 -0
- package/docs/fr/configuration.md +46 -7
- package/docs/fr/custom_domains.md +250 -0
- package/docs/fr/intlayer_with_tanstack+solid.md +14 -33
- package/docs/fr/intlayer_with_tanstack.md +25 -16
- package/docs/fr/intlayer_with_vanilla.md +506 -0
- package/docs/hi/cli/index.md +71 -59
- package/docs/hi/cli/init.md +37 -33
- package/docs/hi/cli/standalone.md +91 -0
- package/docs/hi/configuration.md +39 -7
- package/docs/hi/custom_domains.md +250 -0
- package/docs/hi/intlayer_with_tanstack+solid.md +14 -33
- package/docs/hi/intlayer_with_tanstack.md +25 -16
- package/docs/hi/intlayer_with_vanilla.md +506 -0
- package/docs/id/cli/index.md +59 -47
- package/docs/id/cli/init.md +32 -25
- package/docs/id/cli/standalone.md +91 -0
- package/docs/id/configuration.md +46 -7
- package/docs/id/custom_domains.md +250 -0
- package/docs/id/intlayer_with_tanstack+solid.md +14 -33
- package/docs/id/intlayer_with_tanstack.md +25 -16
- package/docs/id/intlayer_with_vanilla.md +506 -0
- package/docs/it/cli/index.md +58 -41
- package/docs/it/cli/init.md +37 -38
- package/docs/it/cli/standalone.md +91 -0
- package/docs/it/configuration.md +46 -7
- package/docs/it/custom_domains.md +250 -0
- package/docs/it/intlayer_with_tanstack+solid.md +14 -33
- package/docs/it/intlayer_with_tanstack.md +25 -16
- package/docs/it/intlayer_with_vanilla.md +506 -0
- package/docs/ja/cli/index.md +59 -47
- package/docs/ja/cli/init.md +36 -24
- package/docs/ja/cli/standalone.md +91 -0
- package/docs/ja/configuration.md +46 -7
- package/docs/ja/custom_domains.md +250 -0
- package/docs/ja/intlayer_with_tanstack+solid.md +14 -33
- package/docs/ja/intlayer_with_tanstack.md +25 -16
- package/docs/ja/intlayer_with_vanilla.md +506 -0
- package/docs/ko/cli/index.md +58 -46
- package/docs/ko/cli/init.md +39 -35
- package/docs/ko/cli/standalone.md +91 -0
- package/docs/ko/configuration.md +47 -8
- package/docs/ko/custom_domains.md +250 -0
- package/docs/ko/intlayer_with_tanstack+solid.md +14 -33
- package/docs/ko/intlayer_with_tanstack.md +25 -16
- package/docs/ko/intlayer_with_vanilla.md +506 -0
- package/docs/nl/cli/index.md +195 -0
- package/docs/nl/cli/init.md +96 -0
- package/docs/nl/cli/standalone.md +91 -0
- package/docs/nl/configuration.md +46 -7
- package/docs/nl/custom_domains.md +250 -0
- package/docs/nl/intlayer_with_vanilla.md +506 -0
- package/docs/pl/cli/index.md +56 -44
- package/docs/pl/cli/init.md +36 -32
- package/docs/pl/cli/standalone.md +91 -0
- package/docs/pl/configuration.md +46 -7
- package/docs/pl/custom_domains.md +250 -0
- package/docs/pl/intlayer_with_tanstack+solid.md +14 -33
- package/docs/pl/intlayer_with_tanstack.md +25 -16
- package/docs/pl/intlayer_with_vanilla.md +506 -0
- package/docs/pt/cli/index.md +64 -52
- package/docs/pt/cli/init.md +35 -31
- package/docs/pt/cli/standalone.md +91 -0
- package/docs/pt/configuration.md +46 -7
- package/docs/pt/custom_domains.md +250 -0
- package/docs/pt/intlayer_with_tanstack+solid.md +14 -33
- package/docs/pt/intlayer_with_tanstack.md +25 -16
- package/docs/pt/intlayer_with_vanilla.md +506 -0
- package/docs/ru/cli/index.md +54 -42
- package/docs/ru/cli/init.md +31 -27
- package/docs/ru/cli/standalone.md +91 -0
- package/docs/ru/configuration.md +46 -7
- package/docs/ru/custom_domains.md +250 -0
- package/docs/ru/intlayer_with_tanstack+solid.md +14 -33
- package/docs/ru/intlayer_with_tanstack.md +25 -16
- package/docs/ru/intlayer_with_vanilla.md +506 -0
- package/docs/tr/cli/index.md +64 -52
- package/docs/tr/cli/init.md +37 -30
- package/docs/tr/cli/standalone.md +91 -0
- package/docs/tr/configuration.md +46 -7
- package/docs/tr/custom_domains.md +250 -0
- package/docs/tr/intlayer_with_tanstack+solid.md +14 -33
- package/docs/tr/intlayer_with_tanstack.md +25 -16
- package/docs/tr/intlayer_with_vanilla.md +506 -0
- package/docs/uk/cli/index.md +60 -55
- package/docs/uk/cli/init.md +32 -20
- package/docs/uk/cli/standalone.md +91 -0
- package/docs/uk/configuration.md +46 -7
- package/docs/uk/custom_domains.md +250 -0
- package/docs/uk/intlayer_with_tanstack+solid.md +14 -33
- package/docs/uk/intlayer_with_tanstack.md +25 -16
- package/docs/uk/intlayer_with_vanilla.md +506 -0
- package/docs/ur/cli/index.md +195 -0
- package/docs/ur/cli/init.md +96 -0
- package/docs/ur/cli/standalone.md +91 -0
- package/docs/ur/configuration.md +46 -7
- package/docs/ur/custom_domains.md +250 -0
- package/docs/ur/intlayer_with_vanilla.md +506 -0
- package/docs/vi/cli/index.md +72 -61
- package/docs/vi/cli/init.md +33 -21
- package/docs/vi/cli/standalone.md +91 -0
- package/docs/vi/configuration.md +46 -7
- package/docs/vi/custom_domains.md +250 -0
- package/docs/vi/intlayer_with_tanstack+solid.md +14 -33
- package/docs/vi/intlayer_with_tanstack.md +25 -16
- package/docs/vi/intlayer_with_vanilla.md +506 -0
- package/docs/zh/cli/index.md +56 -49
- package/docs/zh/cli/init.md +30 -18
- package/docs/zh/cli/standalone.md +91 -0
- package/docs/zh/configuration.md +46 -7
- package/docs/zh/custom_domains.md +250 -0
- package/docs/zh/intlayer_with_tanstack+solid.md +14 -33
- package/docs/zh/intlayer_with_tanstack.md +25 -16
- package/docs/zh/intlayer_with_vanilla.md +506 -0
- package/package.json +8 -8
- package/src/doc.ts +4 -1
- package/src/generated/docs.entry.ts +60 -0
- package/docs/ar/bundle_optimization.md +0 -185
- package/docs/de/bundle_optimization.md +0 -195
- package/docs/en-GB/bundle_optimization.md +0 -184
- package/docs/es/bundle_optimization.md +0 -194
- package/docs/fr/bundle_optimization.md +0 -184
- package/docs/hi/bundle_optimization.md +0 -185
- package/docs/id/bundle_optimization.md +0 -185
- package/docs/it/bundle_optimization.md +0 -185
- package/docs/ja/bundle_optimization.md +0 -185
- package/docs/ko/bundle_optimization.md +0 -185
- package/docs/pl/bundle_optimization.md +0 -185
- package/docs/pt/bundle_optimization.md +0 -184
- package/docs/ru/bundle_optimization.md +0 -185
- package/docs/tr/bundle_optimization.md +0 -184
- package/docs/uk/bundle_optimization.md +0 -186
- package/docs/vi/bundle_optimization.md +0 -185
- package/docs/zh/bundle_optimization.md +0 -185
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2026-03-31
|
|
3
|
+
updatedAt: 2026-03-31
|
|
4
|
+
title: Vanilla JS i18n - Jak przetłumaczyć aplikację Vanilla JS w 2026 roku
|
|
5
|
+
description: Dowiedz się, jak uczynić swoją stronę Vanilla JS wielojęzyczną. Postępuj zgodnie z dokumentacją, aby ją umiędzynarodowić (i18n) i przetłumaczyć.
|
|
6
|
+
keywords:
|
|
7
|
+
- Międzynarodowienie
|
|
8
|
+
- Dokumentacja
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Vanilla JS
|
|
11
|
+
- JavaScript
|
|
12
|
+
- TypeScript
|
|
13
|
+
- HTML
|
|
14
|
+
slugs:
|
|
15
|
+
- doc
|
|
16
|
+
- environment
|
|
17
|
+
- vanilla
|
|
18
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vanilla-template
|
|
19
|
+
history:
|
|
20
|
+
- version: 8.4.10
|
|
21
|
+
date: 2026-03-31
|
|
22
|
+
changes: "Inicjalizacja historii"
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# Przetłumacz swoją stronę Vanilla JS używając Intlayer | Międzynarodowienie (i18n)
|
|
26
|
+
|
|
27
|
+
## Spis treści
|
|
28
|
+
|
|
29
|
+
<TOC/>
|
|
30
|
+
|
|
31
|
+
## Co to jest Intlayer?
|
|
32
|
+
|
|
33
|
+
**Intlayer** to innowacyjna biblioteka międzynarodowienia (i18n) o otwartym kodzie źródłowym, zaprojektowana w celu uproszczenia obsługi wielojęzyczności w nowoczesnych aplikacjach internetowych.
|
|
34
|
+
|
|
35
|
+
Dzięki Intlayer możesz:
|
|
36
|
+
|
|
37
|
+
- **Łatwo zarządzać tłumaczeniami** używając deklaratywnych słowników na poziomie komponentów.
|
|
38
|
+
- **Dynamicznie lokalizować metadane**, trasy i treści.
|
|
39
|
+
- **Zapewnić wsparcie dla TypeScript** dzięki automatycznie generowanym typom, co poprawia autouzupełnianie i wykrywanie błędów.
|
|
40
|
+
- **Korzystać z zaawansowanych funkcji**, takich jak dynamiczne wykrywanie i przełączanie języka.
|
|
41
|
+
|
|
42
|
+
Ten poradnik pokazuje, jak używać Intlayer w aplikacji Vanilla JavaScript **bez użycia menedżera pakietów lub bundlera** (takiego jak Vite, Webpack itp.).
|
|
43
|
+
|
|
44
|
+
Jeśli Twoja aplikacja używa bundlera (np. Vite), zalecamy zamiast tego skorzystanie z [Poradnika Vite + Vanilla JS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/intlayer_with_vite+vanilla.md).
|
|
45
|
+
|
|
46
|
+
Używając samodzielnego pakietu (standalone bundle), możesz zaimportować Intlayer bezpośrednio do plików HTML za pomocą jednego pliku JavaScript, co czyni go idealnym dla starszych projektów lub prostych stron statycznych.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Przewodnik krok po kroku konfiguracji Intlayer w aplikacji Vanilla JS
|
|
51
|
+
|
|
52
|
+
### Krok 1: Instalacja zależności
|
|
53
|
+
|
|
54
|
+
Zainstaluj niezbędne pakiety za pomocą npm:
|
|
55
|
+
|
|
56
|
+
```bash packageManager="npm"
|
|
57
|
+
# Wygeneruj samodzielny pakiet intlayer i vanilla-intlayer
|
|
58
|
+
# Ten plik zostanie zaimportowany do Twojego pliku HTML
|
|
59
|
+
npx intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
|
|
60
|
+
|
|
61
|
+
# Zainicjuj intlayer z plikiem konfiguracyjnym
|
|
62
|
+
npx intlayer init --no-gitignore
|
|
63
|
+
|
|
64
|
+
# Zbuduj słowniki
|
|
65
|
+
npx intlayer build
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```bash packageManager="pnpm"
|
|
69
|
+
# Wygeneruj samodzielny pakiet intlayer i vanilla-intlayer
|
|
70
|
+
# Ten plik zostanie zaimportowany do Twojego pliku HTML
|
|
71
|
+
pnpm intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
|
|
72
|
+
|
|
73
|
+
# Zainicjuj intlayer z plikiem konfiguracyjnym
|
|
74
|
+
pnpm intlayer init --no-gitignore
|
|
75
|
+
|
|
76
|
+
# Zbuduj słowniki
|
|
77
|
+
pnpm intlayer build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash packageManager="yarn"
|
|
81
|
+
# Wygeneruj samodzielny pakiet intlayer i vanilla-intlayer
|
|
82
|
+
# Ten plik zostanie zaimportowany do Twojego pliku HTML
|
|
83
|
+
yarn intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
|
|
84
|
+
|
|
85
|
+
# Zainicjuj plik konfiguracyjny intlayer, TypeScript jeśli skonfigurowany, zmienne środowiskowe
|
|
86
|
+
yarn intlayer init --no-gitignore
|
|
87
|
+
|
|
88
|
+
# Zbuduj słowniki
|
|
89
|
+
yarn intlayer build
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```bash packageManager="bun"
|
|
93
|
+
# Wygeneruj samodzielny pakiet intlayer i vanilla-intlayer
|
|
94
|
+
# Ten plik zostanie zaimportowany do Twojego pliku HTML
|
|
95
|
+
bun x intlayer standalone --packages intlayer vanilla-intlayer --outfile intlayer.js
|
|
96
|
+
|
|
97
|
+
# Zainicjuj intlayer z plikiem konfiguracyjnym
|
|
98
|
+
bun x intlayer init --no-gitignore
|
|
99
|
+
|
|
100
|
+
# Zbuduj słowniki
|
|
101
|
+
bun x intlayer build
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- **intlayer**
|
|
105
|
+
Główny pakiet dostarczający narzędzia do międzynarodowienia w zakresie zarządzania konfiguracją, tłumaczenia, [deklarowania treści](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/dictionary/content_file.md), transpilacji oraz [poleceń CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/cli/index.md).
|
|
106
|
+
|
|
107
|
+
- **vanilla-intlayer**
|
|
108
|
+
Pakiet integrujący Intlayer z czystymi aplikacjami JavaScript / TypeScript. Dostarcza singleton pub/sub (`IntlayerClient`) oraz pomocników opartych na callbackach (`useIntlayer`, `useLocale` itp.), dzięki czemu każda część Twojej aplikacji może reagować na zmiany języka bez zależności od frameworka UI.
|
|
109
|
+
|
|
110
|
+
> Eksport bundlingu z CLI `intlayer standalone` generuje zoptymalizowaną kompilację dzięki usuwaniu nieużywanych kodów (tree-shaking) nieużywanych pakietów, lokalizacji i nieistotnej logiki (takiej jak przekierowania lub prefiksy), specyficznych dla Twojej konfiguracji.
|
|
111
|
+
|
|
112
|
+
### Krok 2: Konfiguracja Twojego projektu
|
|
113
|
+
|
|
114
|
+
Utwórz plik konfiguracyjny, aby skonfigurować języki Twojej aplikacji:
|
|
115
|
+
|
|
116
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
117
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
118
|
+
|
|
119
|
+
const config: IntlayerConfig = {
|
|
120
|
+
internationalization: {
|
|
121
|
+
locales: [
|
|
122
|
+
Locales.ENGLISH,
|
|
123
|
+
Locales.FRENCH,
|
|
124
|
+
Locales.SPANISH,
|
|
125
|
+
// Twoje inne języki
|
|
126
|
+
],
|
|
127
|
+
defaultLocale: Locales.ENGLISH,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default config;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
135
|
+
import { Locales } from "intlayer";
|
|
136
|
+
|
|
137
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
138
|
+
const config = {
|
|
139
|
+
internationalization: {
|
|
140
|
+
locales: [
|
|
141
|
+
Locales.ENGLISH,
|
|
142
|
+
Locales.FRENCH,
|
|
143
|
+
Locales.SPANISH,
|
|
144
|
+
// Twoje inne języki
|
|
145
|
+
],
|
|
146
|
+
defaultLocale: Locales.ENGLISH,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default config;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
154
|
+
const { Locales } = require("intlayer");
|
|
155
|
+
|
|
156
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
157
|
+
const config = {
|
|
158
|
+
internationalization: {
|
|
159
|
+
locales: [
|
|
160
|
+
Locales.ENGLISH,
|
|
161
|
+
Locales.FRENCH,
|
|
162
|
+
Locales.SPANISH,
|
|
163
|
+
// Twoje inne języki
|
|
164
|
+
],
|
|
165
|
+
defaultLocale: Locales.ENGLISH,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
module.exports = config;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
> Za pomocą tego pliku konfiguracyjnego możesz ustawić zlokalizowane adresy URL, przekierowania middleware, nazwy ciasteczek, lokalizację i rozszerzenie deklaracji treści, wyłączyć logi Intlayer w konsoli i wiele więcej. Pełną listę dostępnych parametrów znajdziesz w [dokumentacji konfiguracji](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/configuration.md).
|
|
173
|
+
|
|
174
|
+
### Krok 3: Zaimportuj pakiet do HTML
|
|
175
|
+
|
|
176
|
+
Po wygenerowaniu pakietu `intlayer.js`, możesz go zaimportować do swojego pliku HTML:
|
|
177
|
+
|
|
178
|
+
```html fileName="index.html"
|
|
179
|
+
<!DOCTYPE html>
|
|
180
|
+
<html lang="pl">
|
|
181
|
+
<head>
|
|
182
|
+
<meta charset="UTF-8" />
|
|
183
|
+
|
|
184
|
+
<!-- Zaimportuj pakiet -->
|
|
185
|
+
<script src="./intlayer.js" defer></script>
|
|
186
|
+
<!-- Zaimportuj swój główny skrypt -->
|
|
187
|
+
<script src="./src/main.js" defer></script>
|
|
188
|
+
</head>
|
|
189
|
+
<body>
|
|
190
|
+
<h1 id="title"></h1>
|
|
191
|
+
<p class="read-the-docs"></p>
|
|
192
|
+
</body>
|
|
193
|
+
</html>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Pakiet udostępnia `Intlayer` i `VanillaIntlayer` jako obiekty globalne na `window`.
|
|
197
|
+
|
|
198
|
+
### Krok 4: Uruchom Intlayer w punkcie wejścia (entry point)
|
|
199
|
+
|
|
200
|
+
W swoim `src/main.js` wywołaj `installIntlayer()` **zanim** jakakolwiek treść zostanie wyrenderowana, aby globalny singleton języka był gotowy.
|
|
201
|
+
|
|
202
|
+
```javascript fileName="src/main.js"
|
|
203
|
+
const { installIntlayer } = window.VanillaIntlayer;
|
|
204
|
+
|
|
205
|
+
// Musi zostać wywołane przed renderowaniem jakiejkolwiek treści i18n.
|
|
206
|
+
installIntlayer();
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Jeśli chcesz również używać renderera markdown, wywołaj `installIntlayerMarkdown()`:
|
|
210
|
+
|
|
211
|
+
```javascript fileName="src/main.js"
|
|
212
|
+
const { installIntlayer, installIntlayerMarkdown } = window.VanillaIntlayer;
|
|
213
|
+
|
|
214
|
+
installIntlayer();
|
|
215
|
+
installIntlayerMarkdown();
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Krok 5: Zadeklaruj swoje treści
|
|
219
|
+
|
|
220
|
+
Twórz i zarządzaj swoimi deklaracjami treści, aby przechowywać tłumaczenia:
|
|
221
|
+
|
|
222
|
+
```typescript fileName="src/app.content.ts" contentDeclarationFormat="typescript"
|
|
223
|
+
import { insert, t, type Dictionary } from "intlayer";
|
|
224
|
+
|
|
225
|
+
const appContent = {
|
|
226
|
+
key: "app",
|
|
227
|
+
content: {
|
|
228
|
+
title: "Vite + Vanilla",
|
|
229
|
+
|
|
230
|
+
viteLogoLabel: t({
|
|
231
|
+
en: "Vite Logo",
|
|
232
|
+
fr: "Logo Vite",
|
|
233
|
+
es: "Logo Vite",
|
|
234
|
+
}),
|
|
235
|
+
|
|
236
|
+
count: insert(
|
|
237
|
+
t({
|
|
238
|
+
en: "count is {{count}}",
|
|
239
|
+
fr: "le compte est {{count}}",
|
|
240
|
+
es: "el recuento es {{count}}",
|
|
241
|
+
})
|
|
242
|
+
),
|
|
243
|
+
|
|
244
|
+
readTheDocs: t({
|
|
245
|
+
en: "Click on the Vite logo to learn more",
|
|
246
|
+
fr: "Cliquez sur le logo Vite pour en savoir plus",
|
|
247
|
+
es: "Kliknij na logo Vite, aby dowiedzieć się więcej",
|
|
248
|
+
}),
|
|
249
|
+
},
|
|
250
|
+
} satisfies Dictionary;
|
|
251
|
+
|
|
252
|
+
export default appContent;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
```javascript fileName="src/app.content.mjs" contentDeclarationFormat="esm"
|
|
256
|
+
import { insert, t } from "intlayer";
|
|
257
|
+
|
|
258
|
+
/** @type {import('intlayer').Dictionary} */
|
|
259
|
+
const appContent = {
|
|
260
|
+
key: "app",
|
|
261
|
+
content: {
|
|
262
|
+
title: "Vite + Vanilla",
|
|
263
|
+
|
|
264
|
+
viteLogoLabel: t({
|
|
265
|
+
en: "Vite Logo",
|
|
266
|
+
fr: "Logo Vite",
|
|
267
|
+
es: "Logo Vite",
|
|
268
|
+
}),
|
|
269
|
+
|
|
270
|
+
count: insert(
|
|
271
|
+
t({
|
|
272
|
+
en: "count is {{count}}",
|
|
273
|
+
fr: "le compte est {{count}}",
|
|
274
|
+
es: "el recuento es {{count}}",
|
|
275
|
+
})
|
|
276
|
+
),
|
|
277
|
+
|
|
278
|
+
readTheDocs: t({
|
|
279
|
+
en: "Click on the Vite logo to learn more",
|
|
280
|
+
fr: "Cliquez sur le logo Vite pour en savoir plus",
|
|
281
|
+
es: "Kliknij na logo Vite, aby dowiedzieć się więcej",
|
|
282
|
+
}),
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export default appContent;
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
```javascript fileName="src/app.content.cjs" contentDeclarationFormat="commonjs"
|
|
290
|
+
const { insert, t } = require("intlayer");
|
|
291
|
+
|
|
292
|
+
/** @type {import('intlayer').Dictionary} */
|
|
293
|
+
const appContent = {
|
|
294
|
+
key: "app",
|
|
295
|
+
content: {
|
|
296
|
+
title: "Vite + Vanilla",
|
|
297
|
+
|
|
298
|
+
viteLogoLabel: t({
|
|
299
|
+
en: "Vite Logo",
|
|
300
|
+
fr: "Logo Vite",
|
|
301
|
+
es: "Logo Vite",
|
|
302
|
+
}),
|
|
303
|
+
|
|
304
|
+
count: insert(
|
|
305
|
+
t({
|
|
306
|
+
en: "count is {{count}}",
|
|
307
|
+
fr: "le compte est {{count}}",
|
|
308
|
+
es: "el recuento es {{count}}",
|
|
309
|
+
})
|
|
310
|
+
),
|
|
311
|
+
|
|
312
|
+
readTheDocs: t({
|
|
313
|
+
en: "Click on the Vite logo to learn more",
|
|
314
|
+
fr: "Cliquez sur le logo Vite pour en savoir plus",
|
|
315
|
+
es: "Kliknij na logo Vite, aby dowiedzieć się więcej",
|
|
316
|
+
}),
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
module.exports = appContent;
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
```json fileName="src/app.content.json" contentDeclarationFormat="json"
|
|
324
|
+
{
|
|
325
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
326
|
+
"key": "app",
|
|
327
|
+
"content": {
|
|
328
|
+
"title": "Vite + Vanilla",
|
|
329
|
+
"viteLogoLabel": {
|
|
330
|
+
"nodeType": "translation",
|
|
331
|
+
"translation": {
|
|
332
|
+
"en": "Vite Logo",
|
|
333
|
+
"fr": "Logo Vite",
|
|
334
|
+
"es": "Logo Vite"
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
"count": {
|
|
338
|
+
"nodeType": "insertion",
|
|
339
|
+
"insertion": {
|
|
340
|
+
"nodeType": "translation",
|
|
341
|
+
"translation": {
|
|
342
|
+
"en": "count is {{count}}",
|
|
343
|
+
"fr": "le compte est {{count}}",
|
|
344
|
+
"es": "el recuento es {{count}}"
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
"readTheDocs": {
|
|
349
|
+
"nodeType": "translation",
|
|
350
|
+
"translation": {
|
|
351
|
+
"en": "Click on the Vite logo to learn more",
|
|
352
|
+
"fr": "Cliquez sur le logo Vite pour en savoir plus",
|
|
353
|
+
"es": "Kliknij na logo Vite, aby dowiedzieć się więcej"
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
> Deklaracje treści mogą być definiowane w dowolnym miejscu aplikacji, o ile znajdują się w katalogu `contentDir` (domyślnie `./src`) i pasują do rozszerzenia pliku deklaracji treści (domyślnie `.content.{json,ts,tsx,js,jsx,mjs,cjs}`).
|
|
361
|
+
>
|
|
362
|
+
> Więcej szczegółów znajdziesz w [dokumentacji deklaracji treści](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/dictionary/content_file.md).
|
|
363
|
+
|
|
364
|
+
### Krok 6: Użyj Intlayer w swoim JavaScript
|
|
365
|
+
|
|
366
|
+
Obiekt `window.VanillaIntlayer` dostarcza pomocników API: `useIntlayer(key, locale?)` zwraca przetłumaczoną treść dla danego klucza.
|
|
367
|
+
|
|
368
|
+
```javascript fileName="src/main.js"
|
|
369
|
+
const { installIntlayer, useIntlayer } = window.VanillaIntlayer;
|
|
370
|
+
|
|
371
|
+
installIntlayer();
|
|
372
|
+
|
|
373
|
+
// Pobierz początkową treść dla bieżącego języka.
|
|
374
|
+
// Podepnij .onChange(), aby otrzymywać powiadomienia o każdej zmianie języka.
|
|
375
|
+
const content = useIntlayer("app").onChange((newContent) => {
|
|
376
|
+
// Ponownie wyrenderuj lub zaktualizuj tylko dotknięte węzły DOM
|
|
377
|
+
document.querySelector("h1").textContent = String(newContent.title);
|
|
378
|
+
document.querySelector(".read-the-docs").textContent = String(
|
|
379
|
+
newContent.readTheDocs
|
|
380
|
+
);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Początkowy render
|
|
384
|
+
document.querySelector("h1").textContent = String(content.title);
|
|
385
|
+
document.querySelector(".read-the-docs").textContent = String(
|
|
386
|
+
content.readTheDocs
|
|
387
|
+
);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
> Uzyskuj dostęp do wartości liści jako ciągów znaków, owijając je w `String()`, co wywołuje metodę `toString()` węzła i zwraca przetłumaczony tekst.
|
|
391
|
+
>
|
|
392
|
+
> Gdy potrzebujesz wartości dla natywnego atrybutu HTML (np. `alt`, `aria-label`), użyj bezpośrednio `.value`:
|
|
393
|
+
>
|
|
394
|
+
> ```javascript
|
|
395
|
+
> img.alt = content.viteLogoLabel.value;
|
|
396
|
+
> ```
|
|
397
|
+
|
|
398
|
+
### (Opcjonalnie) Krok 7: Zmień język swojej treści
|
|
399
|
+
|
|
400
|
+
Aby zmienić język treści, użyj funkcji `setLocale` udostępnianej przez `useLocale`.
|
|
401
|
+
|
|
402
|
+
```javascript fileName="src/locale-switcher.js"
|
|
403
|
+
const { getLocaleName } = window.Intlayer;
|
|
404
|
+
const { useLocale } = window.VanillaIntlayer;
|
|
405
|
+
|
|
406
|
+
export function setupLocaleSwitcher(container) {
|
|
407
|
+
const { locale, availableLocales, setLocale, subscribe } = useLocale();
|
|
408
|
+
|
|
409
|
+
const select = document.createElement("select");
|
|
410
|
+
select.setAttribute("aria-label", "Język");
|
|
411
|
+
|
|
412
|
+
const render = (currentLocale) => {
|
|
413
|
+
select.innerHTML = availableLocales
|
|
414
|
+
.map(
|
|
415
|
+
(loc) =>
|
|
416
|
+
`<option value="${loc}"${loc === currentLocale ? " selected" : ""}>
|
|
417
|
+
${getLocaleName(loc)}
|
|
418
|
+
</option>`
|
|
419
|
+
)
|
|
420
|
+
.join("");
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
render(locale);
|
|
424
|
+
container.appendChild(select);
|
|
425
|
+
|
|
426
|
+
select.addEventListener("change", () => setLocale(select.value));
|
|
427
|
+
|
|
428
|
+
// Utrzymuj listę rozwijaną w synchronizacji, gdy język zmieni się z innego miejsca
|
|
429
|
+
return subscribe((newLocale) => render(newLocale));
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### (Opcjonalnie) Krok 8: Przełącz atrybuty języka i kierunku HTML
|
|
434
|
+
|
|
435
|
+
Zaktualizuj atrybuty `lang` i `dir` tagu `<html>`, aby pasowały do bieżącego języka dla dostępności i SEO.
|
|
436
|
+
|
|
437
|
+
```javascript fileName="src/main.js"
|
|
438
|
+
const { getHTMLTextDir } = window.Intlayer;
|
|
439
|
+
const { installIntlayer, useLocale } = window.VanillaIntlayer;
|
|
440
|
+
|
|
441
|
+
installIntlayer();
|
|
442
|
+
|
|
443
|
+
useLocale({
|
|
444
|
+
onLocaleChange: (locale) => {
|
|
445
|
+
document.documentElement.lang = locale;
|
|
446
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### (Opcjonalnie) Krok 9: Leniwe ładowanie słowników na język (lazy load)
|
|
452
|
+
|
|
453
|
+
Jeśli chcesz leniwie ładować słowniki dla każdego języka, możesz użyć `useDictionaryDynamic`. Jest to przydatne, jeśli nie chcesz pakować wszystkich tłumaczeń w początkowym pliku `intlayer.js`.
|
|
454
|
+
|
|
455
|
+
```javascript fileName="src/app.js"
|
|
456
|
+
const { installIntlayer, useDictionaryDynamic } = window.VanillaIntlayer;
|
|
457
|
+
|
|
458
|
+
installIntlayer();
|
|
459
|
+
|
|
460
|
+
const unsubscribe = useDictionaryDynamic(
|
|
461
|
+
{
|
|
462
|
+
en: () => import("../.intlayer/dictionaries/en/app.mjs"),
|
|
463
|
+
fr: () => import("../.intlayer/dictionaries/fr/app.mjs"),
|
|
464
|
+
es: () => import("../.intlayer/dictionaries/es/app.mjs"),
|
|
465
|
+
},
|
|
466
|
+
"app"
|
|
467
|
+
).onChange((content) => {
|
|
468
|
+
document.querySelector("h1").textContent = String(content.title);
|
|
469
|
+
});
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
> Uwaga: `useDictionaryDynamic` wymaga, aby słowniki były dostępne jako oddzielne pliki ESM. Podejście to jest zazwyczaj stosowane, jeśli masz serwer WWW serwujący słowniki.
|
|
473
|
+
|
|
474
|
+
### Konfiguracja TypeScript
|
|
475
|
+
|
|
476
|
+
Upewnij się, że Twoja konfiguracja TypeScript zawiera automatycznie generowane typy.
|
|
477
|
+
|
|
478
|
+
```json5 fileName="tsconfig.json"
|
|
479
|
+
{
|
|
480
|
+
"compilerOptions": {
|
|
481
|
+
// ...
|
|
482
|
+
},
|
|
483
|
+
"include": ["src", ".intlayer/**/*.ts"],
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Rozszerzenie VS Code
|
|
488
|
+
|
|
489
|
+
Aby poprawić wrażenia z programowania z Intlayer, możesz zainstalować oficjalne **Rozszerzenie Intlayer dla VS Code**.
|
|
490
|
+
|
|
491
|
+
[Zainstaluj z VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
492
|
+
|
|
493
|
+
To rozszerzenie zapewnia:
|
|
494
|
+
|
|
495
|
+
- **Autouzupełnianie** dla kluczy tłumaczeń.
|
|
496
|
+
- **Wykrywanie błędów w czasie rzeczywistym** dla brakujących tłumaczeń.
|
|
497
|
+
- **Podgląd wewnątrz kodu** przetłumaczonej treści.
|
|
498
|
+
- **Szybkie akcje**, aby łatwo tworzyć i aktualizować tłumaczenia.
|
|
499
|
+
|
|
500
|
+
Więcej szczegółów na temat korzystania z rozszerzenia znajdziesz w [dokumentacji rozszerzenia Intlayer dla VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
### Idź dalej
|
|
505
|
+
|
|
506
|
+
Aby pójść dalej, możesz zaimplementować [edytor wizualny](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/intlayer_visual_editor.md) lub wyeksportować swoje treści za pomocą [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pl/intlayer_CMS.md).
|