Skip to content

Follow the system language when LANG is set - #2

Merged
celaldrg merged 1 commit into
masterfrom
fix/linux-language-detection
Nov 12, 2026
Merged

celaldrg merged 1 commit into
masterfrom
fix/linux-language-detection

Conversation

@celaldrg

Copy link
Copy Markdown
Owner

Problem

langParser() in lib/gui/app/i18n.ts returned 'en' whenever process.env.LANG was defined. Linux desktop sessions almost always set LANG, and so do macOS terminals, so on Linux the UI stayed in English for every locale: with LANG=tr_TR.UTF-8 or LANG=zh_CN.UTF-8 the function returned en. The renderer sends the same value to the main process (change-lng), so the menu stayed English too.

Why the check existed

It came in 0f10f2d (2022), together with the first translations, as a "bypass mocha" switch: the specs ran under electron-mocha from a shell, where LANG is set, and they assert English strings (tests/shared/messages.spec.ts still does). LANG was only a proxy for "running tests". Nothing else depends on it:

  • tests/ and wdio.conf.ts never set or read LANG. Specs now run in WebdriverIO workers, and @wdio/local-runner 8.36.1 forks them with NODE_ENV: process.env.NODE_ENV || 'test'.
  • lib/shared/sudo/darwin.ts picks the macOS password prompt language from Intl and supportedLocales and never looked at LANG. On a Mac started from a terminal, the UI was English while the password prompt followed the system language.

Fix

Use NODE_ENV === 'test' as the test signal instead of the presence of LANG. In every other case the language comes from Intl, exactly as it did before when LANG was unset.

  • Tests stay in English, now also on Windows, where LANG is usually unset and the old check did nothing.
  • The branch cannot run in the app: the forge webpack plugin builds with mode set to production (package/make) or development (start), and webpack's optimization.nodeEnv then replaces process.env.NODE_ENV with that string.
  • In Electron, Intl follows the application locale, which Chromium resolves from LANGUAGE, LC_ALL, LC_MESSAGES and LANG on Linux and from the system language settings on Windows and macOS. The UI and the macOS password prompt now use the same source.

Parsing LANG inside langParser() was the other option. I did not take it because it would duplicate what Chromium already does, ignore LANGUAGE, prefer a terminal's LANG over the macOS system language, and still leave test runs depending on the developer's locale.

Verification

  • npx balena-lint --typescript typings lib tests forge.config.ts forge.sidecar.ts forge.pkg-node.ts webpack.config.ts (without --fix): passed.
  • npx tsc -p tsconfig.i18n.json: passed.
  • A throwaway Node script (not committed) loaded lib/gui/app/i18n.ts with ts-node and called langParser() with different LANG/NODE_ENV values and a stubbed Intl locale:
Intl locale Environment Before After
tr-TR (real, this machine) LANG=tr_TR.UTF-8 en tr
zh-CN LANG=zh_CN.UTF-8 en zh-CN
zh-SG LANG=zh_SG.UTF-8 en zh-CN
zh-TW LANG=zh_TW.UTF-8 en zh-TW
zh-HK LANG=zh_HK.UTF-8 en zh-TW
en-US-u-va-posix LANG=C.UTF-8 en en
en-US LANG=en_US.UTF-8 en en
tr-TR NODE_ENV=test, LANG=tr_TR.UTF-8 en en
tr-TR NODE_ENV=test, no LANG tr en
zh-CN NODE_ENV=test, no LANG zh-CN en
tr-TR NODE_ENV=production or development, LANG=tr_TR.UTF-8 en tr
  • tests/shared/messages.spec.ts (English assertions, excluded from the wdio run) under plain mocha with Intl forced to zh-CN and LANG=zh_CN.UTF-8: 8 passing with NODE_ENV=test; without it, 6 failing with Chinese strings, which is what a user with that locale should now see.
  • git merge-tree with feat/turkish-ui: no conflicts.

Not verified

  • The app was not started or packaged. The UI language on a real Linux desktop session and the main-process menu are not verified, and neither is Electron's Intl locale following LANG/LANGUAGE on Linux: the fix relies on Chromium's locale resolution for that, which was not observed here.
  • npm run wdio was not run (install scripts were skipped, so there is no Electron binary).
  • macOS was not tested.

Notes

  • Running specs with plain mocha outside wdio now needs NODE_ENV=test to get English; before, any LANG did it.
  • If NODE_ENV is already set to another value when wdio starts, the workers keep it and the specs follow the system locale.

🤖 Generated with Claude Code

langParser() returned 'en' whenever LANG was defined. The check was a
proxy for "running under mocha", but Linux desktop sessions and macOS
terminals set LANG too, so the UI never followed the system language
there: LANG=tr_TR.UTF-8 or zh_CN.UTF-8 still gave English.

Use NODE_ENV=test as the test signal instead. WebdriverIO starts its
spec workers with NODE_ENV=test unless it is already set, and the forge
webpack build replaces process.env.NODE_ENV with "production" or
"development", so the branch cannot run in the app. Everywhere else the
language comes from Intl, which in Electron follows the application
locale (LANGUAGE, LC_ALL, LC_MESSAGES and LANG on Linux) and which the
macOS sudo prompt already uses.
@celaldrg
celaldrg force-pushed the fix/linux-language-detection branch from 030d3f8 to 45f1c64 Compare October 29, 2026 08:17
@celaldrg
celaldrg force-pushed the fix/linux-language-detection branch from 45f1c64 to 2f3f8fd Compare October 29, 2026 08:26
@celaldrg
celaldrg merged commit c7aa288 into master Nov 12, 2026
2 checks passed
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