@@ -56,19 +56,21 @@ export interface AngularCompilerPluginOptions {
5656 skipCodeGeneration ?: boolean ;
5757 hostOverrideFileSystem ?: { [ path : string ] : string } ;
5858 hostReplacementPaths ?: { [ path : string ] : string } ;
59- i18nFile ?: string ;
60- i18nFormat ?: string ;
59+ i18nInFile ?: string ;
60+ i18nInFormat ?: string ;
61+ i18nOutFile ?: string ;
62+ i18nOutFormat ?: string ;
6163 locale ?: string ;
6264 missingTranslation ?: string ;
63- replaceExport ?: boolean ;
65+ platform ?: PLATFORM ;
6466
6567 // Use tsconfig to include path globs.
6668 exclude ?: string | string [ ] ;
6769 include ?: string [ ] ;
6870 compilerOptions ?: ts . CompilerOptions ;
6971}
7072
71- enum PLATFORM {
73+ export enum PLATFORM {
7274 Browser ,
7375 Server
7476}
@@ -230,11 +232,17 @@ export class AngularCompilerPlugin implements Tapable {
230232 }
231233
232234 // Process i18n options.
233- if ( options . hasOwnProperty ( 'i18nFile ' ) ) {
234- this . _angularCompilerOptions . i18nInFile = options . i18nFile ;
235+ if ( options . hasOwnProperty ( 'i18nInFile ' ) ) {
236+ this . _angularCompilerOptions . i18nInFile = options . i18nInFile ;
235237 }
236- if ( options . hasOwnProperty ( 'i18nFormat' ) ) {
237- this . _angularCompilerOptions . i18nInFormat = options . i18nFormat ;
238+ if ( options . hasOwnProperty ( 'i18nInFormat' ) ) {
239+ this . _angularCompilerOptions . i18nInFormat = options . i18nInFormat ;
240+ }
241+ if ( options . hasOwnProperty ( 'i18nOutFile' ) ) {
242+ this . _angularCompilerOptions . i18nOutFile = options . i18nOutFile ;
243+ }
244+ if ( options . hasOwnProperty ( 'i18nOutFormat' ) ) {
245+ this . _angularCompilerOptions . i18nOutFormat = options . i18nOutFormat ;
238246 }
239247 if ( options . hasOwnProperty ( 'locale' ) && options . locale ) {
240248 this . _angularCompilerOptions . i18nInLocale = this . _validateLocale ( options . locale ) ;
@@ -273,8 +281,7 @@ export class AngularCompilerPlugin implements Tapable {
273281 }
274282 }
275283
276- // TODO: consider really using platform names in the plugin options.
277- this . _platform = options . replaceExport ? PLATFORM . Server : PLATFORM . Browser ;
284+ this . _platform = options . platform || PLATFORM . Browser ;
278285 timeEnd ( 'AngularCompilerPlugin._setupOptions' ) ;
279286 }
280287
@@ -722,6 +729,24 @@ export class AngularCompilerPlugin implements Tapable {
722729 } ) ;
723730 }
724731
732+ writeI18nOutFile ( ) {
733+ function _recursiveMkDir ( p : string ) : Promise < void > {
734+ if ( fs . existsSync ( p ) ) {
735+ return Promise . resolve ( ) ;
736+ } else {
737+ return _recursiveMkDir ( path . dirname ( p ) )
738+ . then ( ( ) => fs . mkdirSync ( p ) ) ;
739+ }
740+ }
741+
742+ // Write the extracted messages to disk.
743+ const i18nOutFilePath = path . resolve ( this . _basePath , this . _angularCompilerOptions . i18nOutFile ) ;
744+ const i18nOutFileContent = this . _compilerHost . readFile ( i18nOutFilePath ) ;
745+ if ( i18nOutFileContent ) {
746+ _recursiveMkDir ( path . dirname ( i18nOutFilePath ) )
747+ . then ( ( ) => fs . writeFileSync ( i18nOutFilePath , i18nOutFileContent ) ) ;
748+ }
749+ }
725750
726751 getFile ( fileName : string ) {
727752 const outputFile = fileName . replace ( / .t s $ / , '.js' ) ;
@@ -792,8 +817,13 @@ export class AngularCompilerPlugin implements Tapable {
792817
793818 if ( ! hasErrors ( allDiagnostics ) ) {
794819 time ( 'AngularCompilerPlugin._emit.ng.emit' ) ;
795- emitResult = angularProgram . emit ( { emitFlags : EmitFlags . Default , customTransformers } ) ;
820+ const extractI18n = ! ! this . _angularCompilerOptions . i18nOutFile ;
821+ const emitFlags = extractI18n ? EmitFlags . I18nBundle : EmitFlags . Default ;
822+ emitResult = angularProgram . emit ( { emitFlags, customTransformers } ) ;
796823 allDiagnostics . push ( ...emitResult . diagnostics ) ;
824+ if ( extractI18n ) {
825+ this . writeI18nOutFile ( ) ;
826+ }
797827 timeEnd ( 'AngularCompilerPlugin._emit.ng.emit' ) ;
798828 }
799829 }
0 commit comments