Skip to content

Commit 0249ba4

Browse files
use the actual extension id as the id in the language pack (microsoft#165436)
Past behavior caused 404s to be thrown by the unpkg service because core was trying to load: `${extensionId}` -> `vscode.markdown` and not what the build creates in the language packs: `vscode.${extensionFolder}` -> `vscode.markdown-basics` this aligns build time and runtime.
1 parent 2e47c97 commit 0249ba4

File tree

2 files changed

+46
-69
lines changed

2 files changed

+46
-69
lines changed

build/lib/i18n.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ exports.extraLanguages = [
3636
{ id: 'hu', folderName: 'hun' },
3737
{ id: 'tr', folderName: 'trk' }
3838
];
39-
// non built-in extensions also that are transifex and need to be part of the language packs
40-
const externalExtensionsWithTranslations = {
41-
'vscode-chrome-debug': 'msjsdiag.debugger-for-chrome',
42-
'vscode-node-debug': 'ms-vscode.node-debug',
43-
'vscode-node-debug2': 'ms-vscode.node-debug2'
44-
};
4539
var LocalizeInfo;
4640
(function (LocalizeInfo) {
4741
function is(value) {
@@ -513,10 +507,10 @@ function createXlfFilesForCoreBundle() {
513507
});
514508
}
515509
exports.createXlfFilesForCoreBundle = createXlfFilesForCoreBundle;
516-
function createL10nBundleForExtension(extensionName) {
510+
function createL10nBundleForExtension(extensionFolderName) {
517511
const result = (0, event_stream_1.through)();
518512
gulp.src([
519-
`extensions/${extensionName}/src/**/*.ts`,
513+
`extensions/${extensionFolderName}/src/**/*.ts`,
520514
]).pipe((0, event_stream_1.writeArray)((err, files) => {
521515
if (err) {
522516
result.emit('error', err);
@@ -527,7 +521,7 @@ function createL10nBundleForExtension(extensionName) {
527521
}));
528522
if (Object.keys(json).length > 0) {
529523
result.emit('data', new File({
530-
path: `${extensionName}/bundle.l10n.json`,
524+
path: `extensions/${extensionFolderName}/bundle.l10n.json`,
531525
contents: Buffer.from(JSON.stringify(json), 'utf8')
532526
}));
533527
}
@@ -545,10 +539,14 @@ function createXlfFilesForExtensions() {
545539
if (!stat.isDirectory()) {
546540
return;
547541
}
548-
const extensionName = path.basename(extensionFolder.path);
549-
if (extensionName === 'node_modules') {
542+
const extensionFolderName = path.basename(extensionFolder.path);
543+
if (extensionFolderName === 'node_modules') {
550544
return;
551545
}
546+
// Get extension id and use that as the id
547+
const manifest = fs.readFileSync(path.join(extensionFolder.path, 'package.json'), 'utf-8');
548+
const manifestJson = JSON.parse(manifest);
549+
const extensionId = manifestJson.publisher + '.' + manifestJson.name;
552550
counter++;
553551
let _l10nMap;
554552
function getL10nMap() {
@@ -557,17 +555,17 @@ function createXlfFilesForExtensions() {
557555
}
558556
return _l10nMap;
559557
}
560-
(0, event_stream_1.merge)(gulp.src([`.build/extensions/${extensionName}/package.nls.json`, `.build/extensions/${extensionName}/**/nls.metadata.json`], { allowEmpty: true }), createL10nBundleForExtension(extensionName)).pipe((0, event_stream_1.through)(function (file) {
558+
(0, event_stream_1.merge)(gulp.src([`.build/extensions/${extensionFolderName}/package.nls.json`, `.build/extensions/${extensionFolderName}/**/nls.metadata.json`], { allowEmpty: true }), createL10nBundleForExtension(extensionFolderName)).pipe((0, event_stream_1.through)(function (file) {
561559
if (file.isBuffer()) {
562560
const buffer = file.contents;
563561
const basename = path.basename(file.path);
564562
if (basename === 'package.nls.json') {
565563
const json = JSON.parse(buffer.toString('utf8'));
566-
getL10nMap().set(`extensions/${extensionName}/package`, json);
564+
getL10nMap().set(`extensions/${extensionId}/package`, json);
567565
}
568566
else if (basename === 'nls.metadata.json') {
569567
const json = JSON.parse(buffer.toString('utf8'));
570-
const relPath = path.relative(`.build/extensions/${extensionName}`, path.dirname(file.path));
568+
const relPath = path.relative(`.build/extensions/${extensionFolderName}`, path.dirname(file.path));
571569
for (const file in json) {
572570
const fileContent = json[file];
573571
const info = Object.create(null);
@@ -578,12 +576,12 @@ function createXlfFilesForExtensions() {
578576
: { key: fileContent.keys[i], comment: undefined };
579577
info[key] = comment ? { message, comment } : message;
580578
}
581-
getL10nMap().set(`extensions/${extensionName}/${relPath}/${file}`, info);
579+
getL10nMap().set(`extensions/${extensionId}/${relPath}/${file}`, info);
582580
}
583581
}
584582
else if (basename === 'bundle.l10n.json') {
585583
const json = JSON.parse(buffer.toString('utf8'));
586-
getL10nMap().set(`extensions/${extensionName}/bundle`, json);
584+
getL10nMap().set(`extensions/${extensionId}/bundle`, json);
587585
}
588586
else {
589587
this.emit('error', new Error(`${file.path} is not a valid extension nls file`));
@@ -593,7 +591,7 @@ function createXlfFilesForExtensions() {
593591
}, function () {
594592
if (_l10nMap?.size > 0) {
595593
const xlfFile = new File({
596-
path: path.join(extensionsProject, extensionName + '.xlf'),
594+
path: path.join(extensionsProject, extensionId + '.xlf'),
597595
contents: Buffer.from((0, l10n_dev_1.getL10nXlf)(_l10nMap), 'utf8')
598596
});
599597
folderStream.queue(xlfFile);
@@ -712,18 +710,14 @@ function prepareI18nPackFiles(resultingTranslationPaths) {
712710
const path = file.name;
713711
const firstSlash = path.indexOf('/');
714712
if (project === extensionsProject) {
713+
// resource will be the extension id
715714
let extPack = extensionsPacks[resource];
716715
if (!extPack) {
717716
extPack = extensionsPacks[resource] = { version: i18nPackVersion, contents: {} };
718717
}
719-
const externalId = externalExtensionsWithTranslations[resource];
720-
if (!externalId) { // internal extension: remove 'extensions/extensionId/' segnent
721-
const secondSlash = path.indexOf('/', firstSlash + 1);
722-
extPack.contents[path.substring(secondSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
723-
}
724-
else {
725-
extPack.contents[path] = getRecordFromL10nJsonFormat(file.messages);
726-
}
718+
// remove 'extensions/extensionId/' segment
719+
const secondSlash = path.indexOf('/', firstSlash + 1);
720+
extPack.contents[path.substring(secondSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
727721
}
728722
else {
729723
mainPack.contents[path.substring(firstSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
@@ -741,16 +735,10 @@ function prepareI18nPackFiles(resultingTranslationPaths) {
741735
const translatedMainFile = createI18nFile('./main', mainPack);
742736
resultingTranslationPaths.push({ id: 'vscode', resourceName: 'main.i18n.json' });
743737
this.queue(translatedMainFile);
744-
for (const extension in extensionsPacks) {
745-
const translatedExtFile = createI18nFile(`extensions/${extension}`, extensionsPacks[extension]);
738+
for (const extensionId in extensionsPacks) {
739+
const translatedExtFile = createI18nFile(`extensions/${extensionId}`, extensionsPacks[extensionId]);
746740
this.queue(translatedExtFile);
747-
const externalExtensionId = externalExtensionsWithTranslations[extension];
748-
if (externalExtensionId) {
749-
resultingTranslationPaths.push({ id: externalExtensionId, resourceName: `extensions/${extension}.i18n.json` });
750-
}
751-
else {
752-
resultingTranslationPaths.push({ id: `vscode.${extension}`, resourceName: `extensions/${extension}.i18n.json` });
753-
}
741+
resultingTranslationPaths.push({ id: extensionId, resourceName: `extensions/${extensionId}.i18n.json` });
754742
}
755743
this.queue(null);
756744
})

build/lib/i18n.ts

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ export const extraLanguages: Language[] = [
4949
{ id: 'tr', folderName: 'trk' }
5050
];
5151

52-
// non built-in extensions also that are transifex and need to be part of the language packs
53-
const externalExtensionsWithTranslations: Record<string, string> = {
54-
'vscode-chrome-debug': 'msjsdiag.debugger-for-chrome',
55-
'vscode-node-debug': 'ms-vscode.node-debug',
56-
'vscode-node-debug2': 'ms-vscode.node-debug2'
57-
};
58-
5952
interface Item {
6053
id: string;
6154
message: string;
@@ -586,10 +579,10 @@ export function createXlfFilesForCoreBundle(): ThroughStream {
586579
});
587580
}
588581

589-
function createL10nBundleForExtension(extensionName: string): ThroughStream {
582+
function createL10nBundleForExtension(extensionFolderName: string): ThroughStream {
590583
const result = through();
591584
gulp.src([
592-
`extensions/${extensionName}/src/**/*.ts`,
585+
`extensions/${extensionFolderName}/src/**/*.ts`,
593586
]).pipe(writeArray((err, files: File[]) => {
594587
if (err) {
595588
result.emit('error', err);
@@ -602,7 +595,7 @@ function createL10nBundleForExtension(extensionName: string): ThroughStream {
602595

603596
if (Object.keys(json).length > 0) {
604597
result.emit('data', new File({
605-
path: `${extensionName}/bundle.l10n.json`,
598+
path: `extensions/${extensionFolderName}/bundle.l10n.json`,
606599
contents: Buffer.from(JSON.stringify(json), 'utf8')
607600
}));
608601
}
@@ -622,10 +615,15 @@ export function createXlfFilesForExtensions(): ThroughStream {
622615
if (!stat.isDirectory()) {
623616
return;
624617
}
625-
const extensionName = path.basename(extensionFolder.path);
626-
if (extensionName === 'node_modules') {
618+
const extensionFolderName = path.basename(extensionFolder.path);
619+
if (extensionFolderName === 'node_modules') {
627620
return;
628621
}
622+
// Get extension id and use that as the id
623+
const manifest = fs.readFileSync(path.join(extensionFolder.path, 'package.json'), 'utf-8');
624+
const manifestJson = JSON.parse(manifest);
625+
const extensionId = manifestJson.publisher + '.' + manifestJson.name;
626+
629627
counter++;
630628
let _l10nMap: Map<string, l10nJsonFormat>;
631629
function getL10nMap() {
@@ -635,18 +633,18 @@ export function createXlfFilesForExtensions(): ThroughStream {
635633
return _l10nMap;
636634
}
637635
merge(
638-
gulp.src([`.build/extensions/${extensionName}/package.nls.json`, `.build/extensions/${extensionName}/**/nls.metadata.json`], { allowEmpty: true }),
639-
createL10nBundleForExtension(extensionName)
636+
gulp.src([`.build/extensions/${extensionFolderName}/package.nls.json`, `.build/extensions/${extensionFolderName}/**/nls.metadata.json`], { allowEmpty: true }),
637+
createL10nBundleForExtension(extensionFolderName)
640638
).pipe(through(function (file: File) {
641639
if (file.isBuffer()) {
642640
const buffer: Buffer = file.contents as Buffer;
643641
const basename = path.basename(file.path);
644642
if (basename === 'package.nls.json') {
645643
const json: l10nJsonFormat = JSON.parse(buffer.toString('utf8'));
646-
getL10nMap().set(`extensions/${extensionName}/package`, json);
644+
getL10nMap().set(`extensions/${extensionId}/package`, json);
647645
} else if (basename === 'nls.metadata.json') {
648646
const json: BundledExtensionFormat = JSON.parse(buffer.toString('utf8'));
649-
const relPath = path.relative(`.build/extensions/${extensionName}`, path.dirname(file.path));
647+
const relPath = path.relative(`.build/extensions/${extensionFolderName}`, path.dirname(file.path));
650648
for (const file in json) {
651649
const fileContent = json[file];
652650
const info: l10nJsonFormat = Object.create(null);
@@ -658,11 +656,11 @@ export function createXlfFilesForExtensions(): ThroughStream {
658656

659657
info[key] = comment ? { message, comment } : message;
660658
}
661-
getL10nMap().set(`extensions/${extensionName}/${relPath}/${file}`, info);
659+
getL10nMap().set(`extensions/${extensionId}/${relPath}/${file}`, info);
662660
}
663661
} else if (basename === 'bundle.l10n.json') {
664662
const json: l10nJsonFormat = JSON.parse(buffer.toString('utf8'));
665-
getL10nMap().set(`extensions/${extensionName}/bundle`, json);
663+
getL10nMap().set(`extensions/${extensionId}/bundle`, json);
666664
} else {
667665
this.emit('error', new Error(`${file.path} is not a valid extension nls file`));
668666
return;
@@ -671,7 +669,7 @@ export function createXlfFilesForExtensions(): ThroughStream {
671669
}, function () {
672670
if (_l10nMap?.size > 0) {
673671
const xlfFile = new File({
674-
path: path.join(extensionsProject, extensionName + '.xlf'),
672+
path: path.join(extensionsProject, extensionId + '.xlf'),
675673
contents: Buffer.from(getL10nXlf(_l10nMap), 'utf8')
676674
});
677675
folderStream.queue(xlfFile);
@@ -813,17 +811,14 @@ export function prepareI18nPackFiles(resultingTranslationPaths: TranslationPath[
813811
const firstSlash = path.indexOf('/');
814812

815813
if (project === extensionsProject) {
814+
// resource will be the extension id
816815
let extPack = extensionsPacks[resource];
817816
if (!extPack) {
818817
extPack = extensionsPacks[resource] = { version: i18nPackVersion, contents: {} };
819818
}
820-
const externalId = externalExtensionsWithTranslations[resource];
821-
if (!externalId) { // internal extension: remove 'extensions/extensionId/' segnent
822-
const secondSlash = path.indexOf('/', firstSlash + 1);
823-
extPack.contents[path.substring(secondSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
824-
} else {
825-
extPack.contents[path] = getRecordFromL10nJsonFormat(file.messages);
826-
}
819+
// remove 'extensions/extensionId/' segment
820+
const secondSlash = path.indexOf('/', firstSlash + 1);
821+
extPack.contents[path.substring(secondSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
827822
} else {
828823
mainPack.contents[path.substring(firstSlash + 1)] = getRecordFromL10nJsonFormat(file.messages);
829824
}
@@ -842,17 +837,11 @@ export function prepareI18nPackFiles(resultingTranslationPaths: TranslationPath[
842837
resultingTranslationPaths.push({ id: 'vscode', resourceName: 'main.i18n.json' });
843838

844839
this.queue(translatedMainFile);
845-
for (const extension in extensionsPacks) {
846-
const translatedExtFile = createI18nFile(`extensions/${extension}`, extensionsPacks[extension]);
840+
for (const extensionId in extensionsPacks) {
841+
const translatedExtFile = createI18nFile(`extensions/${extensionId}`, extensionsPacks[extensionId]);
847842
this.queue(translatedExtFile);
848843

849-
const externalExtensionId = externalExtensionsWithTranslations[extension];
850-
if (externalExtensionId) {
851-
resultingTranslationPaths.push({ id: externalExtensionId, resourceName: `extensions/${extension}.i18n.json` });
852-
} else {
853-
resultingTranslationPaths.push({ id: `vscode.${extension}`, resourceName: `extensions/${extension}.i18n.json` });
854-
}
855-
844+
resultingTranslationPaths.push({ id: extensionId, resourceName: `extensions/${extensionId}.i18n.json` });
856845
}
857846
this.queue(null);
858847
})

0 commit comments

Comments
 (0)