11# WLED i18n Toolchain
22
3- Build-time internationalization for WLED Web UI. Translates HTML/JS strings at compile time with ** zero runtime overhead ** and ** zero flash overhead ** (replaces, not adds) .
3+ Build-time internationalization for WLED Web UI. Translates HTML/JS strings at compile time — replaces English text, does not add to it .
44
55## How It Works
66
@@ -43,7 +43,7 @@ WLED-translations/
4343├── library.json # PlatformIO dependency manifest
4444├── zh_CN/
4545│ ├── static.json # Layer 1: static HTML (429 entries)
46- │ ├── js.json # Layer 2: JS strings (45 entries)
46+ │ ├── js.json # Layer 2: JS strings (716 entries)
4747│ ├── effects.json # Layer 3: effect names (216 entries)
4848│ ├── palettes.json # Layer 4: palette names (72 entries)
4949│ └── metadata.json
@@ -61,7 +61,7 @@ cd WLED-translations
6161
6262# 2. Generate English template (from WLED source)
6363python3 /path/to/WLED/tools/i18n/extract.py --stats
64- cp /path/to/WLED/tools/i18n/locales/en_template.json en_template/
64+ cp -r /path/to/WLED/tools/i18n/locales/* en_template/
6565
6666# 3. Create your locale
6767mkdir de_DE
@@ -98,6 +98,24 @@ npm ci && npm run build
9898pio run -e esp32dev
9999```
100100
101+ ### Version updates (diff)
102+
103+ When WLED releases a new version, compare templates to find changes:
104+
105+ ``` bash
106+ # Generate old and new templates
107+ python3 tools/i18n/extract.py --stats # on old version
108+ cp tools/i18n/locales/en_template.json en_template_old.json
109+
110+ python3 tools/i18n/extract.py --stats # on new version
111+ cp tools/i18n/locales/en_template.json en_template_new.json
112+
113+ # Compare
114+ python3 tools/i18n/diff.py --old en_template_old.json --new en_template_new.json
115+ ```
116+
117+ Output shows added/removed/modified strings. Translators update only changed entries.
118+
101119## Translation Search Order
102120
103121` build.py ` searches for translations in this order:
@@ -106,37 +124,64 @@ pio run -e esp32dev
1061242 . ` .pio/libdeps/*/WLED-translations/<locale>/ ` (PlatformIO out-of-tree)
1071253 . ` tools/i18n/locales/<locale>.json ` (local fallback)
108126
109- ## Translation JSON Format
110-
111- ``` json
112- {
113- "index.htm" : {
114- "html:body > div#btns > a:nth-of-type(1):text" : {
115- "en" : " Power" ,
116- "translation" : " 电源" ,
117- "context" : " index.htm: (html_text)"
118- },
119- "js:index.htm:45:a1b2c3d4" : {
120- "en" : " Loading..." ,
121- "translation" : " 加载中..." ,
122- "context" : " index.htm:45 (js_innerHTML)"
123- }
124- }
125- }
126- ```
127-
128127## Coverage
129128
130129| Layer | Content | Method | Count |
131130| -------| ---------| --------| -------|
132131| 1. Static HTML | Labels, buttons, placeholders | DOM text matching | 429 |
133- | 2. JS strings | ` alert() ` , ` innerHTML ` , ` innerText ` | Script block regex | 45 |
134- | 3. Effect names | FX names in ` colors.cpp ` | PROGMEM replacement | 216 |
135- | 4. Palette names | Palette names in ` colors.cpp ` | PROGMEM replacement | 72 |
132+ | 2. JS strings | ` alert() ` , ` innerHTML ` , ` innerText ` | Script block regex | 716 |
133+ | 3. Effect names | FX names in ` FX.cpp ` | PROGMEM replacement | 216 |
134+ | 4. Palette names | Palette names in ` FX_fcn.cpp ` | PROGMEM replacement | 72 |
135+
136+ ## Known Limitations
137+
138+ ### Cannot translate (technical)
136139
137- ## Limitations
140+ - ** Dynamic runtime text** — OTA update errors, Info page content, usermod settings, Pin Info page
141+ - ** External tools** — PixelForge add-ons (always English, downloaded on-the-fly)
142+ - ** JavaScript template literals** — strings with ` ${...} ` interpolation
143+ - ** C++ server-side strings** — ~ 12 strings in ` xml.cpp ` need ` #ifdef WLED_LOCALE_* `
138144
139- 1 . ** No runtime language switching** — language is fixed at build time
140- 2 . ** JS template literals with ` ${...} ` ** — partial strings can't be safely replaced
141- 3 . ** C++ server-side strings** — ~ 12 strings in ` xml.cpp ` need ` #ifdef WLED_LOCALE_* `
142- 4 . ** External tools** (pixelforge, pixelmagic) — always English, downloaded on-the-fly
145+ ### Language-specific issues (acknowledged)
146+
147+ - Word order differences (e.g., "X of Y" patterns)
148+ - Number formats (decimal point vs comma)
149+ - Grammar rules (singular/plural, countable/uncountable)
150+ - Date formats
151+
152+ These are known limitations. The tool handles short labels and UI fragments, not full sentences.
153+
154+ ## Layer 3/4: Effect & Palette Names
155+
156+ Effect names (216) and palette names (72) are translated via C++ PROGMEM replacement:
157+
158+ ``` c
159+ // locale_effects.h (auto-generated)
160+ #pragma once
161+ #ifdef WLED_LOCALE
162+ #undef _ data_FX_MODE_STATIC
163+ static const char _ data_FX_MODE_STATIC[ ] PROGMEM = "常亮";
164+ // ...
165+ #endif
166+ ```
167+
168+ The ` .h ` files are generated in the translation repo. Users copy them to their local build.
169+
170+ ## Architecture
171+
172+ ```
173+ WLED (core repo)
174+ └── tools/i18n/
175+ ├── extract.py # Extract strings from HTML/JS
176+ ├── build.py # Apply translations (pre-build script)
177+ ├── diff.py # Compare template versions
178+ └── README.md
179+
180+ WLED-translations (community repo)
181+ ├── zh_CN/
182+ │ ├── static.json # Layer 1: HTML text
183+ │ ├── js.json # Layer 2: JS strings
184+ │ ├── effects.json # Layer 3: effect names
185+ │ └── palettes.json # Layer 4: palette names
186+ └── en_template/ # English template
187+ ```
0 commit comments