Skip to content

Commit

Permalink
Change imagery Transifex to YAML, use translated name and description
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Jun 16, 2017
1 parent ad8a2fc commit 3d20831
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ source_lang = en
type = YAML

[id-editor.imagery]
file_filter = .tx/tmp/imagery/<lang>.json
file_filter = .tx/tmp/imagery/<lang>.yaml
source_lang = en
type = KEYVALUEJSON
type = YAML
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 5 additions & 24 deletions data/update_locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

// 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;
if (code === 'vi') { url += '?mode=reviewed'; }

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]);
});
};
}
Expand Down
86 changes: 63 additions & 23 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
8 changes: 7 additions & 1 deletion modules/renderer/background_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 });
};


Expand Down
5 changes: 3 additions & 2 deletions modules/ui/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 3d20831

Please sign in to comment.