Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for localized alt_name tag #582

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ module.exports = function(){

// Map localized names which begin with 'name:'
// @ref: http://wiki.openstreetmap.org/wiki/Namespace#Language_code_suffix
var suffix = getNameSuffix( key );
let suffix = getNameSuffix( key, 'name:');
let altSuffix = getNameSuffix( key, 'alt_name:');
if( suffix ){
var val1 = trim( value );
if( val1 ){
doc.setName( suffix, val1 );
}
} else if ( altSuffix ) {
let val1 = trim(value);
if (val1){
doc.setNameAlias( altSuffix, val1 );
}
}

// Map name data from our name mapping schema
else if( _.has(NAME_SCHEMA, key) ){
var val2 = trim( value );
Expand Down Expand Up @@ -133,14 +138,13 @@ function trim( str ){

// extract name suffix, eg for 'name:EN' return 'en'
// if not valid, return false.
function getNameSuffix( tag ){

if( tag.length < 6 || tag.substr(0,5) !== 'name:' ){
function getNameSuffix( tag, prefix ){
if( tag.length < 6 || tag.substr(0, prefix.length) !== prefix ){
return false;
}

// normalize suffix
var suffix = tag.substr(5).toLowerCase();
var suffix = tag.substr(prefix.length).toLowerCase();

// check the suffix is in the localized key list
if( LOCALIZED_NAME_KEYS.indexOf(suffix) === -1 ){
Expand Down
17 changes: 17 additions & 0 deletions test/stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ module.exports.tests.localised_names = function(test, common) {
});
};

module.exports.tests.localised_alt_names = function(test, common) {
var doc = new Document('a','b',1);
doc.setMeta('tags', { 'name:en': 'test', 'alt_name:en': 'alt_lest', 'name:es': 'prueba', 'alt_name:es': 'alt_prueba' });
test('maps - localised names', function(t) {
var stream = mapper();
stream.pipe( through.obj( function( doc, enc, next ){
t.equal(doc.getName('en'), 'test', 'correctly mapped');
t.equal(doc.getName('es'), 'prueba', 'correctly mapped');
t.deepEqual(doc.getNameAliases('en'), ['alt_lest'], 'correctly mapped');
t.deepEqual(doc.getNameAliases('es'), ['alt_prueba'], 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

module.exports.tests.osm_names = function(test, common) {
test('maps - default name', function(t) {
var doc = new Document('a','b',1);
Expand Down