package: expose core localizations as assets
This commit is contained in:
parent
2e7a8e069c
commit
f4d50e2073
3 changed files with 89 additions and 3 deletions
|
@ -4,6 +4,24 @@ export interface Person {
|
|||
email?: string;
|
||||
}
|
||||
|
||||
export interface Translation {
|
||||
id: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface Localization {
|
||||
languageId: string;
|
||||
languageName?: string;
|
||||
languageNameLocalized?: string;
|
||||
translations: Translation[];
|
||||
minimalTranslations?: { [key: string]: string };
|
||||
}
|
||||
|
||||
export interface Contributions {
|
||||
'localizations'?: Localization[];
|
||||
[contributionType: string]: any;
|
||||
}
|
||||
|
||||
export interface Manifest {
|
||||
// mandatory (npm)
|
||||
name: string;
|
||||
|
@ -13,7 +31,7 @@ export interface Manifest {
|
|||
// vscode
|
||||
publisher: string;
|
||||
icon?: string;
|
||||
contributes?: { [contributionType: string]: any; };
|
||||
contributes?: Contributions;
|
||||
activationEvents?: string[];
|
||||
extensionDependencies?: string[];
|
||||
galleryBanner?: { color?: string; theme?: string; };
|
||||
|
|
|
@ -531,6 +531,47 @@ class IconProcessor extends BaseProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
export class NLSProcessor extends BaseProcessor {
|
||||
|
||||
private translations: { [path: string]: string } = Object.create(null);
|
||||
|
||||
constructor(manifest: Manifest) {
|
||||
super(manifest);
|
||||
|
||||
if (!manifest.contributes || !manifest.contributes.localizations || manifest.contributes.localizations.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localizations = manifest.contributes.localizations;
|
||||
const translations: { [languageId: string]: string } = Object.create(null);
|
||||
|
||||
// take last reference in the manifest for any given language
|
||||
for (const localization of localizations) {
|
||||
for (const translation of localization.translations) {
|
||||
if (translation.id === 'vscode' && !!translation.path) {
|
||||
translations[localization.languageId.toUpperCase()] = `extension/${util.normalize(translation.path)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// invert the map for later easier retrieval
|
||||
for (const languageId of Object.keys(translations)) {
|
||||
this.translations[translations[languageId]] = languageId;
|
||||
}
|
||||
}
|
||||
|
||||
onFile(file: IFile): Promise<IFile> {
|
||||
const normalizedPath = util.normalize(file.path);
|
||||
const language = this.translations[normalizedPath];
|
||||
|
||||
if (language) {
|
||||
this.assets.push({ type: `Microsoft.VisualStudio.Code.Translation.${language}`, path: normalizedPath });
|
||||
}
|
||||
|
||||
return Promise.resolve(file);
|
||||
}
|
||||
}
|
||||
|
||||
export function validateManifest(manifest: Manifest): Manifest {
|
||||
validatePublisher(manifest.publisher);
|
||||
validateExtensionName(manifest.name);
|
||||
|
@ -700,7 +741,8 @@ export function createDefaultProcessors(manifest: Manifest, options: IPackageOpt
|
|||
new ReadmeProcessor(manifest, options),
|
||||
new ChangelogProcessor(manifest, options),
|
||||
new LicenseProcessor(manifest),
|
||||
new IconProcessor(manifest)
|
||||
new IconProcessor(manifest),
|
||||
new NLSProcessor(manifest)
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -918,7 +918,7 @@ describe('toVsixManifest', () => {
|
|||
contributes: {
|
||||
localizations: [{
|
||||
languageId: 'de',
|
||||
translations: [{ id: 'vscode' }, { id: 'vscode.go' }]
|
||||
translations: [{ id: 'vscode', path: 'fake.json' }, { id: 'vscode.go', path: 'what.json' }]
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
@ -935,6 +935,32 @@ describe('toVsixManifest', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should expose localization contributions as assets', () => {
|
||||
const manifest = {
|
||||
name: 'test',
|
||||
publisher: 'mocha',
|
||||
version: '0.0.1',
|
||||
engines: Object.create(null),
|
||||
contributes: {
|
||||
localizations: [{
|
||||
languageId: 'de',
|
||||
translations: [{ id: 'vscode', path: 'fake.json' }, { id: 'vscode.go', path: 'what.json' }]
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
const files = [
|
||||
{ path: 'extension/fake.json', contents: new Buffer('') }
|
||||
];
|
||||
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(parseXmlManifest)
|
||||
.then(result => {
|
||||
const assets = result.PackageManifest.Assets[0].Asset;
|
||||
assert(assets.some(asset => asset.$.Type === 'Microsoft.VisualStudio.Code.Translation.DE' && asset.$.Path === 'extension/fake.json'));
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect language extensions', () => {
|
||||
const manifest = {
|
||||
name: 'test',
|
||||
|
|
Loading…
Add table
Reference in a new issue