import { loader } from 'webpack' ; import { Terminal } from '@rushstack/node-core-library' ; import { LocalizationPlugin } from '../LocalizationPlugin' ; import { ILocalizationFile } from '../interfaces' ; import { LocFileParser } from '../utilities/LocFileParser' ; import { loaderFactory , IBaseLoaderOptions } from './LoaderFactory' ; import { EntityMarker } from '../utilities/EntityMarker' ; import { LoaderTerminalProvider } from '../utilities/LoaderTerminalProvider' ; export interface ILocLoaderOptions extends IBaseLoaderOptions { pluginInstance : LocalizationPlugin ; } export default loaderFactory ( function ( this , locFilePath , content , options ) { const { pluginInstance } = options ; const terminal = new Terminal ( LoaderTerminalProvider . getTerminalProviderForLoader ( this ) ) ; const locFileData = LocFileParser . parseLocFile ( { content , terminal , filePath : locFilePath , resxNewlineNormalization : options . resxNewlineNormalization } ) ; const { additionalLoadedFilePaths , errors } = pluginInstance . addDefaultLocFile ( terminal , locFilePath , locFileData ) ; for ( const additionalFile of additionalLoadedFilePaths ) { this . dependency ( additionalFile ) ; } for ( const error of errors ) { this . emitError ( error ) ; } const resultObject = { } ; for ( const stringName in locFileData ) { const stringKey = `${ locFilePath }?${ stringName }` ; if ( pluginInstance . stringKeys . has ( stringKey ) ) { resultObject [ stringName ] = pluginInstance . stringKeys . get ( stringKey ) ! . value ; } else { throw new Error ( `Unexpected - missing placeholder for string key "${ stringKey }"` ) ; } } EntityMarker . markEntity ( this . _module , true ) ; return resultObject ; } ) ;