index.js
function (filePatterns, destination, options) {
  try {
    var fse = require('fs-extra')
  } catch (e) {
    console.error('This method can only be used in server applications.\n' +
      'Consider using the alternative method "i18nCompile.fromString()" instead.')
  }

  options = options || {};
  var matchedFiles = _.map(filePatterns, function (pattern) {
    return glob.sync(pattern);
  });

  var files = _.uniq(_.flatten(matchedFiles));

  var srcList = files.filter(function (filepath) {
    // Warn on and remove invalid source files (if nonull was set).
    try {
      fse.accessSync(filepath);
      return true;
    } catch (e) {
      console.warn('Source file "' + filepath + '" not found.');
      return false;
    }
  }).map(function (filepath) {
    // Read YAML file.
    var content = yaml.safeLoad(fse.readFileSync(filepath, 'utf8'), {
      filename: filepath,
      schema: yaml.JSON_SCHEMA
    });

    return new SrcItem(filepath, content);
  });

  var compiled = compileTranslations(srcList);

  // Handle options.
  if (options.merge) {
    // Write the destination file(with all languages merged in the same file).
    fse.outputFileSync(destination, JSON.stringify(compiled));

    // Print a success message.
    console.log('File "' + destination + '" created.');

    return;
  }

  // Write the destination files.
  for (var lang in compiled) {
    var fileDest = langFileDest(destination, lang, options.langPlace);
    fse.outputFileSync(fileDest, JSON.stringify(compiled[lang]));

    // Print a success message.
    console.log('File "' + fileDest + '" created.');
  }
}
function (filePatterns, destination, options) {
  try {
    var fse = require('fs-extra')
  } catch (e) {
    console.error('This method can only be used in server applications.\n' +
      'Consider using the alternative method "i18nCompile.fromString()" instead.')
  }

  options = options || {};
  var matchedFiles = _.map(filePatterns, function (pattern) {
    return glob.sync(pattern);
  });

  var files = _.uniq(_.flatten(matchedFiles));

  var srcList = files.filter(function (filepath) {
    // Warn on and remove invalid source files (if nonull was set).
    try {
      fse.accessSync(filepath);
      return true;
    } catch (e) {
      console.warn('Source file "' + filepath + '" not found.');
      return false;
    }
  }).map(function (filepath) {
    // Read YAML file.
    var content = yaml.safeLoad(fse.readFileSync(filepath, 'utf8'), {
      filename: filepath,
      schema: yaml.JSON_SCHEMA
    });

    return new SrcItem(filepath, content);
  });

  var compiled = compileTranslations(srcList);

  // Handle options.
  if (options.merge) {
    // Write the destination file(with all languages merged in the same file).
    fse.outputFileSync(destination, JSON.stringify(compiled));

    // Print a success message.
    console.log('File "' + destination + '" created.');

    return;
  }

  // Write the destination files.
  for (var lang in compiled) {
    var fileDest = langFileDest(destination, lang, options.langPlace);
    fse.outputFileSync(fileDest, JSON.stringify(compiled[lang]));

    // Print a success message.
    console.log('File "' + fileDest + '" created.');
  }
}
function ( filePatterns , destination , options ) { try { var fse = require ( 'fs-extra' ) } catch ( e ) { console . error ( 'This method can only be used in server applications.\n' + 'Consider using the alternative method "i18nCompile.fromString()" instead.' ) } options = options || { } ; var matchedFiles = _ . map ( filePatterns , function ( pattern ) { return glob . sync ( pattern ) ; } ) ; var files = _ . uniq ( _ . flatten ( matchedFiles ) ) ; var srcList = files . filter ( function ( filepath ) { // Warn on and remove invalid source files (if nonull was set). try { fse . accessSync ( filepath ) ; return true ; } catch ( e ) { console . warn ( 'Source file "' + filepath + '" not found.' ) ; return false ; } } ) . map ( function ( filepath ) { // Read YAML file. var content = yaml . safeLoad ( fse . readFileSync ( filepath , 'utf8' ) , { filename : filepath , schema : yaml . JSON_SCHEMA } ) ; return new SrcItem ( filepath , content ) ; } ) ; var compiled = compileTranslations ( srcList ) ; // Handle options. if ( options . merge ) { // Write the destination file(with all languages merged in the same file). fse . outputFileSync ( destination , JSON . stringify ( compiled ) ) ; // Print a success message. console . log ( 'File "' + destination + '" created.' ) ; return ; } // Write the destination files. for ( var lang in compiled ) { var fileDest = langFileDest ( destination , lang , options . langPlace ) ; fse . outputFileSync ( fileDest , JSON . stringify ( compiled [ lang ] ) ) ; // Print a success message. console . log ( 'File "' + fileDest + '" created.' ) ; } }
Compile files to json.

@param {String[]} filePatterns - files to compile. Glob patterns can be used to match many files
@param {String} destination - where to write the compiled results
@param {*} [options] - compiling options
Compile files to json .