mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Fixes #126408: Support changes in vscode-nls-dev that allow hint comments in package.nls.json
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user