diff --git a/whosonfirst/feature.js b/whosonfirst/feature.js index 5654689..9b9619d 100644 --- a/whosonfirst/feature.js +++ b/whosonfirst/feature.js @@ -50,9 +50,15 @@ feature.getLocalLanguages = (feat, type = 'official') => { // see: https://github.com/whosonfirst-data/whosonfirst-data/issues/2154 feature.getPlacetypeLocal = (feat) => _.flatten( feature.getLocalLanguages(feat, 'official') - .map(lang => `label:${lang}_x_preferred_placetype`) - .concat(['wof:placetype_local']) - .map(prop => _.get(feat, `properties.${prop}`)) + .concat(['eng']) // fallback to English when no other languages are available + .map(lang => { + const endonym = _.get(feat, `properties.label:${lang}_x_preferred_placetype`) + + // When a localized placetype isn't in a latin char set then WOF often provides + // a transliteration we can include in a parenthetical, like: مقاطعة (muhafazah) + const latinized = _.get(feat, `properties.label:${lang}_latn_x_preferred_placetype`) + return (endonym && latinized) ? endonym + ` (${latinized})` : endonym + }) ).filter(val => _.isString(val) && !_.isEmpty(val)) module.exports = feature diff --git a/whosonfirst/feature.test.js b/whosonfirst/feature.test.js index b4ffb76..c857c21 100644 --- a/whosonfirst/feature.test.js +++ b/whosonfirst/feature.test.js @@ -80,19 +80,45 @@ module.exports.getLocalLanguages = (test) => { module.exports.getPlacetypeLocal = (test) => { test('getPlacetypeLocal', (t) => { t.deepEqual([], feature.getPlacetypeLocal({})) - t.deepEqual(['LOCAL_PLACETYPE'], feature.getPlacetypeLocal({ + t.deepEqual([], feature.getPlacetypeLocal({ properties: { 'wof:placetype_local': 'LOCAL_PLACETYPE' } })) - t.deepEqual(['LOCAL_PLACETYPE'], feature.getPlacetypeLocal({ - properties: { 'wof:placetype_local': ['LOCAL_PLACETYPE'] } - })) - t.deepEqual(['ENDONYM_PLACETYPE', 'LOCAL_PLACETYPE'], feature.getPlacetypeLocal({ + t.deepEqual(['ENDONYM_PLACETYPE'], feature.getPlacetypeLocal({ properties: { 'wof:lang_x_official': 'und', 'label:und_x_preferred_placetype': 'ENDONYM_PLACETYPE', 'wof:placetype_local': 'LOCAL_PLACETYPE' } })) + // Makkah, Saudi Arabia + t.deepEqual(['مقاطعة (muhafazah)', 'region'], feature.getPlacetypeLocal({ + properties: { + 'wof:lang_x_official': 'ara', + 'label:ara_x_preferred_placetype': 'مقاطعة', + 'label:ara_latn_x_preferred_placetype': 'muhafazah', + 'label:eng_x_preferred_placetype': 'region', + 'wof:placetype': 'region' + } + })) + // Glasgow, Scotland, UK + t.deepEqual(['unitary district'], feature.getPlacetypeLocal({ + properties: { + 'wof:lang_x_official': 'und', + 'label:eng_x_preferred_placetype': 'unitary district', + 'wof:placetype_local': 'unitary district', + 'wof:placetype': 'county' + } + })) + // Madrid, province in Spain + t.deepEqual(['provincia', 'province'], feature.getPlacetypeLocal({ + properties: { + 'wof:lang_x_official': 'spa', + 'label:spa_x_preferred_placetype': 'provincia', + 'label:eng_x_preferred_placetype': 'province', + 'wof:placetype_local': 'autonomous community', // old junk data + 'wof:placetype': 'region' + } + })) t.end() }) } diff --git a/whosonfirst/view/shapefile.js b/whosonfirst/view/shapefile.js index 116eff6..7e594fc 100644 --- a/whosonfirst/view/shapefile.js +++ b/whosonfirst/view/shapefile.js @@ -29,7 +29,7 @@ module.exports = (feat, params) => { parent_id: spr.parent_id, name: spr.name, placetype: spr.placetype, - placelocal: _.first(feature.getPlacetypeLocal(feat)) || '', // note: not a SPR field + placelocal: feature.getPlaceTypeLocal(feat), country: spr.country, repo: spr.repo, lat: spr.latitude,