<commit_before>var path = require( 'path' );
var fs = require( 'fs' );
var _ = require( 'underscore' );
var mkpath = require( 'mkpath' );
var util = require( 'lz-node-utils' );

module.exports = function( handlebars ) {
	return function( config ) {

		config = _.defaults( config, {
			// directory from which to source the templtes
			// sourceDir:
			// (array) globbing pattern of files in sourceDir
			// source:
			// (string) directory in which to place translated files (optional)
			dest: '',
			// translator object, must expost function translate(templateContents, model)
			translator: {
				translate: function( templateContents ) {
					return templateContents;
				}
			},
			// The relative path of the partial from sourceDir, without the .tmpl extension
			partialPathToName: function( partialPath ) {
				return partialPath.replace( '.tmpl', '' );
			},
			// Something is considered a partial if the filename begins with `_`
			isPartial: function( filePath ) {
				return path.basename( filePath )[ 0 ] === '_';
			}
		} );

		// TODO: ensure that config.sourceDir exists

		var sourceFiles = listSourceFiles( config.source );

		// Get a list of sourceFiles that are considered partials
		var partialTemplates = _.filter( sourceFiles, determineIfPartial );

		// Register each partial with handlebars
		_.each( partialTemplates, function( filePath ) {
			var partialName = getPartialName( filePath );
			var partialContents = util.file.read( filePath );
			handlebars.registerPartial( partialName, partialContents );
		} );

		/***************************************************************************
		 ****************************    EXTERNAL API    ***************************
		 **************************************************************************/
		return {
			exportify: function( options ) {

				var toExport;

				// TODO: Clean up API, what's really needed here?
				var defaults = {
					source: '',
					dest: '',
					model: {},
					modelOpts: {},
					translateOpts: {}
				};

				if ( options && options.targets ) {
					toExport = _.map( options.targets, function( pageOpts ) {
						return _.defaults( {
							source: realPath( pageOpts.source ),
							dest: path.join( config.dest, pageOpts.dest ),
							model: getModel( pageOpts ),
							translateOpts: pageOpts.translateOpts
						}, defaults );
					} );
				} else if ( options ) {
					toExport = [ _.defaults( {
						source: realPath( options.source ),
						dest: path.join( config.dest, options.dest ),
						model: getModel( options ),
						translateOpts: options.translateOpts
					}, defaults ) ];
				} else {
					toExport = _.map( sourceFiles, function( sourcePath ) {
						var pathFromSrc = getPathFromSourceDir( sourcePath );
						var dest = path.join( config.dest, pathFromSrc );
						return _.defaults( {
							source: sourcePath,
							dest: dest,
							model: {}
						}, defaults );
					} );
				}

				_.each( toExport, function( paths ) {

					// Create the destination dir if it doesn't exist
					mkpath.sync( path.dirname( paths.dest ) );

					// Pass the file through the translator
					var translated = '';
					try {
						translated = config.translator.translate( util.file.read( paths.source ), paths.translateOpts, paths.model );
					} catch ( exception ) {
						console.log( 'Error translating file: ' + paths.source );
						console.log( exception.message );
						process.exit( 1 );
					}

					// Write the translated file to its destination
					fs.writeFileSync( path.join( process.cwd(), paths.dest ), translated );
				} );
			}
		};
<commit_msg>First arg to translate is now source. UPDATE TRANSLATORS<commit_after>var path = require( 'path' );
var fs = require( 'fs' );
var _ = require( 'underscore' );
var mkpath = require( 'mkpath' );
var util = require( 'lz-node-utils' );

module.exports = function( handlebars ) {
	return function( config ) {

		config = _.defaults( config, {
			// directory from which to source the templtes
			// sourceDir:
			// (array) globbing pattern of files in sourceDir
			// source:
			// (string) directory in which to place translated files (optional)
			dest: '',
			// translator object, must expost function translate(templateContents, model)
			translator: {
				translate: function( templateContents ) {
					return templateContents;
				}
			},
			// The relative path of the partial from sourceDir, without the .tmpl extension
			partialPathToName: function( partialPath ) {
				return partialPath.replace( '.tmpl', '' );
			},
			// Something is considered a partial if the filename begins with `_`
			isPartial: function( filePath ) {
				return path.basename( filePath )[ 0 ] === '_';
			}
		} );

		// TODO: ensure that config.sourceDir exists

		var sourceFiles = listSourceFiles( config.source );

		// Get a list of sourceFiles that are considered partials
		var partialTemplates = _.filter( sourceFiles, determineIfPartial );

		// Register each partial with handlebars
		_.each( partialTemplates, function( filePath ) {
			var partialName = getPartialName( filePath );
			var partialContents = util.file.read( filePath );
			handlebars.registerPartial( partialName, partialContents );
		} );

		/***************************************************************************
		 ****************************    EXTERNAL API    ***************************
		 **************************************************************************/
		return {
			exportify: function( options ) {

				var toExport;

				// TODO: Clean up API, what's really needed here?
				var defaults = {
					source: '',
					dest: '',
					model: {},
					modelOpts: {},
					translateOpts: {}
				};

				if ( options && options.targets ) {
					toExport = _.map( options.targets, function( pageOpts ) {
						return _.defaults( {
							source: realPath( pageOpts.source ),
							dest: path.join( config.dest, pageOpts.dest ),
							model: getModel( pageOpts ),
							translateOpts: pageOpts.translateOpts
						}, defaults );
					} );
				} else if ( options ) {
					toExport = [ _.defaults( {
						source: realPath( options.source ),
						dest: path.join( config.dest, options.dest ),
						model: getModel( options ),
						translateOpts: options.translateOpts
					}, defaults ) ];
				} else {
					toExport = _.map( sourceFiles, function( sourcePath ) {
						var pathFromSrc = getPathFromSourceDir( sourcePath );
						var dest = path.join( config.dest, pathFromSrc );
						return _.defaults( {
							source: sourcePath,
							dest: dest,
							model: {}
						}, defaults );
					} );
				}

				_.each( toExport, function( paths ) {

					// Create the destination dir if it doesn't exist
					mkpath.sync( path.dirname( paths.dest ) );

					// Pass the file through the translator
					var translated = '';
					try {
						translated = config.translator.translate( paths.source, util.file.read( paths.source ), paths.translateOpts, paths.model );
					} catch ( exception ) {
						console.log( 'Error translating file: ' + paths.source );
						console.log( exception.message );
						process.exit( 1 );
					}

					// Write the translated file to its destination
					fs.writeFileSync( path.join( process.cwd(), paths.dest ), translated );
				} );
			}
		};

{'fraction_non_alphanumeric': 0.16824872747282982, 'fraction_numerical': 0.0005502820195350117, 'mean_word_length': 2.8918629550321198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5062742', 'n_tokens_mistral': 2578, 'n_tokens_neox': 1948, 'n_words': 579}