Add i18n translation 'zh-CN' #13

Merged
owendswang merged 0 commits from feat/i18n into main 2026-08-22 06:54:19 -05:00
owendswang commented 2026-07-24 10:29:45 -05:00 (Migrated from git.etawen.dev)

Trying to add i18n style multi-language support and I tranlated 'zh-CN'. English is displayed by default if no supported language file.
And added a language select in Settings page. It follows the language preset of the browser/system by default.
And I added a new entry for previewing UI locally in 'Makefile': make ui-preview.

To add other language, just add a new JS file in 'src/i18n/' directory and add a new option in the settings page.

And I though about splitting the language file out from 'ui.html', but it's too complecated, I think.

All the changes are front-end side.

Trying to add i18n style multi-language support and I tranlated 'zh-CN'. English is displayed by default if no supported language file. And added a language select in Settings page. It follows the language preset of the browser/system by default. And I added a new entry for previewing UI locally in 'Makefile': `make ui-preview`. To add other language, just add a new JS file in 'src/i18n/' directory and add a new option in the settings page. And I though about splitting the language file out from 'ui.html', but it's too complecated, I think. All the changes are front-end side.
earthonion commented 2026-08-22 06:54:18 -05:00 (Migrated from git.etawen.dev)

Reviewed and merging. Verified locally: sentinel "__I18N_DICTIONARIES__"; is injected exactly once, sed r splices each src/i18n/*.js file after it, sentinel line then deleted; post-build _ui_tmp.html contains one window.GARLIC_I18N = {} init followed by the window.GARLIC_I18N[zh-CN] = { ... } dict. t() uses textContent (no XSS), esc() wraps <option> values/labels. Language preference persisted in localStorage under garlic_lang, system fallback via navigator.languages.

One minor nit for a follow-up (not blocking): ui-preview binds python3 -m http.server to 0.0.0.0 — for a local preview 127.0.0.1 would be safer on shared networks.

Reviewed and merging. Verified locally: sentinel `"__I18N_DICTIONARIES__";` is injected exactly once, `sed r` splices each `src/i18n/*.js` file after it, sentinel line then deleted; post-build `_ui_tmp.html` contains one `window.GARLIC_I18N = {}` init followed by the `window.GARLIC_I18N[zh-CN] = { ... }` dict. `t()` uses `textContent` (no XSS), `esc()` wraps `<option>` values/labels. Language preference persisted in `localStorage` under `garlic_lang`, `system` fallback via `navigator.languages`. One minor nit for a follow-up (not blocking): `ui-preview` binds `python3 -m http.server` to `0.0.0.0` — for a local preview `127.0.0.1` would be safer on shared networks.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
git-etawen-dev-earthonion/garlic-savemgr!13
No description provided.