From 3d208311bd1bec8bbd163765968657eeb66d1af9 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 16 Jun 2017 00:51:04 -0400 Subject: [PATCH] Change imagery Transifex to YAML, use translated name and description --- .tx/config | 4 +- build.js | 4 +- data/update_locales.js | 29 ++------- dist/locales/en.json | 86 ++++++++++++++++++++------- modules/renderer/background_source.js | 8 ++- modules/ui/background.js | 5 +- 6 files changed, 82 insertions(+), 54 deletions(-) diff --git a/.tx/config b/.tx/config index 226039477..4f3831038 100644 --- a/.tx/config +++ b/.tx/config @@ -15,6 +15,6 @@ source_lang = en type = YAML [id-editor.imagery] -file_filter = .tx/tmp/imagery/.json +file_filter = .tx/tmp/imagery/.yaml source_lang = en -type = KEYVALUEJSON +type = YAML diff --git a/build.js b/build.js index 4ff98806f..b4b6a1d74 100644 --- a/build.js +++ b/build.js @@ -66,8 +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 imagery = JSON.parse(fs.readFileSync('./node_modules/editor-layer-index/i18n/en.json', 'utf8')); -var en = _.merge(core, { en: { presets: tstrings }}, { en: { imagery: imagery }}); +var imagery = YAML.load(fs.readFileSync('node_modules/editor-layer-index/i18n/en.yaml', 'utf8')); +var en = _.merge(core, { en: { presets: tstrings }}, imagery); fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4)); process.exit(); diff --git a/data/update_locales.js b/data/update_locales.js index 5f000157e..786a657c1 100644 --- a/data/update_locales.js +++ b/data/update_locales.js @@ -26,13 +26,13 @@ var auth = JSON.parse(fs.readFileSync('./transifex.auth', 'utf8')); var sourceCore = yaml.load(fs.readFileSync('./data/core.yaml', 'utf8')), sourcePresets = yaml.load(fs.readFileSync('./data/presets.yaml', 'utf8')), - sourceImagery = JSON.parse(fs.readFileSync('./node_modules/editor-layer-index/i18n/en.json', 'utf8')); + sourceImagery = yaml.load(fs.readFileSync('./node_modules/editor-layer-index/i18n/en.yaml', 'utf8')); asyncMap(resources, getResource, function(err, locales) { if (err) return console.log(err); - var locale = _.merge(sourceCore, sourcePresets, { en: { imagery: sourceImagery }}), + var locale = _.merge(sourceCore, sourcePresets, sourceImagery), dataLocales = {}; locales.forEach(function(l) { @@ -83,33 +83,14 @@ function getResource(resource, callback) { function getLanguage(resourceURL) { return function(code, callback) { code = code.replace(/-/g, '_'); - var isImagery = resourceURL.match(/imagery\/$/); - var mode; + var url = resourceURL + 'translation/' + code; + if (code === 'vi') { url += '?mode=reviewed'; } - // 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); - 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); + callback(null, yaml.safeLoad(content)[code]); }); }; } diff --git a/dist/locales/en.json b/dist/locales/en.json index 50dfe48f9..ea361b35c 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -5111,29 +5111,69 @@ } }, "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" + "Bing": { + "name": "Bing aerial imagery" + }, + "DigitalGlobe-Premium": { + "attribution": { + "text": "Terms & Feedback" + }, + "name": "DigitalGlobe Premium Imagery" + }, + "DigitalGlobe-Standard": { + "attribution": { + "text": "Terms & Feedback" + }, + "name": "DigitalGlobe Standard Imagery" + }, + "Mapbox": { + "attribution": { + "text": "Terms & Feedback" + }, + "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", + "name": "New & Misaligned TIGER Roads" + }, + "mapbox_locator_overlay": { + "attribution": { + "text": "Terms & Feedback" + }, + "description": "Shows major features to help orient you.", + "name": "Locator Overlay" + }, + "osm-gps": { + "attribution": { + "text": "© OpenStreetMap contributors" + }, + "description": "Public GPS traces uploaded to OpenStreetMap.", + "name": "OpenStreetMap GPS traces" + }, + "osm-mapnik-german_style": { + "attribution": { + "text": "© OpenStreetMap contributors, CC-BY-SA" + }, + "name": "OpenStreetMap (German Style)" + }, + "stamen-terrain-background": { + "attribution": { + "text": "Map tiles by Stamen Design, under CC BY 3.0" + }, + "name": "Stamen Terrain" + }, + "tf-cycle": { + "attribution": { + "text": "Maps © Thunderforest, Data © OpenStreetMap contributors" + }, + "name": "Thunderforest OpenCycleMap" + }, + "tf-landscape": { + "attribution": { + "text": "Maps © Thunderforest, Data © OpenStreetMap contributors" + }, + "name": "Thunderforest Landscape" + } } } } \ No newline at end of file diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index 9b04453d5..ec9517e78 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -9,6 +9,7 @@ export function rendererBackgroundSource(data) { var source = _.clone(data), offset = [0, 0], name = source.name, + description = source.description, best = !!source.best; source.scaleExtent = data.scaleExtent || [0, 20]; @@ -30,7 +31,12 @@ export function rendererBackgroundSource(data) { source.name = function() { - return name; + return t('imagery.' + source.id + '.name', { default: name }); + }; + + + source.description = function() { + return t('imagery.' + source.id + '.description', { default: description }); }; diff --git a/modules/ui/background.js b/modules/ui/background.js index 8bdb3b0ad..676eaaae4 100644 --- a/modules/ui/background.js +++ b/modules/ui/background.js @@ -62,6 +62,7 @@ export function uiBackground(context) { var item = d3.select(this).select('label'), span = item.select('span'), placement = (i < nodes.length / 2) ? 'bottom' : 'top', + description = d.description(), isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth')); if (d === previous) { @@ -73,10 +74,10 @@ export function uiBackground(context) { return uiTooltipHtml(tip, uiCmd('⌘B')); }) ); - } else if (d.description || isOverflowing) { + } else if (description || isOverflowing) { item.call(tooltip() .placement(placement) - .title(d.description || d.name()) + .title(description || d.name()) ); } else { item.call(tooltip().destroy);