Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default translations with incorrect case #11042

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions packages/core/src/common/nls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class LocalizationKeyProvider {
private data = this.buildData();

get(defaultValue: string): string | undefined {
return this.data.get(Localization.normalize(defaultValue.toLowerCase()));
const normalized = Localization.normalize(defaultValue);
return this.data.get(normalized) || this.data.get(normalized.toUpperCase());
}

/**
Expand All @@ -86,16 +87,36 @@ class LocalizationKeyProvider {
const keys: NlsKeys = bundles.keys;
const messages: Record<string, string[]> = bundles.messages;
const data = new Map<string, string>();
const keysAndMessages = this.buildKeyMessageTuples(keys, messages);
for (const { key, message } of keysAndMessages) {
data.set(message, key);
}
// 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
for (const { key, message } of keysAndMessages) {
const upperMessage = message.toUpperCase();
if (!data.has(upperMessage)) {
data.set(upperMessage, key);
}
}
return data;
}

private buildKeyMessageTuples(keys: NlsKeys, messages: Record<string, string[]>): { key: string, message: string }[] {
const list: { key: string, message: string }[] = [];
for (const [fileKey, messageBundle] of Object.entries(messages)) {
const keyBundle = keys[fileKey];
for (let i = 0; i < messageBundle.length; i++) {
const message = Localization.normalize(messageBundle[i]).toLowerCase();
const message = Localization.normalize(messageBundle[i]);
const key = keyBundle[i];
const localizationKey = this.buildKey(typeof key === 'string' ? key : key.key, fileKey);
data.set(message, localizationKey);
list.push({
key: localizationKey,
message
});
}
}
return data;
return list;
}

private buildKey(key: string, filepath: string): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export namespace WorkspaceCommands {
id: 'workspace:openFile',
originalCategory: FILE_CATEGORY,
category: nls.localizeByDefault(CommonCommands.FILE_CATEGORY),
dialogLabel: 'Open File'
dialogLabel: nls.localizeByDefault('Open File')
};
export const OPEN_FOLDER: Command & { dialogLabel: string } = {
id: 'workspace:openFolder',
Expand Down