<commit_before>/*
 * Adapted from https://github.com/mozilla/donate.mozilla.org/blob/master/scripts/properties2json.js
 */

var properties = require("properties-parser");
var write = require("fs-writefile-promise");
var path = require("path");
var FS = require("q-io/fs");
var env = require("./lib/environment");

var l10nConfig = env.get("L10N");
var localeSrc = path.join(process.cwd(), l10nConfig.locale_src || "locales");
var localeDest = path.join(process.cwd(), l10nConfig.locale_dest || l10nConfig.locale_src || "locales");

function getListLocales() {
  return new Promise(function(resolve, reject) {
    FS.listDirectoryTree(localeSrc).then(function(dirTree) {
      var list = [];
      dirTree.forEach(function(i) {
        var that = i.split(localeSrc + "/");
        if (that[1]) {
          list.push(that[1]);
        }
      });
      return resolve(list);
    }).catch(reject);
  });
}

function writeFiles(localeInfoList) {
  localeInfoList.forEach(function(localeInfo) {
    var langDir = path.join(localeDest, localeInfo.locale.replace(/-/g, "_"));

    FS.makeTree(langDir)
    .then(function() {
      return write(path.join(langDir, "messages.json"), JSON.stringify(localeInfo.content, null, 2), "utf-8")
      .then(function(filename) {
        console.log("Done writing: " + filename);
      });
    })
    .catch(function(err) {
      console.error(err);
    });
  });
}

function getContentMessages(locale) {
  return new Promise(function(resolve, reject) {
    properties.read(path.join(localeSrc, locale, "messages.properties"), function(message_error, message_properties) {
      if (message_error && message_error.code !== "ENOENT") {
        return reject(message_error);<commit_msg>Fix #1372 - Locale generation script should work on Windows<commit_after>/*
 * Adapted from https://github.com/mozilla/donate.mozilla.org/blob/master/scripts/properties2json.js
 */

var properties = require("properties-parser");
var write = require("fs-writefile-promise");
var path = require("path");
var FS = require("q-io/fs");
var env = require("./lib/environment");

var l10nConfig = env.get("L10N");
var localeSrc = path.join(process.cwd(), l10nConfig.locale_src || "locales");
var localeDest = path.join(process.cwd(), l10nConfig.locale_dest || l10nConfig.locale_src || "locales");

function getListLocales() {
  return new Promise(function(resolve, reject) {
    FS.listDirectoryTree(localeSrc).then(function(dirTree) {
      var list = [];
      dirTree.forEach(function(locale) {
        locale = path.relative(localeSrc, locale);
        if (locale) {
          list.push(locale);
        }
      });
      return resolve(list);
    }).catch(reject);
  });
}

function writeFiles(localeInfoList) {
  localeInfoList.forEach(function(localeInfo) {
    var langDir = path.join(localeDest, localeInfo.locale.replace(/-/g, "_"));

    FS.makeTree(langDir)
    .then(function() {
      return write(path.join(langDir, "messages.json"), JSON.stringify(localeInfo.content, null, 2), "utf-8")
      .then(function(filename) {
        console.log("Done writing: " + filename);
      });
    })
    .catch(function(err) {
      console.error(err);
    });
  });
}

function getContentMessages(locale) {
  return new Promise(function(resolve, reject) {
    properties.read(path.join(localeSrc, locale, "messages.properties"), function(message_error, message_properties) {
      if (message_error && message_error.code !== "ENOENT") {
        return reject(message_error);
{'fraction_non_alphanumeric': 0.16040172166427547, 'fraction_numerical': 0.009182209469153515, 'mean_word_length': 3.868715083798883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7085988', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1075, 'n_words': 189}