Fixes #126408: Support changes in vscode-nls-dev that allow hint comments in package.nls.json

This commit is contained in:
Dirk Baeumer
2021-06-16 11:53:10 +02:00
parent b724a7a6dc
commit 9c3a109adf
3 changed files with 10 additions and 6 deletions

View File

@@ -320,7 +320,7 @@ function translatePackageJSON(packageJSON, packageNLSPath) {
else if (typeof val === 'string' && val.charCodeAt(0) === CharCode_PC && val.charCodeAt(val.length - 1) === CharCode_PC) {
const translated = packageNls[val.substr(1, val.length - 2)];
if (translated) {
obj[key] = translated;
obj[key] = typeof translated === 'string' ? translated : (typeof translated.message === 'string' ? translated.message : val);
}
}
}

View File

@@ -385,8 +385,11 @@ export function scanBuiltinExtensions(extensionsRoot: string, exclude: string[]
}
export function translatePackageJSON(packageJSON: string, packageNLSPath: string) {
interface NLSFormat {
[key: string]: string | { message: string, comment: string[] };
}
const CharCode_PC = '%'.charCodeAt(0);
const packageNls = JSON.parse(fs.readFileSync(packageNLSPath).toString());
const packageNls: NLSFormat = JSON.parse(fs.readFileSync(packageNLSPath).toString());
const translate = (obj: any) => {
for (let key in obj) {
const val = obj[key];
@@ -397,7 +400,7 @@ export function translatePackageJSON(packageJSON: string, packageNLSPath: string
} else if (typeof val === 'string' && val.charCodeAt(0) === CharCode_PC && val.charCodeAt(val.length - 1) === CharCode_PC) {
const translated = packageNls[val.substr(1, val.length - 2)];
if (translated) {
obj[key] = translated;
obj[key] = typeof translated === 'string' ? translated : (typeof translated.message === 'string' ? translated.message : val);
}
}
}

View File

@@ -9,11 +9,11 @@ import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
const nlsRegex = /^%([\w\d.-]+)%$/i;
export interface ITranslations {
[key: string]: string;
[key: string]: string | { message: string; comment: string[] };
}
export function localizeManifest(manifest: IExtensionManifest, translations: ITranslations): IExtensionManifest {
const patcher = (value: string) => {
const patcher = (value: string): string | undefined => {
if (typeof value !== 'string') {
return undefined;
}
@@ -24,7 +24,8 @@ export function localizeManifest(manifest: IExtensionManifest, translations: ITr
return undefined;
}
return translations[match[1]] || value;
const translation = translations[match[1]] ?? value;
return typeof translation === 'string' ? translation : (typeof translation.message === 'string' ? translation.message : value);
};
return cloneAndChange(manifest, patcher);