Skip to content

Translation capability for branch 0_15#4274

Closed
Sojourneer wants to merge 11 commits intowled:mainfrom
Sojourneer:0_15
Closed

Translation capability for branch 0_15#4274
Sojourneer wants to merge 11 commits intowled:mainfrom
Sojourneer:0_15

Conversation

@Sojourneer
Copy link
Copy Markdown

@Sojourneer Sojourneer commented Nov 11, 2024

Translation capability for WLED. Google translated language files provided for JA, FR, DE. Has been tested on an ESP8266.

The coverage is high but not perfect; manual addition of text is required. A more robust solution using a screen scraper on a running WLED instance is probably a better way to go.

From the introduction to the I18N/tools (see wled00/I18N/tools/I18N.md for the details):

WLED Localization

Localization for WLED provides the ability to switch between display languages dynamically from the UI settings page. This setting is local to the browser, and is effective immediately (no Save or page refresh is required).

The rest of this document explains the process for providing this capability.

In summary, the UISimulator Web Server and a couple of python scripts are used to extract, translate, and test the translations on a static simulation of WLED. The translation files are then committed to Github, from which the L12N script included on each HTML page will access and apply the translation.


Summary by CodeRabbit

Release Notes

  • New Features

    • Added multi-language support enabling users to switch the UI display language to French, German, or Japanese.
    • Added a language selection dropdown in the UI Settings page with automatic language preference persistence.
  • Chores

    • Updated build system to include language resources and localization assets.

@softhack007 softhack007 added enhancement discussion python Pull requests that update Python code javascript Pull requests that update Javascript code labels Nov 11, 2024
@softhack007
Copy link
Copy Markdown
Member

softhack007 commented Nov 11, 2024

@Sojourneer please clean up you PR - it seems there are lots of copied files and "cached whatever" that look like backups or intermediate files.

I'll mark your PR as draft for the time being.

@softhack007 softhack007 marked this pull request as draft November 11, 2024 15:24
@@ -0,0 +1,2 @@
cd wled00
sudo python3 UISimulator/main.py "$@" No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sudo should not be needed in a public repository.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what that means. For example, is it permissible in documentation in a public repository?

Copy link
Copy Markdown
Member

@softhack007 softhack007 Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means that i don't want to have scripts that use sudo. If possible, change to python3 UISimulator/main.py "$@" .

Running programs with root permissions is only permissible when there is a very good justification.

@softhack007
Copy link
Copy Markdown
Member

The rest of this document explains the process for providing this capability.

Where is this document?

@Sojourneer
Copy link
Copy Markdown
Author

@Sojourneer please clean up you PR - it seems there are lots of copied files and "cached whatever" that look like backups or intermediate files.

I'll mark your PR as draft for the time being.

There are no files that are purely generated from something else.

@Sojourneer
Copy link
Copy Markdown
Author

From the introduction to the I18N/tools (see wled00/I18N/tools/I18N.md for the details):

@softhack007
Copy link
Copy Markdown
Member

softhack007 commented Dec 1, 2024

I'll mark your PR as draft for the time being.

There are no files that are purely generated from something else.

Maybe i should be a bit clearer about what I want.

A/ New directories you added --> please move I18N, UIsimulator, and scripts out of wled00. What will be included into the firmware itself, should be subfolders inside data. UIsimulator, and scripts could be placed into "tools"

image

B/ There are many sub-folders inside I18N/data and their purpose is unclear - in fact these looks like cached files. Please check if they can be removed and auto-generated by script. As a rule of thumb, any file that can be regenerated by a build script should not be added to the github repository.

image

C/ Translation files are appearing in several directories. Actually, it might be better to put them into a new lang directory on the top level, next to wled00/.
image

After this first cleanup, other maintainers might be able to review your work, ask questions and suggest improvements.

@netmindz netmindz changed the base branch from 0_15 to main December 16, 2024 13:26
@Sojourneer
Copy link
Copy Markdown
Author

Sojourneer commented Dec 20, 2024

I'll mark your PR as draft for the time being.

There are no files that are purely generated from something else.

Maybe i should be a bit clearer about what I want.

A/ New directories you added --> please move I18N, UIsimulator, and scripts out of wled00. What will be included into the firmware itself, should be subfolders inside data. UIsimulator, and scripts could be placed into "tools"

After this first cleanup, other maintainers might be able to review your work, ask questions and suggest improvements.

Sorry, I missed your message.

