src/vs/platform/extensionManagement/common/extensionNls.ts
90 LOC · 87 covered · 3 uncovered · 13 ranges · 55 concepts · 6 introducers · 34 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
extensionNls.ts ×2
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isObject, isString } from '../../../base/common/types.js';
import { ILocalizedString } from '../../action/common/action.js';
import { IExtensionManifest } from '../../extensions/common/extensions.js';
import { localize } from '../../../nls.js';
import { ILogger } from '../../log/common/log.js';
export interface ITranslations {
[key: string]: string | { message: string; comment: string[] } | undefined;
}
export function localizeManifest(logger: ILogger, extensionManifest: IExtensionManifest, translations: ITranslations, fallbackTranslations?: ITranslations): IExtensionManifest {
replaceNLStrings(logger, extensionManifest, translations, fallbackTranslations);
} catch (error) {
logger.error(error?.message ?? error);
/*Ignore Error*/
}
}
/**
* This routine makes the following assumptions:
* The root element is an object literal
*/
function replaceNLStrings(logger: ILogger, extensionManifest: IExtensionManifest, messages: ITranslations, originalMessages?: ITranslations): void {
extensionNls.ts ×7
const processEntry = (obj: Record<string, unknown>, key: string | number, command?: boolean) => {
const value = obj[key];
if (isString(value)) {
const str = value;
const length = str.length;
if (length > 1 && str[0] === '%' && str[length - 1] === '%') {
const messageKey = str.substr(1, length - 2);
let translated = messages[messageKey];
// If the messages come from a language pack they might miss some keys
// Fill them from the original messages.
if (translated === undefined && originalMessages) {
}
const message: string | undefined = typeof translated === 'string' ? translated : translated?.message;
extensionNls.ts ×7
// This branch returns ILocalizedString's instead of Strings so that the Command Palette can contain both the localized and the original value.
const original = originalMessages?.[messageKey];
const originalMessage: string | undefined = typeof original === 'string' ? original : original?.message;
if (!message) {
logger.warn(`[${extensionManifest.name}]: ${localize('missingNLSKey', "Couldn't find message for key {0}.", messageKey)}`);
}
return;
}
if (
// if we are translating the title or category of a command
command && (key === 'title' || key === 'category') &&
) {
value: message,
original: originalMessage
};
obj[key] = localizedString;
obj[key] = message;
}
}
} else if (isObject(value)) {
for (const k in value) {
if (value.hasOwnProperty(k)) {
k === 'commands' ? processEntry(value as Record<string, unknown>, k, true) : processEntry(value as Record<string, unknown>, k, command);
}
}
} else if (Array.isArray(value)) {
for (let i = 0; i < (value as Array<unknown>).length; i++) {
processEntry(value, i, command);
}
}
};
for (const key in extensionManifest) {
if (extensionManifest.hasOwnProperty(key)) {
processEntry(extensionManifest, key);
}
}
}