@@ -65,7 +65,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
6565 private _passthroughStringsMap : Map < string , string > ;
6666 private _locales : Set < string > ;
6767 private _localeNamePlaceholder : IStringPlaceholder ;
68- private _defaultLocale : string ;
6968
7069 /**
7170 * The outermost map's keys are the locale names.
@@ -369,18 +368,10 @@ export class LocalizationPlugin implements Webpack.Plugin {
369368 }
370369 }
371370
372- let newAsset : IAsset ;
373- if ( locale === this . _defaultLocale ) {
374- newAsset = asset ;
375- } else {
376- newAsset = lodash . clone ( asset ) ;
377- }
378-
379- // TODO:
380- // - Fixup source maps
381371 const resultFilename : string = assetName . replace ( Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX , locale ) ;
382372 const newAssetSource : string = reconstruction . join ( '' ) ;
383373 const newAssetSize : number = asset . size ( ) + sizeDiff ;
374+ const newAsset : IAsset = lodash . clone ( asset ) ;
384375 newAsset . source = ( ) => newAssetSource ;
385376 newAsset . size = ( ) => newAssetSize ;
386377 result . set (
@@ -556,46 +547,20 @@ export class LocalizationPlugin implements Webpack.Plugin {
556547 }
557548 // END options.localizedStrings
558549
559- // START options.defaultLocale
550+ // START options.passthroughLocale
560551 { // eslint-disable-line no-lone-blocks
561- if (
562- ! this . _options . defaultLocale ||
563- ( ! this . _options . defaultLocale . locale && ! this . _options . defaultLocale . usePassthroughLocale )
564- ) {
565- if ( this . _locales . size === 1 ) {
566- this . _defaultLocale = this . _locales . entries [ 0 ] ;
567- } else {
568- errors . push ( new Error (
569- 'Either options.defaultLocale.locale must be provided or options.defaultLocale.usePassthroughLocale ' +
570- 'must be set to true if more than one locale\'s data is provided'
571- ) ) ;
572- }
573- } else {
574- const { locale, usePassthroughLocale, passthroughLocaleName } = this . _options . defaultLocale ;
575- if ( locale && usePassthroughLocale ) {
576- errors . push ( new Error (
577- 'Either options.defaultLocale.locale must be provided or options.defaultLocale.usePassthroughLocale ' +
578- 'must be set to true, but not both'
579- ) ) ;
580- } else if ( usePassthroughLocale ) {
581- this . _defaultLocale = passthroughLocaleName || 'passthrough' ;
582- this . _locales . add ( this . _defaultLocale ) ;
583- this . _stringPlaceholderMap . get ( this . _localeNamePlaceholder . suffix ) ! [ this . _defaultLocale ] =
584- this . _defaultLocale ;
552+ if ( this . _options . passthroughLocale ) {
553+ const { usePassthroughLocale, passthroughLocaleName = 'passthrough' } = this . _options . passthroughLocale ;
554+ if ( usePassthroughLocale ) {
555+ this . _locales . add ( passthroughLocaleName ) ;
556+ this . _stringPlaceholderMap . get ( this . _localeNamePlaceholder . suffix ) ! [ passthroughLocaleName ] = passthroughLocaleName ;
585557 this . _passthroughStringsMap . forEach ( ( stringName : string , stringKey : string ) => {
586- this . _stringPlaceholderMap . get ( stringKey ) ! [ this . _defaultLocale ] = stringName ;
558+ this . _stringPlaceholderMap . get ( stringKey ) ! [ passthroughLocaleName ] = stringName ;
587559 } ) ;
588- } else if ( locale ) {
589- this . _defaultLocale = locale ;
590- if ( ! this . _locales . has ( locale ) ) {
591- errors . push ( new Error ( `The specified default locale "${ locale } " was not provided in the localized data` ) ) ;
592- }
593- } else {
594- errors . push ( new Error ( 'Unknown error occurred processing default locale.' ) ) ;
595560 }
596561 }
597562 }
598- // END options.defaultLocale
563+ // END options.passthroughLocale
599564
600565 return errors ;
601566 }
0 commit comments