Download and merge imagery resource from Transifex

This commit is contained in:
Bryan Housel
2017-06-15 16:15:05 -04:00
parent 7843478633
commit 7be29479af
3 changed files with 57 additions and 10 deletions
+2 -1
View File
@@ -66,7 +66,8 @@ fs.writeFileSync('data/taginfo.json', JSON.stringify(taginfo, null, 4));
// Push changes from data/core.yaml into en.json
var core = YAML.load(fs.readFileSync('data/core.yaml', 'utf8'));
var en = _.merge(core, { en: { presets: tstrings }});
var imagery = JSON.parse(fs.readFileSync('./node_modules/editor-layer-index/i18n/en.json', 'utf8'));
var en = _.merge(core, { en: { presets: tstrings }}, { en: { imagery: imagery }});
fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4));
process.exit();
+30 -9
View File
@@ -9,7 +9,7 @@ var request = require('request').defaults({ maxSockets: 1 }),
var resources = ['core', 'presets', 'imagery'];
var outdir = './dist/locales/';
var api = 'https://www.transifex.com/api/2/';
var project = api + 'project/id-editor/';
var projectURL = api + 'project/id-editor/';
/*
@@ -32,7 +32,7 @@ var sourceCore = yaml.load(fs.readFileSync('./data/core.yaml', 'utf8')),
asyncMap(resources, getResource, function(err, locales) {
if (err) return console.log(err);
var locale = _.merge(sourceCore, sourcePresets, {en: sourceImagery}),
var locale = _.merge(sourceCore, sourcePresets, { en: { imagery: sourceImagery }}),
dataLocales = {};
locales.forEach(function(l) {
@@ -62,11 +62,11 @@ asyncMap(resources, getResource, function(err, locales) {
function getResource(resource, callback) {
resource = project + 'resource/' + resource + '/';
getLanguages(resource, function(err, codes) {
var resourceURL = projectURL + 'resource/' + resource + '/';
getLanguages(resourceURL, function(err, codes) {
if (err) return callback(err);
asyncMap(codes, getLanguage(resource), function(err, results) {
asyncMap(codes, getLanguage(resourceURL), function(err, results) {
if (err) return callback(err);
var locale = {};
@@ -80,15 +80,36 @@ function getResource(resource, callback) {
}
function getLanguage(resource) {
function getLanguage(resourceURL) {
return function(code, callback) {
code = code.replace(/-/g, '_');
var url = resource + 'translation/' + code;
if (code === 'vi') url += '?mode=reviewed';
var isImagery = resourceURL.match(/imagery\/$/);
var mode;
// Transifex treats JSONKEYVALUE a bit differently than YML.
// YML = untranslated strings are excluded
// JSONKEYVALUE = untranslated strings are replaced by source strings
if (code === 'vi') {
mode = isImagery ? 'onlyreviewed' : 'reviewed';
} else {
mode = isImagery ? 'onlytranslated': 'default';
}
var url = resourceURL + 'translation/' + code + '?mode=' + mode;
request.get(url, { auth : auth }, function(err, resp, body) {
if (err) return callback(err);
console.log(resp.statusCode + ': ' + url);
callback(null, yaml.load(JSON.parse(body).content)[code]);
var content = JSON.parse(body).content;
var data;
if (isImagery) {
// keep only translated (non-empty) values
var imagery = _.pickBy(JSON.parse(content), _.identity);
data = _.isEmpty(imagery) ? {} : { imagery: imagery };
} else {
data = yaml.safeLoad(content)[code];
}
callback(null, data);
});
};
}
+25
View File
@@ -5109,6 +5109,31 @@
"terms": ""
}
}
},
"imagery": {
"Bing.name": "Bing aerial imagery",
"DigitalGlobe-Premium.attribution.text": "Terms & Feedback",
"DigitalGlobe-Premium.name": "DigitalGlobe Premium Imagery",
"DigitalGlobe-Standard.attribution.text": "Terms & Feedback",
"DigitalGlobe-Standard.name": "DigitalGlobe Standard Imagery",
"Mapbox.attribution.text": "Terms & Feedback",
"Mapbox.name": "Mapbox Satellite",
"New_and_Misaligned_TIGER_Roads-2013.description": "At zoom level 16+, public domain map data from the US Census. At lower zooms, only changes since 2006 minus changes already incorporated into OpenStreetMap",
"New_and_Misaligned_TIGER_Roads-2013.name": "New & Misaligned TIGER Roads",
"mapbox_locator_overlay.attribution.text": "Terms & Feedback",
"mapbox_locator_overlay.description": "Shows major features to help orient you.",
"mapbox_locator_overlay.name": "Locator Overlay",
"osm-gps.attribution.text": "© OpenStreetMap contributors",
"osm-gps.description": "Public GPS traces uploaded to OpenStreetMap.",
"osm-gps.name": "OpenStreetMap GPS traces",
"osm-mapnik-german_style.attribution.text": "© OpenStreetMap contributors, CC-BY-SA",
"osm-mapnik-german_style.name": "OpenStreetMap (German Style)",
"stamen-terrain-background.attribution.text": "Map tiles by Stamen Design, under CC BY 3.0",
"stamen-terrain-background.name": "Stamen Terrain",
"tf-cycle.attribution.text": "Maps © Thunderforest, Data © OpenStreetMap contributors",
"tf-cycle.name": "Thunderforest OpenCycleMap",
"tf-landscape.attribution.text": "Maps © Thunderforest, Data © OpenStreetMap contributors",
"tf-landscape.name": "Thunderforest Landscape"
}
}
}