6
6
import * as path from 'path' ;
7
7
import * as fs from 'fs' ;
8
8
9
- import { through , ThroughStream } from 'event-stream' ;
9
+ import { merge , through , ThroughStream , writeArray } from 'event-stream' ;
10
10
import * as File from 'vinyl' ;
11
11
import * as Is from 'is' ;
12
12
import * as xml2js from 'xml2js' ;
13
13
import * as gulp from 'gulp' ;
14
14
import * as fancyLog from 'fancy-log' ;
15
15
import * as ansiColors from 'ansi-colors' ;
16
16
import * as iconv from '@vscode/iconv-lite-umd' ;
17
- import { l10nJsonFormat , getL10nXlf , l10nJsonDetails , getL10nFilesFromXlf } from '@vscode/l10n-dev' ;
17
+ import { l10nJsonFormat , getL10nXlf , l10nJsonDetails , getL10nFilesFromXlf , getL10nJson } from '@vscode/l10n-dev' ;
18
18
19
19
function log ( message : any , ...rest : any [ ] ) : void {
20
20
fancyLog ( ansiColors . green ( '[i18n]' ) , message , ...rest ) ;
@@ -50,7 +50,7 @@ export const extraLanguages: Language[] = [
50
50
] ;
51
51
52
52
// non built-in extensions also that are transifex and need to be part of the language packs
53
- export const externalExtensionsWithTranslations = {
53
+ const externalExtensionsWithTranslations : Record < string , string > = {
54
54
'vscode-chrome-debug' : 'msjsdiag.debugger-for-chrome' ,
55
55
'vscode-node-debug' : 'ms-vscode.node-debug' ,
56
56
'vscode-node-debug2' : 'ms-vscode.node-debug2'
@@ -586,6 +586,32 @@ export function createXlfFilesForCoreBundle(): ThroughStream {
586
586
} ) ;
587
587
}
588
588
589
+ function createL10nBundleForExtension ( extensionName : string ) : ThroughStream {
590
+ const result = through ( ) ;
591
+ gulp . src ( [
592
+ `extensions/${ extensionName } /src/**/*.ts` ,
593
+ ] ) . pipe ( writeArray ( ( err , files : File [ ] ) => {
594
+ if ( err ) {
595
+ result . emit ( 'error' , err ) ;
596
+ return ;
597
+ }
598
+
599
+ const json = getL10nJson ( files . map ( file => {
600
+ return file . contents . toString ( 'utf8' ) ;
601
+ } ) ) ;
602
+
603
+ if ( Object . keys ( json ) ) {
604
+ result . emit ( 'data' , new File ( {
605
+ path : `${ extensionName } /bundle.l10n.json` ,
606
+ contents : Buffer . from ( JSON . stringify ( json ) , 'utf8' )
607
+ } ) ) ;
608
+ }
609
+ result . emit ( 'end' ) ;
610
+ } ) ) ;
611
+
612
+ return result ;
613
+ }
614
+
589
615
export function createXlfFilesForExtensions ( ) : ThroughStream {
590
616
let counter : number = 0 ;
591
617
let folderStreamEnded : boolean = false ;
@@ -608,7 +634,10 @@ export function createXlfFilesForExtensions(): ThroughStream {
608
634
}
609
635
return _l10nMap ;
610
636
}
611
- gulp . src ( [ `.build/extensions/${ extensionName } /package.nls.json` , `.build/extensions/${ extensionName } /**/nls.metadata.json` ] , { allowEmpty : true } ) . pipe ( through ( function ( file : File ) {
637
+ merge (
638
+ gulp . src ( [ `.build/extensions/${ extensionName } /package.nls.json` , `.build/extensions/${ extensionName } /**/nls.metadata.json` ] , { allowEmpty : true } ) ,
639
+ createL10nBundleForExtension ( extensionName )
640
+ ) . pipe ( through ( function ( file : File ) {
612
641
if ( file . isBuffer ( ) ) {
613
642
const buffer : Buffer = file . contents as Buffer ;
614
643
const basename = path . basename ( file . path ) ;
@@ -631,6 +660,9 @@ export function createXlfFilesForExtensions(): ThroughStream {
631
660
}
632
661
getL10nMap ( ) . set ( `extensions/${ extensionName } /${ relPath } /${ file } ` , info ) ;
633
662
}
663
+ } else if ( basename === 'bundle.l10n.json' ) {
664
+ const json : l10nJsonFormat = JSON . parse ( buffer . toString ( 'utf8' ) ) ;
665
+ getL10nMap ( ) . set ( `extensions/${ extensionName } /bundle` , json ) ;
634
666
} else {
635
667
this . emit ( 'error' , new Error ( `${ file . path } is not a valid extension nls file` ) ) ;
636
668
return ;
@@ -762,7 +794,7 @@ function getRecordFromL10nJsonFormat(l10nJsonFormat: l10nJsonFormat): Record<str
762
794
return record ;
763
795
}
764
796
765
- export function prepareI18nPackFiles ( externalExtensions : Record < string , string > , resultingTranslationPaths : TranslationPath [ ] ) : NodeJS . ReadWriteStream {
797
+ export function prepareI18nPackFiles ( resultingTranslationPaths : TranslationPath [ ] ) : NodeJS . ReadWriteStream {
766
798
const parsePromises : Promise < l10nJsonDetails [ ] > [ ] = [ ] ;
767
799
const mainPack : I18nPack = { version : i18nPackVersion , contents : { } } ;
768
800
const extensionsPacks : Record < string , I18nPack > = { } ;
@@ -785,7 +817,7 @@ export function prepareI18nPackFiles(externalExtensions: Record<string, string>,
785
817
if ( ! extPack ) {
786
818
extPack = extensionsPacks [ resource ] = { version : i18nPackVersion , contents : { } } ;
787
819
}
788
- const externalId = externalExtensions [ resource ] ;
820
+ const externalId = externalExtensionsWithTranslations [ resource ] ;
789
821
if ( ! externalId ) { // internal extension: remove 'extensions/extensionId/' segnent
790
822
const secondSlash = path . indexOf ( '/' , firstSlash + 1 ) ;
791
823
extPack . contents [ path . substring ( secondSlash + 1 ) ] = getRecordFromL10nJsonFormat ( file . messages ) ;
@@ -814,7 +846,7 @@ export function prepareI18nPackFiles(externalExtensions: Record<string, string>,
814
846
const translatedExtFile = createI18nFile ( `extensions/${ extension } ` , extensionsPacks [ extension ] ) ;
815
847
this . queue ( translatedExtFile ) ;
816
848
817
- const externalExtensionId = externalExtensions [ extension ] ;
849
+ const externalExtensionId = externalExtensionsWithTranslations [ extension ] ;
818
850
if ( externalExtensionId ) {
819
851
resultingTranslationPaths . push ( { id : externalExtensionId , resourceName : `extensions/${ extension } .i18n.json` } ) ;
820
852
} else {
0 commit comments