Allow language packs to override settings display labels - #324190
Allow language packs to override settings display labels#324190boxi-wangji wants to merge 6 commits into
Conversation
Language packs can ship optional settingDisplay.* entries in a dedicated module. VS Code loads these module translations at startup and uses them to override settings list category, title, and enum labels without locale-specific logic in core. Co-authored-by: Cursor <cursoragent@cursor.com>
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @deepak1556Matched files:
@rzhao271Matched files:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a supported mechanism for language packs to override the settings UI display labels (category, title, and enum option labels) without patching VS Code core. It threads a new per-module translation table (nls.moduleTranslations.json) out of the language pack cache, propagates it as a _VSCODE_NLS_MODULE_TRANSLATIONS global across the main process and renderer(s), and consults it in the settings tree when computing display labels. This fits into the existing NLS/language-pack infrastructure (src/vs/nls.ts, src/vs/base/node/nls.ts, sandbox config) and the preferences editor.
Changes:
- Introduce a language-pack-provided module translation table and plumb it from cache generation → bootstrap → main → renderer globals.
- Add
settingsDisplayLabels.tsoverride helpers and wire them intosettingsTreeModels/settingsTreefor category, title, and enum labels. - Adjust settings editor CSS to support wrapped/pre-line labels.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/nls.ts | Adds getNLSModuleTranslations/getNLSModuleTranslationsMap accessors and moduleTranslationsFile config field. |
| src/typings/vscode-globals-nls.d.ts | Declares the new _VSCODE_NLS_MODULE_TRANSLATIONS global. |
| src/vs/base/node/nls.ts | Generates/reuses nls.moduleTranslations.json and extracts only the settings-display-labels module. |
| src/bootstrap-esm.ts | Loads module translations from the language pack file into the global. |
| src/vs/base/parts/sandbox/common/sandboxTypes.ts | Adds optional moduleTranslations to sandbox NLS config. |
| src/vs/platform/windows/electron-main/windowsMainService.ts | Passes module translations map into the window config. |
| src/vs/code/electron-browser/workbench/workbench.ts | Initializes the renderer global from config. |
| src/vs/sessions/electron-browser/sessions.ts | Same renderer initialization for the Agents window. |
| src/vs/workbench/contrib/preferences/browser/settingsDisplayLabels.ts | New override lookup helpers (category/label/enum). |
| src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts | Consults overrides before fallback labels; renames initLabels→initFallbackLabels. |
| src/vs/workbench/contrib/preferences/browser/settingsTree.ts | Applies enum label overrides in the dropdown renderer. |
| src/vs/workbench/contrib/preferences/browser/media/settingsEditor2.css | Allows pre-line labels and clears the description below floated labels. |
| return defaultNLSConfiguration(userLocale, osLocale, nlsMetadataPath); | ||
| } | ||
|
|
||
| const SETTING_DISPLAY_LABELS_MODULE = 'vs/workbench/contrib/preferences/browser/settingsDisplayLabels'; |
| export function getSettingDisplayCategoryOverride(settingKey: string): string | undefined { | ||
| if (!settingKey.includes('.')) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const categoryPath = settingKey.substring(0, settingKey.lastIndexOf('.')); | ||
| for (const path of [categoryPath, categoryPath.split('.')[0]]) { | ||
| const value = readOverride(`settingDisplayCategory.${path}`); | ||
| if (value) { | ||
| return value; | ||
| } | ||
| } | ||
|
|
||
| return undefined; | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
ls.moduleTranslations.json)
Motivation
Setting descriptions are already localized, but the settings list derives short labels from setting keys. Language packs need a supported way to provide clearer display labels without patching VS Code core.
Language pack contract
Test plan
Made with Cursor