From 964f69ca3b3a5fb87ffa0177fb300b74ba0ca39f Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 22 Nov 2023 13:32:10 +0100 Subject: [PATCH] Improve default translation using preferred keys (#13078) --- packages/core/src/common/nls.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/common/nls.ts b/packages/core/src/common/nls.ts index 0e87d49f9d691..2ba45b8f3bad8 100644 --- a/packages/core/src/common/nls.ts +++ b/packages/core/src/common/nls.ts @@ -81,6 +81,10 @@ interface NlsInfo { class LocalizationKeyProvider { + private preferredKeys = new Set([ + // We only want the `File` translation used in the menu + 'vscode/fileActions.contribution/filesCategory' + ]); private data = this.buildData(); get(defaultValue: string): string | undefined { @@ -100,9 +104,16 @@ class LocalizationKeyProvider { const keys: NlsKeys = bundles.keys; const messages: Record = bundles.messages; const data = new Map(); + const foundPreferredKeys = new Set(); const keysAndMessages = this.buildKeyMessageTuples(keys, messages); for (const { key, message } of keysAndMessages) { - data.set(message, key); + if (!foundPreferredKeys.has(message)) { + data.set(message, key); + if (this.preferredKeys.has(key)) { + // Prevent messages with preferred keys to be overriden + foundPreferredKeys.add(message); + } + } } // Second pass adds each message again in upper case, if the message doesn't already exist in upper case // The second pass is needed to not accidentally override any translations which actually use the upper case message