UNPKG

@mediafly/translate

Version:

Translate strings extracted from apps using Google Translate

31 lines (26 loc) 921 B
var fs = require('fs') var path = require('path') var highland = require('highland') var readFile = require('./read-file').read var flatten = require('flat') var en = readFile('locale-en') var flattenedEnglishFile = flatten(en) var format = require('./format') const { getTranslationsDir } = require('./util') var config = require(path.join(process.cwd(), 'mediafly-translate.config')) var fileFormat = config.format || 'json' const TRANSLATIONS_DIRECTORY = getTranslationsDir() function addToObject(memo, key) { return Object.assign({}, memo, {[key]: key}) } function translate() { var writeFileOptions if (config.format === 'strings') { writeFileOptions = { encoding: 'ucs2' } } return highland.keys(flattenedEnglishFile) .reduce(addToObject, {}) .map(format.transform) .pipe(fs.createWriteStream(`${TRANSLATIONS_DIRECTORY}/locale-ke.${fileFormat}`, writeFileOptions)) } module.exports = { translate }