Skip to content

feat(i18n): add Simplified Chinese to the app and the bundled web UI - #4

Closed
naturalwill wants to merge 5 commits into
0xProbabillity:mainfrom
naturalwill:feat/i18n-zh-CN
Closed

naturalwill wants to merge 5 commits into
0xProbabillity:mainfrom
naturalwill:feat/i18n-zh-CN

Conversation

@naturalwill

Copy link
Copy Markdown

What

House Control for Android now speaks Simplified Chinese: the native screens, the widgets and
the bundled web UI (the 3D home, the panel, the floor plan editor and the connections).

The app follows the phone's language. On Android 13 and later it is also listed under
Settings → Apps → House Control → Language; on earlier releases it follows the system
language, as every other Android app does.

How it is put together

The native screens. Every label the app shows now comes from the string resources
instead of a Kotlin literal — 236 new entries in app/src/main/res/values/strings.xml, with
their Chinese wording in app/src/main/res/values-zh-rCN/strings.xml. A new
app/src/main/res/xml/locales_config.xml names the app's languages, and the manifest points
at it. No new dependency.

The web UI. The page is upstream's, and upstream keeps writing its labels as plain English
literals. Rather than rewriting them, the DOM helper (web/src/ui/dom.js) passes every text
node and every readable attribute through a lookup, and a new dictionary
(web/src/locales/zh-CN.js) holds the Chinese wording. The lookup falls back to the English
text when a label is not in the dictionary, so:

  • the English UI is unchanged, word for word;
  • a missing translation can never break the page;
  • upstream keeps writing its labels as English literals — a new label needs no dictionary
    entry to keep working, and the dictionary does not have to be kept in step with the source.

The app tells the page which language it runs in through window.__HOUSE_BOOT__.locale, which
HomeWeb.kt fills in from the app's own configuration. web/README.md lists this alongsidethe other Android additions to that directory.

What a reviewer can check

  • The English UI is untouched: run it with the phone in English and compare.
  • The Chinese UI: set the phone to Chinese, or pick Chinese (Simplified)​ in the app's
    language settings on Android 13+.
  • The Build workflow runs the unit tests and builds a debug APK on every push; it passes.
  • The web UI builds on its own (cd web && npm install && npm run build).

Notes and limits

  • The dictionary is keyed by the English text, so a device, room or scene of your own that
    happens to read exactly like a UI label ("Home", "On") is translated as well. Removing that
    entry from the dictionary is enough to leave it alone.
  • Only Simplified Chinese is shipped. A device set to Traditional Chinese stays in English,
    which is what the resource qualifiers do as well — the two halves of the screen agree.
  • The last commit fixes a Kotlin problem this refactoring introduced: model.macName is a
    delegated property, and Kotlin cannot smart cast one.

Commits

  1. feat(i18n): add Simplified Chinese string resources — the resources and the locales config
  2. refactor(i18n): read the native screens' text from resources — the Compose screens, the
    widgets and the WebView's language
  3. feat(i18n): translate the bundled web UI — the lookup and the dictionary
  4. docs(i18n): document Chinese language support — a Languages section and a Chinese README
  5. fix(i18n): read the paired computer's name into a local before using it

The native screens wrote their labels as English literals inside Kotlin,
so there was no way to offer the app in another language. Move every
label the app shows into the string resources and add a values-zh-rCN
set carrying the Simplified Chinese wording.

Android 13 and later list the app's languages in the system settings;
locales_config.xml names English and zh-CN. On earlier releases the app
follows the system language through the resource qualifiers, as it does
for every other Android app.
Every user-visible string in the Compose screens, the widgets, the
shortcuts and the banners now comes from res/values/strings.xml, so the
resource set can be translated. The English wording is unchanged; only
where the text is looked up has moved.

A button's callback is a plain lambda, in which a resource cannot be
read, so the confirmations take their title, message and action from
the composable scope instead.

The WebView is told which language the app runs in, so that its half of
the screen follows the same choice as the native half.
The web UI writes its labels as plain English literals, which upstream
keeps editing. Rather than rewriting them, the DOM helper passes each
label through a lookup that falls back to the English word, so a missing
entry can never break the page and upstream's wording stays the source
of truth.

Adds a 400-entry zh-CN dictionary covering the panel, the floor plan
editor, the connections and the AI Access window, together with the few
places that write text straight to the DOM instead of through the
helper.

The phone's language reaches the page through window.__HOUSE_BOOT__.locale,
and the page sets its document language to match.
Adds a Languages section to the README explaining how the app picks its
language and how another one would be added, a Simplified Chinese
translation of the README, and a changelog entry.
model.macName is a delegated property, so Kotlin cannot smart cast it
from a null check to a non-null String. Two places used it that way
after the texts moved into the resources, and the build failed:

  e: .../ui/DevicesScreen.kt:175:84 Smart cast to 'Any' is impossible,
     because 'macName' is a delegated property.
  e: .../ui/HomeScreens.kt:105:72 Smart cast to 'Any' is impossible,
     because 'macName' is a delegated property.

Take it into a local val first: a local can be smart cast.
@naturalwill naturalwill closed this Nov 5, 2026
@naturalwill
naturalwill deleted the feat/i18n-zh-CN branch November 6, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant