write = (locale) => {
    let stats, target, tmp

    // don't write new locale information to disk if updateFiles isn't true
    if (!updateFiles) {
      return
    }

    // creating directory if necessary
    try {
      stats = fs.lstatSync(directory)
    } catch (e) {
      logDebug('creating locales dir in: ' + directory)
      try {
        fs.mkdirSync(directory, directoryPermissions)
      } catch (e) {
        // in case of parallel tasks utilizing in same dir
        if (e.code !== 'EEXIST') throw e
      }
    }

    // first time init has an empty file
    if (!locales[locale]) {
      locales[locale] = {}
    }

    // writing to tmp and rename on success
    try {
      target = getStorageFilePath(locale)
      tmp = target + '.tmp'
      fs.writeFileSync(
        tmp,
        parser.stringify(locales[locale], null, indent),
        'utf8'
      )
      stats = fs.statSync(tmp)
      if (stats.isFile()) {
        fs.renameSync(tmp, target)
      } else {
        logError(
          'unable to write locales to file (either ' +
            tmp +
            ' or ' +
            target +
            ' are not writeable?): '
        )
      }
    } catch (e) {
      logError(
        'unexpected error writing files (either ' +
          tmp +
          ' or ' +
          target +
          ' are not writeable?): ',
        e
      )
    }
  }
try writing a file in a created directory