I decided a few weeks back to move all the work to a new repository https://github.com/Sojourneer/WLED-Translators-Pack, so all the ugly stuff is elsewhere and it is largely independent of the main repository. The Translator's Pack also includes a proxy server instead of the UI Simulator, in order to get better coverage of the application. The proxy server stuff is new to me and has me tearing my hair out, so the translation stuff has been bumped by other Christmas projects. (Although I have been using it personally).

I will get back to this after New Years.

@softhack007
Copy link
Copy Markdown
Member

closing due to inactivity - the PR structure (files, scripts, unclear helpers, ...) needs heavy cleanup before it would be acceptable for merging.

@softhack007
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 993c93e2-3b93-4fc1-af08-3ec92c4d8e41

📥 Commits

Reviewing files that changed from the base of the PR and between 18e0ec9 and 9f30aae.

⛔ Files ignored due to path filters (1)
  • wled00/I18N/tools/I18N.pdf is excluded by !**/*.pdf
📒 Files selected for processing (84)
  • .gitignore
  • tools/cdata.js
  • wled00/I18N/L12N/de.json
  • wled00/I18N/L12N/fr.json
  • wled00/I18N/L12N/ja.json
  • wled00/I18N/data/cachedFromWLED/cfg.json
  • wled00/I18N/data/cachedFromWLED/effects.json
  • wled00/I18N/data/cachedFromWLED/fxdata.json
  • wled00/I18N/data/cachedFromWLED/nodes.json
  • wled00/I18N/data/cachedFromWLED/palettes.json
  • wled00/I18N/data/cachedFromWLED/palx.json
  • wled00/I18N/data/cachedFromWLED/presets.json
  • wled00/I18N/data/cachedFromWLED/si.json
  • wled00/I18N/data/fromPages copy/_settings.json
  • wled00/I18N/data/fromPages copy/_settings_2D.json
  • wled00/I18N/data/fromPages copy/_settings_leds.json
  • wled00/I18N/data/fromPages copy/_settings_sec.json
  • wled00/I18N/data/fromPages copy/_settings_sync.json
  • wled00/I18N/data/fromPages copy/_settings_time.json
  • wled00/I18N/data/fromPages copy/_settings_ui.json
  • wled00/I18N/data/fromPages copy/_settings_um.json
  • wled00/I18N/data/fromPages copy/_settings_wifi.json
  • wled00/I18N/data/fromPages copy/index.htm.json
  • wled00/I18N/data/fromPages/_settings.json
  • wled00/I18N/data/fromPages/_settings_2D.json
  • wled00/I18N/data/fromPages/_settings_leds.json
  • wled00/I18N/data/fromPages/_settings_sec.json
  • wled00/I18N/data/fromPages/_settings_sync.json
  • wled00/I18N/data/fromPages/_settings_time.json
  • wled00/I18N/data/fromPages/_settings_ui.json
  • wled00/I18N/data/fromPages/_settings_um.json
  • wled00/I18N/data/fromPages/_settings_wifi.json
  • wled00/I18N/data/fromPages/index.htm.json
  • wled00/I18N/data/fromScripts/toast.json
  • wled00/I18N/data/iso639.json
  • wled00/I18N/data/langs.json
  • wled00/I18N/data/list.json
  • wled00/I18N/langs/de.json
  • wled00/I18N/langs/fr.json
  • wled00/I18N/langs/ja.json
  • wled00/I18N/scripts/I18N.js
  • wled00/I18N/scripts/L12N copy.js
  • wled00/I18N/scripts/L12N.js
  • wled00/I18N/tools/HTMLPatchingParser.py
  • wled00/I18N/tools/HTMLparser.py
  • wled00/I18N/tools/I18N.md
  • wled00/I18N/tools/L12N.py
  • wled00/I18N/tools/injectL12N.py
  • wled00/I18N/tools/installLang.py
  • wled00/UISimulator/main.py
  • wled00/UISimulator/response/WLEDrequestHandlers.py
  • wled00/UISimulator/response/__init__.py
  • wled00/UISimulator/response/requestHandler.py
  • wled00/UISimulator/runSimulator
  • wled00/UISimulator/server.py
  • wled00/data/404.htm
  • wled00/data/L12N.js
  • wled00/data/cpal/cpal.htm
  • wled00/data/dmxmap.htm
  • wled00/data/edit.htm
  • wled00/data/icons-ui/demo.html
  • wled00/data/index.htm
  • wled00/data/langcodes.json
  • wled00/data/liveview.htm
  • wled00/data/liveviewws2D.htm
  • wled00/data/msg.htm
  • wled00/data/pixart/pixart.htm
  • wled00/data/pxmagic/pxmagic.htm
  • wled00/data/settings.htm
  • wled00/data/settings_2D.htm
  • wled00/data/settings_dmx.htm
  • wled00/data/settings_leds.htm
  • wled00/data/settings_pin.htm
  • wled00/data/settings_sec.htm
  • wled00/data/settings_sync.htm
  • wled00/data/settings_time.htm
  • wled00/data/settings_ui.htm
  • wled00/data/settings_um.htm
  • wled00/data/settings_wifi.htm
  • wled00/data/update.htm
  • wled00/data/usermod.htm
  • wled00/data/welcome.htm
  • wled00/scripts/s.js
  • wled00/wled_server.cpp

Walkthrough

This PR introduces comprehensive internationalization (i18n) and localization (l12n) infrastructure to WLED, enabling multi-language UI support. It adds translation systems, language files (French, German, Japanese), client-side scripts, Python tooling for translation management, a UI simulator for testing, and updates existing HTML pages to load localization functionality.

Changes

Cohort / File(s) Summary
Git Configuration
.gitignore
Added *.pyc pattern to ignore Python compiled bytecode files.
Build Tool Updates
tools/cdata.js
Extended build process to embed L12N.js and langcodes.json as compressed assets (JS_L12N, JSON_LANGCODES) in generated C headers.
I18N Cached Data
wled00/I18N/data/cachedFromWLED/*
Added 10 new JSON cache files containing device configuration snapshots, effects lists, palettes, presets, and device state/info metadata for translation reference.
I18N Localization Data
wled00/I18N/data/fromPages copy/*, wled00/I18N/data/fromPages/*
Added 14 new JSON files providing localized UI text mappings for settings pages (WiFi, LED, 2D, Sync, Time, UI, Usermod, Security) and main interface, with path-based and pattern-based translation keys.
I18N Script Data
wled00/I18N/data/fromScripts/toast.json, wled00/I18N/data/iso639.json, wled00/I18N/data/langs.json, wled00/I18N/data/list.json
Added language metadata files including ISO639 language code mappings, supported language list, and HTML page manifest for i18n processing.
Translation Language Files
wled00/I18N/langs/de.json, wled00/I18N/langs/fr.json, wled00/I18N/langs/ja.json
Added complete translation mappings for German, French, and Japanese with exact and pattern-based key matching for localized strings (~1000 lines each).
Client-Side I18N Scripts
wled00/I18N/scripts/I18N.js, wled00/I18N/scripts/L12N copy.js, wled00/I18N/scripts/L12N.js
Implemented client-side DOM translation engines: I18N.js scrapes and collects UI strings for translation, while L12N.js (primary) applies cached/fetched translations to text nodes and attributes with undo capability and global function wrapping for UI updates.
Python I18N Tools
wled00/I18N/tools/HTMLPatchingParser.py, wled00/I18N/tools/HTMLparser.py, wled00/I18N/tools/I18N.md, wled00/I18N/tools/L12N.py, wled00/I18N/tools/injectL12N.py, wled00/I18N/tools/installLang.py
Added Python utilities: HTML parser for source modification, translation collection/generation pipeline (with Google Translate integration), localization script injection, and per-language translation optimization and installation tools. Includes i18n workflow documentation.
UI Simulator Server
wled00/UISimulator/main.py, wled00/UISimulator/response/requestHandler.py, wled00/UISimulator/response/WLEDrequestHandlers.py, wled00/UISimulator/server.py, wled00/UISimulator/runSimulator
Added HTTP server framework for local testing of i18n/l12n functionality: lightweight request routing, file serving, POST handlers for collecting translation data, and optional HTML patching for script injection. Includes shell script entry point.
Data Files and Scripts
wled00/data/L12N.js, wled00/data/langcodes.json
Added production localization script and language-code reference JSON for client-side runtime use.
HTML Page Updates — Core Pages
wled00/data/index.htm, wled00/data/settings.htm, wled00/data/404.htm, wled00/data/404.htm, wled00/data/liveview.htm, wled00/data/update.htm, wled00/data/welcome.htm
Added <script src='/L12N.js'></script> and wrapped onload handlers with try { ...original... } finally { runI18N(); } pattern to ensure localization runs on page load.
HTML Page Updates — Settings Pages
wled00/data/settings_*.htm (WiFi, LEDs, 2D, DMX, Sync, Time, Pin, Security, Usermod)
Injected /L12N.js script and updated page onload to invoke runI18N() after initialization; each page follows consistent localization setup pattern.
HTML Page Updates — Specialty Pages
wled00/data/dmxmap.htm, wled00/data/edit.htm, wled00/data/icons-ui/demo.html, wled00/data/liveviewws2D.htm, wled00/data/msg.htm, wled00/data/cpal/cpal.htm, wled00/data/pixart/pixart.htm, wled00/data/pxmagic/pxmagic.htm, wled00/data/usermod.htm
Consistently added /L12N.js script includes and runI18N() invocation in onload handlers across all auxiliary and theme-related pages.
Settings UI Enhancement
wled00/data/settings_ui.htm
Extended cLS() to clear I18N.langs.* localStorage keys; added populateLangCodeSelector() to fetch /langcodes.json and populate language dropdown; added OnChangeLangCode() to trigger language switching; integrated language selector UI control and updated page initialization flow.
Server Routes and Resources
wled00/wled_server.cpp
Added new routes: /L12N.js (serves embedded JS_L12N) and /langcodes.json (serves embedded JSON_LANGCODES); updated serveSettingsJS() to intercept and serve localization script early.
Miscellaneous
wled00/scripts/s.js
Added GetV() function that sets DS.value = "WLED" and ST.checked = 0.

Sequence Diagram(s)

sequenceDiagram
    participant Browser as Browser/DOM
    participant L12N as L12N.js
    participant localStorage as localStorage
    participant Server as WLED Server
    participant GH as GitHub Raw

    Browser->>L12N: Page load → runI18N()
    L12N->>localStorage: Check I18N.langCode
    alt Language is 'en'
        L12N->>Browser: No translation needed
    else Non-English language
        L12N->>localStorage: Check I18N.langs.{langCode}
        alt Cached translation exists
            localStorage-->>L12N: Return cached JSON
            L12N->>L12N: applyTranslation()
        else Cache miss
            L12N->>Server: Fetch /langs/{langCode}.json
            alt Server has file
                Server-->>L12N: Return translation JSON
            else Server miss
                L12N->>GH: Fetch from GitHub raw URL
                GH-->>L12N: Return translation JSON
            end
            L12N->>localStorage: Store in I18N.langs.{langCode}
            L12N->>L12N: applyTranslation()
        end
        L12N->>Browser: Walk DOM, apply translations
        L12N->>Browser: Update text nodes & attributes (title, placeholder, label, value)
    end
    
    note over Browser,L12N: Wrapped global functions (updateUI, genForm, makeSeg, etc.)<br/>trigger re-translation after UI updates
Loading
sequenceDiagram
    participant User as User/Browser
    participant SettingsUI as settings_ui.htm
    participant LangSelect as Language Dropdown
    participant L12N as L12N.singleton
    participant Server as /langcodes.json
    
    User->>SettingsUI: Page loads
    SettingsUI->>Server: populateLangCodeSelector()
    Server-->>SettingsUI: {lc:"fr",t:"French"}, {lc:"ja",t:"Japanese"}
    SettingsUI->>LangSelect: Populate <option> elements
    LangSelect->>LangSelect: Mark current I18N.langCode as selected
    
    User->>LangSelect: Select new language
    LangSelect->>SettingsUI: OnChangeLangCode(e)
    SettingsUI->>L12N: I18N.singleton.setLang(newLangCode)
    L12N->>L12N: undoAll() + fetch translation
    L12N->>L12N: applyTranslation()
    L12N->>User: UI text updates in real-time
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

The PR introduces a substantial, multi-component i18n/l12n system spanning Python tooling, JavaScript client libraries, HTML template modifications across 30+ pages, embedded data resources, and server routes. While many HTML changes follow a repetitive pattern (script injection + onload wrapping), the review requires careful assessment of: (1) the client-side translation logic and function-wrapping mechanisms in L12N.js, (2) the Python translation pipeline and HTML patching tools, (3) server-side resource embedding and routing, and (4) potential side effects from global function wrapping and DOM manipulation. The heterogeneity of languages and concerns (Python, JavaScript, C++, JSON) and the breadth of affected pages elevates complexity despite some repetitive patterns.

Possibly related PRs

  • PR #5013: Modifies UI page initialization, resource loading, and script injection patterns across the same settings and main pages, overlapping with this PR's HTML template updates.
  • PR #3777: Modifies settings_leds.htm, which this PR also updates; potential merge conflicts or sequential dependency.

Suggested reviewers

  • netmindz
  • willmmiles
✨ Finishing Touches
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch 0_15

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion enhancement javascript Pull requests that update Javascript code python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants