Support locales in taginfo. Fixes #678

This commit is contained in:
Tom MacWright
2013-02-07 18:24:01 -05:00
parent 645dcebbfe
commit 27e7df888d
+48 -21
View File
@@ -119,30 +119,45 @@ iD.ui.inspector = function() {
removeBtn.append('span') removeBtn.append('span')
.attr('class', 'icon delete'); .attr('class', 'icon delete');
var helpBtn = row.append('button') function findLocal(docs) {
.attr('tabindex', -1) var locale = iD.detect().locale.toLowerCase(),
.attr('class', 'tag-help minor') localized;
.on('click', function(d) {
var params = _.extend({}, d, { localized = _.find(docs, function(d) {
geometry: entity.geometry(context.graph()) return d.lang.toLowerCase() === locale;
}); });
if (d.key && d.value) { if (localized) return localized;
taginfo.docs(params, function(err, docs) {
var en; // try the non-regional version of a language, like
if (!err && docs) { // 'en' if the language is 'en-US'
en = _.find(docs, function(d) { if (locale.indexOf('-') !== -1) {
return d.lang == 'en'; var first = locale.split('-')[0];
localized = _.find(docs, function(d) {
return d.lang.toLowerCase() === first;
});
if (localized) return localized;
}
// finally fall back to english
return _.find(docs, function(d) {
return d.lang.toLowerCase() === 'en';
}); });
} }
if (en) {
function keyValueReference(err, docs) {
var local;
if (!err && docs) {
local = findLocal(docs);
}
if (local) {
var types = []; var types = [];
if (en.on_area) types.push('area'); if (local.on_area) types.push('area');
if (en.on_node) types.push('point'); if (local.on_node) types.push('point');
if (en.on_way) types.push('line'); if (local.on_way) types.push('line');
en.types = types; local.types = types;
iD.ui.modal(context.container()) iD.ui.modal(context.container())
.select('.content') .select('.content')
.datum(en) .datum(local)
.call(iD.ui.tagReference); .call(iD.ui.tagReference);
} else { } else {
iD.ui.flash(context.container()) iD.ui.flash(context.container())
@@ -150,9 +165,9 @@ iD.ui.inspector = function() {
.append('h3') .append('h3')
.text(t('inspector.no_documentation_combination')); .text(t('inspector.no_documentation_combination'));
} }
}); }
} else if (d.key) {
taginfo.values(params, function(err, values) { function keyReference(err, values) {
if (!err && values.data.length) { if (!err && values.data.length) {
iD.ui.modal(context.container()) iD.ui.modal(context.container())
.select('.content') .select('.content')
@@ -168,7 +183,19 @@ iD.ui.inspector = function() {
.append('h3') .append('h3')
.text(t('inspector.no_documentation_key')); .text(t('inspector.no_documentation_key'));
} }
}
var helpBtn = row.append('button')
.attr('tabindex', -1)
.attr('class', 'tag-help minor')
.on('click', function(d) {
var params = _.extend({}, d, {
geometry: entity.geometry(context.graph())
}); });
if (d.key && d.value) {
taginfo.docs(params, keyValueReference);
} else if (d.key) {
taginfo.values(params, keyReference);
} }
}); });