Skip to content

Commit

Permalink
feat(name): use "name:en" as a fallback for when no default name was …
Browse files Browse the repository at this point in the history
…found
  • Loading branch information
missinglink committed Aug 13, 2019
1 parent 834df89 commit a8f0acb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ module.exports = function(){
}
}

// Handle the case where no default name was set but there was
// an english name which we could use as the default.
if( !doc.getName('default') ){
var en = doc.getName('en');
if( 'string' === typeof en ){
doc.setName('default', en);
}
}

// Import airport codes as aliases
if( tags.hasOwnProperty('aerodrome') || tags.hasOwnProperty('aeroway') ){
if( tags.hasOwnProperty('iata') ){
Expand Down
19 changes: 19 additions & 0 deletions test/stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ module.exports.tests.accept_localized_keys = function(test, common) {
});
};

// Use 'name:en' in situations where no other default name was available
// https://github.com/pelias/openstreetmap/issues/497
module.exports.tests.use_en_as_fallback_default = function (test, common) {
var doc = new Document('a', 'b', 1);
doc.setMeta('tags', { 'name:ru': 'test1', 'name:pl': 'test2', 'name:en': 'test3' });
test('maps - use name:en as fallback default', function (t) {
var stream = mapper();
stream.pipe(through.obj(function (doc, enc, next) {
t.equal(doc.getName('default'), 'test3', 'name:en used as fallback');
t.equal(doc.getName('ru'), 'test1', 'correctly mapped');
t.equal(doc.getName('pl'), 'test2', 'correctly mapped');
t.equal(doc.getName('en'), 'test3', 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

module.exports.tests.lowercase_keys = function(test, common) {
var doc = new Document('a','b',1);
doc.setMeta('tags', { 'name:EN': 'test' });
Expand Down

0 comments on commit a8f0acb

Please sign in to comment.