From 01a6130751c53883c9cae0dc9c9d77fc8553e460 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 29 Mar 2019 01:27:38 -0400 Subject: [PATCH] Remove lodash merge.. also don't need esm dependency anymore (re: #6087) --- data/update_locales.js | 44 +++++++++++++++++++----------------------- package.json | 1 - 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/data/update_locales.js b/data/update_locales.js index a88584acd..b9f716b60 100644 --- a/data/update_locales.js +++ b/data/update_locales.js @@ -1,8 +1,4 @@ /* Downloads the latest translations from Transifex */ - -const requireESM = require('esm')(module); -const _merge = requireESM('lodash-es/merge').default; - const fs = require('fs'); const prettyStringify = require('json-stringify-pretty-compact'); const request = require('request').defaults({ maxSockets: 1 }); @@ -35,25 +31,26 @@ const sourceCommunity = YAML.load(fs.readFileSync('./node_modules/osm-community- asyncMap(resources, getResource, function(err, results) { if (err) return console.log(err); - var locale = _merge( - sourceCore, - sourcePresets, - sourceImagery, - { en: { community: sourceCommunity.en } } // add namespace - ); - var dataLocales = {}; - - results.forEach(function(l) { - locale = _merge(locale, l); + // merge in strings fetched from transifex + var allStrings = {}; + results.forEach(function(resourceStrings) { + Object.keys(resourceStrings).forEach(function(code) { + if (!allStrings[code]) { allStrings[code] = {}; } + var source = resourceStrings[code]; + var target = allStrings[code]; + Object.keys(source).forEach(function(k) { target[k] = source[k]; }); + }); }); - asyncMap(Object.keys(locale), + // write files and fetch language info for each locale + var dataLocales = {}; + asyncMap(Object.keys(allStrings), function(code, done) { - if (code === 'en' || !Object.keys(locale[code]).length) { + if (code === 'en' || !Object.keys(allStrings[code]).length) { done(); } else { var obj = {}; - obj[code] = locale[code]; + obj[code] = allStrings[code]; fs.writeFileSync(outdir + code + '.json', JSON.stringify(obj, null, 4)); getLanguageInfo(code, function(err, info) { @@ -151,13 +148,12 @@ function getLanguages(resource, callback) { var url = resource + '?details'; request.get(url, { auth: auth }, function(err, resp, body) { - if (err) return callback(err); - console.log(resp.statusCode + ': ' + url); - callback(null, JSON.parse(body).available_languages.map(function(d) { - return d.code.replace(/_/g, '-'); - }).filter(function(d) { - return d !== 'en'; - })); + if (err) return callback(err); + console.log(resp.statusCode + ': ' + url); + callback(null, JSON.parse(body).available_languages + .map(function(d) { return d.code.replace(/_/g, '-'); }) + .filter(function(d) { return d !== 'en'; }) + ); }); } diff --git a/package.json b/package.json index deee233bc..6c829d16d 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "ecstatic": "^3.0.0", "editor-layer-index": "github:osmlab/editor-layer-index#gh-pages", "eslint": "^5.15.3", - "esm": "^3.2.18", "gaze": "^1.1.1", "glob": "^7.1.0", "happen": "^0.3.1",