@@ -505,34 +505,30 @@ export class LocalizationPlugin implements Webpack.Plugin {
505
505
const stringsMap : Map < string , string > = new Map < string , string > ( ) ;
506
506
filesMap . set ( localizedFilePath , stringsMap ) ;
507
507
508
- for ( const stringName in localizedFileData ) {
509
- if ( ! localizedFileData . hasOwnProperty || localizedFileData . hasOwnProperty ( stringName ) ) {
510
- const stringKey : string = `${ localizedFilePath } ?${ stringName } ` ;
511
- if ( ! this . stringKeys . has ( stringKey ) ) {
512
- const placeholder : IStringPlaceholder = this . _getPlaceholderString ( ) ;
513
- this . stringKeys . set ( stringKey , placeholder ) ;
514
- }
515
-
516
- const placeholder : IStringPlaceholder = this . stringKeys . get ( stringKey ) ! ;
517
- if ( ! this . _stringPlaceholderMap . has ( placeholder . suffix ) ) {
518
- this . _stringPlaceholderMap . set (
519
- placeholder . suffix ,
520
- {
521
- values : {
522
- [ this . _passthroughLocaleName ] : stringName
523
- } ,
524
- locFilePath : localizedFilePath ,
525
- stringName : stringName
526
- }
527
- ) ;
528
- }
508
+ for ( const [ stringName , stringValue ] of Object . entries ( localizedFileData ) ) {
509
+ const stringKey : string = `${ localizedFilePath } ?${ stringName } ` ;
510
+ if ( ! this . stringKeys . has ( stringKey ) ) {
511
+ const placeholder : IStringPlaceholder = this . _getPlaceholderString ( ) ;
512
+ this . stringKeys . set ( stringKey , placeholder ) ;
513
+ }
529
514
530
- const stringValue : string = localizedFileData [ stringName ] ;
515
+ const placeholder : IStringPlaceholder = this . stringKeys . get ( stringKey ) ! ;
516
+ if ( ! this . _stringPlaceholderMap . has ( placeholder . suffix ) ) {
517
+ this . _stringPlaceholderMap . set (
518
+ placeholder . suffix ,
519
+ {
520
+ values : {
521
+ [ this . _passthroughLocaleName ] : stringName
522
+ } ,
523
+ locFilePath : localizedFilePath ,
524
+ stringName : stringName
525
+ }
526
+ ) ;
527
+ }
531
528
532
- this . _stringPlaceholderMap . get ( placeholder . suffix ) ! . values [ localeName ] = stringValue ;
529
+ this . _stringPlaceholderMap . get ( placeholder . suffix ) ! . values [ localeName ] = stringValue ;
533
530
534
- stringsMap . set ( stringName , stringValue ) ;
535
- }
531
+ stringsMap . set ( stringName , stringValue ) ;
536
532
}
537
533
}
538
534
@@ -726,19 +722,22 @@ export class LocalizationPlugin implements Webpack.Plugin {
726
722
}
727
723
728
724
private _chunkHasLocalizedModules ( chunk : Webpack . compilation . Chunk ) : boolean {
729
- if ( EntityMarker . getMark ( chunk ) === undefined ) {
730
- let chunkHasAnyLocModules : boolean = false ;
731
- if ( ! chunkHasAnyLocModules ) {
732
- for ( const module of chunk . getModules ( ) ) {
733
- if ( EntityMarker . getMark ( module ) ) {
734
- chunkHasAnyLocModules = true ;
735
- break ;
736
- }
725
+ let chunkHasAnyLocModules : boolean | undefined = EntityMarker . getMark ( chunk ) ;
726
+ if ( chunkHasAnyLocModules === undefined ) {
727
+ chunkHasAnyLocModules = false ;
728
+ for ( const module of chunk . getModules ( ) ) {
729
+ if ( EntityMarker . getMark ( module ) ) {
730
+ chunkHasAnyLocModules = true ;
731
+ break ;
737
732
}
738
733
}
739
734
740
- // Check async chunks if this is a runtime chunk and we haven't directly found any localized modules
741
- if ( chunk . hasRuntime ( ) && ! chunkHasAnyLocModules ) {
735
+ // If this chunk doesn't directly contain any localized resources, it still
736
+ // needs to be localized if it's an entrypoint chunk (i.e. - it has a runtime)
737
+ // and it loads localized async chunks.
738
+ // In that case, the generated chunk URL generation code needs to contain
739
+ // the locale name.
740
+ if ( ! chunkHasAnyLocModules && chunk . hasRuntime ( ) ) {
742
741
for ( const asyncChunk of chunk . getAllAsyncChunks ( ) ) {
743
742
if ( this . _chunkHasLocalizedModules ( asyncChunk ) ) {
744
743
chunkHasAnyLocModules = true ;
@@ -750,13 +749,13 @@ export class LocalizationPlugin implements Webpack.Plugin {
750
749
EntityMarker . markEntity ( chunk , chunkHasAnyLocModules ) ;
751
750
}
752
751
753
- return EntityMarker . getMark ( chunk ) ! ;
752
+ return chunkHasAnyLocModules ;
754
753
}
755
754
756
755
private _convertLocalizationFileToLocData ( locFile : ILocalizationFile ) : ILocaleFileData {
757
756
const locFileData : ILocaleFileData = { } ;
758
- for ( const stringName in locFile ) { // eslint-disable-line guard-for-in
759
- locFileData [ stringName ] = locFile [ stringName ] . value ;
757
+ for ( const [ stringName , locFileEntry ] of Object . entries ( locFile ) ) {
758
+ locFileData [ stringName ] = locFileEntry . value ;
760
759
}
761
760
762
761
return locFileData ;
0 commit comments