Skip to content

Commit

Permalink
Improve default translation using preferred keys (#13078)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Nov 22, 2023
1 parent 8e7b161 commit 964f69c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/core/src/common/nls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -100,9 +104,16 @@ class LocalizationKeyProvider {
const keys: NlsKeys = bundles.keys;
const messages: Record<string, string[]> = bundles.messages;
const data = new Map<string, string>();
const foundPreferredKeys = new Set<string>();
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
Expand Down

0 comments on commit 964f69c

Please sign in to comment.