Skip to content

feat(settings): add app language override - #567

Merged
tieubao merged 7 commits into
consolelabs:developfrom
AlexPlum405:feature/language-settings
Nov 23, 2026
Merged

tieubao merged 7 commits into
consolelabs:developfrom
AlexPlum405:feature/language-settings

Conversation

@AlexPlum405

@AlexPlum405 AlexPlum405 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Adds Settings › General › App language: follow macOS, or pick any localization the build ships. The list shows each language under its own name (English, 简体中文, 日本語, …), so the right row is findable while the app is in another language. The choice is stored as CFBundle's AppleLanguages key and takes effect after a restart; the row explains that and offers Restart Now in the direct build.

macOS already follows the system language, but it cannot help a bilingual user or someone whose system language is not the language they want for this app. The app had no override of its own.

How it was tested

scripts/test.sh --serial (both schemes, full suite, macOS 27.2.1):

scheme build_s test_s total_s passed failed result
Hidden Bar 18.6 20.2 38.8 805 0 ok
Hidden Bar App Store 14.8 10.9 25.7 519 0 ok
  • The new strings are translated in every locale; LocaleCoverageTests (keys, translations, placeholders) passes.
  • New LanguagePreferencesTests covers native names, the AppleLanguages write/remove round trip, reading only the app's own domain, the General pane write path, the relaunch helper's arguments, the build gate, and "same pick, no restart".
  • plutil -lint hidden/*.lproj/*.strings: OK.

One environment note: the suite only passes with an English test host. With the host in 简体中文, 35 assertions fail in the Hidden Bar scheme — and also on develop without this PR — because several tests compare against English literals (ArrivalsPromptTests, PalettePanelTests, PresentationViewsTests, …). No layout assertion fails there: the clipping test reports zero "needs X pt" / "runs past the width" lines. I left those tests alone; happy to fix them in a separate PR.

Restart Now

Same shape as AppStoreMigration.relaunch(at:): a /bin/sh helper polls kill -0 on this process and only then runs open, so the new instance does not race the old one and quit as a duplicate. NSApp.terminate runs only after the helper started; a helper that cannot start leaves the app open instead of quitting with nothing to reopen it. The migration now calls the same AppRelaunch, so there is one reload script in the app.

Tried in the sandboxed App Store build: the helper starts, but the sandbox answers kill -0 with Operation not permitted (sleep and open both work, exit 0), so the wait cannot work there. Restart Now is therefore offered in the direct build only; the "Takes effect after Hidden Bar restarts." caption stays in both builds. Picking the language already stored now does nothing, so no sheet appears for a no-op.

UI proof

Every image below is drawn by a Debug-Direct build of this branch: SettingsSnapshot renders the window into a bitmap, so the app was launched fresh for each state and no screen-recording permission is needed. Hidden Bar has no light/dark switch: the light and dark images are the same window under the system's light and dark appearance, as the PR template asks. The test Mac's system language is Simplified Chinese.

Picker on 简体中文

Language row, light

Language row, dark

Override set to Japanese: the whole pane is Japanese

Japanese, light

Japanese, dark

Back to "follow macOS": the override removed, launched again, pane back in the system language (Chinese) and the picker on 跟随系统

Follow system, light

Follow system, dark

The whole General pane after launching with Simplified Chinese, showing this branch's strings

General after restart

The open list and the Restart prompt

Open language list

Restart Now prompt

  • This PR changes something users see, and the proof is above
  • This PR changes nothing users see

@tieubao

tieubao commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the careful write-up. An app language override is a reasonable idea, and we would like to look at it properly. Two things are needed first.

1. Proof on screen. For a change that users see, we ask for screenshots or a short recording in the PR, taken from a build of the branch:

  • the new row in Settings > General, in light and in dark appearance;
  • the open language list;
  • the state after a choice, with the "Restart Now" row;
  • the app after the restart in one non-English language, and after switching back to "follow macOS".

2. Merge develop. Since you opened this, every locale file was completed (#559, #563 to #565) and a notice was added (#576), so CHANGELOG.md and each Localizable.strings now conflict. Two rules apply to the new strings: every key goes into all twelve locales in the same commit, translated, and LocaleCoverageTests fails on a value that still holds the English text. Language names shown in their own language (English, 简体中文, 日本語) can go on that test's allow-list with a reason.

CI for a fork needs a maintainer's approval. We will approve the run once the branch merges cleanly and we have read the diff.

@AlexPlum405
AlexPlum405 force-pushed the feature/language-settings branch from d3225c6 to 5a23127 Compare November 20, 2026 07:29
@AlexPlum405

Copy link
Copy Markdown
Contributor Author

Rebased onto develop (ee3af24) and resolved the localization/CHANGELOG conflicts. The new strings are translated in every locale; LocaleCoverageTests and the full Hidden Bar scheme pass (291 tests, 0 failures). UI proof is committed under docs/verification/language-setting/ and embedded in the description. CI is waiting for your approval.

@tieubao

tieubao commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the quick rebase and the screenshots. The branch merges cleanly now and the proof covers most of what we asked for: the new row in light and dark, the open list, the Restart Now sheet and the pane after a restart in 简体中文. Three things before we go further:

  1. Back to "follow macOS". One more screenshot: the app after you pick "System (follow macOS)" and restart, so the pane shows the system language again. The row alone does not show that the restart returns it.
  2. Both schemes. CONTRIBUTING asks for both schemes to pass, and the description lists the Debug-Direct scheme only. Please run scripts/test.sh (it runs the direct and the App Store scheme) and paste the summary table.
  3. Restart Now (AppRelaunch in LanguagePreferences.swift). Two points:
    • It calls NSApp.terminate(nil) even when the helper process failed to start (try? task.run()), so a failed launch quits the app and does not reopen it. AppStoreMigration.relaunch(at:) in hidden/Features/AppStoreMigration/AppStoreMigration.swift already solves this: it waits for the old process to exit (kill -0 loop, not a fixed sleep 1) and terminates only if the helper started. Please reuse that shape, or share it.
    • The App Store build is sandboxed (Hidden.entitlements). Please try Restart Now with the "Hidden Bar App Store" scheme. If /bin/sh and open do not work there, show the Restart Now button in the direct build only and keep the "takes effect after Hidden Bar restarts" caption for both.

Once these are in we will read the rest of the diff properly and approve the CI run. Thanks for translating the new strings into all locales, that part is exactly what we ask for.

@AlexPlum405

Copy link
Copy Markdown
Contributor Author

All three points are in (fbfc982).

1. Back to "follow macOS". Added: the picker on 跟随系统 after the override was removed, and the pane showing the system language again. Two new PNGs (language-row-follow-system-{light,dark}.png), plus an override-set-to-Japanese pair (language-row-ja-{light,dark}.png) so both directions are visible.

2. Both schemes. scripts/test.sh --serial on macOS 27.2.1:

scheme                    build_s   test_s  total_s  passed  failed  result
Hidden Bar                   20.8     21.3     42.1     803       0  ok
Hidden Bar App Store         15.2      9.1     24.3     518       0  ok

The table is in the description too. One note: the suite only passes with an English test host. With the host in 简体中文, 35 assertions fail in this scheme — and also on develop without this PR — because several tests compare against English literals (ArrivalsPromptTests, PalettePanelTests, PresentationViewsTests, …). No layout assertion fails there: the clipping test reports zero "needs X pt" / "runs past the width" lines. I did not change those tests here; say the word if you want that fixed in a separate PR.

3. Restart Now. Now the same shape as AppStoreMigration.relaunch(at:): the helper polls kill -0 and only then runs open, and NSApp.terminate runs only after the helper started, so a helper that cannot start leaves the app open. AppRelaunch.arguments(for:pid:) is split out and unit-tested.

For the sandbox: I tried it in a sandboxed test app with the same entitlements. The helper starts, but kill -0 returns Operation not permitted under the sandbox (sleep and open both work, exit 0). So the wait cannot work in the App Store build. Per your second option, Restart Now is shown in the direct build only; both builds keep the "Takes effect after Hidden Bar restarts." caption.

@tieubao tieubao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this is close, and the tests pass on our side too (803 in the Hidden Bar scheme, LocaleCoverageTests included). I approved the CI run. Before merge:

  1. The "back to follow macOS" screenshots are byte-identical to the earlier system pair, and your Mac runs in Chinese, so they cannot show a change. Please set the override to Japanese, pick "follow macOS", restart, and show the pane back in Chinese.
  2. The after-restart screenshot shows strings that are not in this branch (点击菜单栏空白处, 敏感应用), so it predates the rebase. Please retake it.
  3. The CHANGELOG entry sits under v1.13.3, which is already released. Please add an ## Unreleased heading above it.
  4. Please drop appLanguage and read the app's own AppleLanguages only (LanguagePreferences.swift:26 and :49). Otherwise a change in the macOS per-app language panel leaves this picker showing the old value.

Smaller, optional: skip the restart sheet when the pick changes nothing (PreferencesViewController.swift:142), and reuse AppStoreMigration.relaunch(at:) instead of a second copy of the relaunch script.

AlexPlum405 and others added 5 commits November 23, 2026 09:38
- General › Language: follow macOS or pick any localization the build ships.
  The choice is stored as CFBundle's AppleLanguages key, so it takes effect
  after a restart; macOS's per-app language panel writes the same value.
- Keep a separate appLanguage key so "follow the system" stays distinguishable
  from the global AppleLanguages domain, and read a per-app choice macOS stored
  in the app's own domain.
- Translate the new row in all 13 locales and add LanguagePreferencesTests;
  extend the every-locale key check.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Rendered from a Debug-Direct build of this branch on macOS 27.2.1:
the General Language row in light and dark, set to 简体中文 and to
follow the system.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Captured on macOS 27.2.1: the open language list (each language under
its own name), the Restart Now prompt after a choice, and the General
pane after restarting in Simplified Chinese.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
… the sandbox

- AppRelaunch now waits for this process to exit (kill -0 loop) instead of
  sleeping a fixed second, and quits only after the helper started; a helper
  that cannot start leaves the app open.
- The App Store build is sandboxed and its sandbox denies the kill -0 probe, so
  Restart Now is offered in the direct build only; the caption still tells both
  builds that the choice takes effect after a restart.
- Cover the helper arguments and the build gate, and add the Japanese and
  back-to-follow-system screenshots.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
…the relaunch

- Drop appLanguage: the row now reads and writes CFBundle's AppleLanguages in
  the app's own domain, so a change made in the macOS per-app language panel
  shows up here too. The read uses persistentDomain, never a plain lookup,
  which would fall back to the global domain and turn "follow the system" into
  the system language.
- Skip the restart sheet when the picked language is the stored one.
- AppStoreMigration.relaunch(at:) now calls AppRelaunch, so the app has one
  reload script.
- Move the CHANGELOG entry under a new Unreleased heading; v1.13.3 is released.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
@AlexPlum405
AlexPlum405 force-pushed the feature/language-settings branch from fbfc982 to 7ac11a5 Compare November 23, 2026 01:56
…h script

- Drop appLanguage: the row reads and writes CFBundle's AppleLanguages in the
  app's own domain, so a language picked in the macOS per-app panel shows up
  here too. The read uses persistentDomain, never a plain lookup, which would
  fall back to the global domain and turn "follow the system" into the system
  language.
- Ask for a restart only when the pick differs from what is stored.
- AppStoreMigration.relaunch(at:) calls AppRelaunch, so the app has one reload
  script.
- Move the CHANGELOG entry under a new Unreleased heading; v1.13.3 is released.
- Re-render the UI proof from this branch: picker on 简体中文, override set to
  Japanese, and the override removed (back to the system language, Chinese),
  plus the whole General pane after a restart.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
@AlexPlum405

Copy link
Copy Markdown
Contributor Author

All four points are in (bead40b).

1. Back to "follow macOS". Regenerated from this branch. I set the override to Japanese, rendered, then removed the override and launched again: the Japanese pair and the follow-system pair now differ (and I deleted the earlier duplicate language-row-system-* files). Both pairs plus the whole General pane are rendered by SettingsSnapshot from a fresh launch per state, so no screen-recording permission is involved.

2. After-restart screenshot. Retaken. The old one was from the installed build; the new general-zh-Hans-after-restart.png is the whole General pane rendered by this branch's build and shows this branch's strings (点按菜单栏中的空白处, 敏感 App).

3. CHANGELOG. Moved under a new ## Unreleased heading above v1.13.3.

4. appLanguage is gone. The row now reads and writes only CFBundle's AppleLanguages in the app's own domain, so a change in the macOS per-app panel shows up here. Note it reads persistentDomain(forName:) rather than stringArray(forKey:): a plain lookup falls back to the global domain, where macOS keeps the system language, and "follow the system" would read back as that language. There is a test for exactly this (test_overrideReadsOnlyTheNamedDomain).

Optional items, both done. Picking the stored language no longer opens the sheet (LanguagePreferences.needsRestart). AppStoreMigration.relaunch(at:) now calls AppRelaunch, so the app has one relaunch script.

Both schemes, scripts/test.sh --serial:

scheme                    build_s   test_s  total_s  passed  failed  result
Hidden Bar                   18.6     20.2     38.8     805       0  ok
Hidden Bar App Store         14.8     10.9     25.7     519       0  ok

One thing I want to flag rather than hide: the suite passes only with an English test host. On a host set to 简体中文, 35 assertions fail in the Hidden Bar scheme, on develop as well as on this PR, because several tests compare against English literals. No layout assertion fails there (the clipping test reports zero "needs X pt" / "runs past the width"). I did not touch those tests in this PR; say the word and I will do it separately.

@tieubao

tieubao commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks, all four are in, and the two optional points too. Reading only the app's own persistentDomain is the right call, and sharing one relaunch script is a good cleanup.

develop moved while you worked, so CHANGELOG.md conflicted. I pushed a merge commit (77295cf) to your branch that keeps both Unreleased entries; nothing else changed. I approved the CI run on it, and we merge once it is green. Our local run of the merged tree passed (826 cases, LocaleCoverageTests and the Settings layout tests included).

One small note for later, not blocking: if macOS stores a region-qualified code such as zh-Hans-CN from its per-app panel, the picker would show System. A prefix match could cover that.

@tieubao
tieubao merged commit c1d2704 into consolelabs:develop Nov 23, 2026
3 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.

2 participants