mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-16 02:32:53 +00:00
Support locales in taginfo. Fixes #678
This commit is contained in:
@@ -119,6 +119,72 @@ iD.ui.inspector = function() {
|
||||
removeBtn.append('span')
|
||||
.attr('class', 'icon delete');
|
||||
|
||||
function findLocal(docs) {
|
||||
var locale = iD.detect().locale.toLowerCase(),
|
||||
localized;
|
||||
|
||||
localized = _.find(docs, function(d) {
|
||||
return d.lang.toLowerCase() === locale;
|
||||
});
|
||||
if (localized) return localized;
|
||||
|
||||
// try the non-regional version of a language, like
|
||||
// 'en' if the language is 'en-US'
|
||||
if (locale.indexOf('-') !== -1) {
|
||||
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';
|
||||
});
|
||||
}
|
||||
|
||||
function keyValueReference(err, docs) {
|
||||
var local;
|
||||
if (!err && docs) {
|
||||
local = findLocal(docs);
|
||||
}
|
||||
if (local) {
|
||||
var types = [];
|
||||
if (local.on_area) types.push('area');
|
||||
if (local.on_node) types.push('point');
|
||||
if (local.on_way) types.push('line');
|
||||
local.types = types;
|
||||
iD.ui.modal(context.container())
|
||||
.select('.content')
|
||||
.datum(local)
|
||||
.call(iD.ui.tagReference);
|
||||
} else {
|
||||
iD.ui.flash(context.container())
|
||||
.select('.content')
|
||||
.append('h3')
|
||||
.text(t('inspector.no_documentation_combination'));
|
||||
}
|
||||
}
|
||||
|
||||
function keyReference(err, values) {
|
||||
if (!err && values.data.length) {
|
||||
iD.ui.modal(context.container())
|
||||
.select('.content')
|
||||
.datum({
|
||||
data: values.data,
|
||||
title: 'Key:' + params.key,
|
||||
geometry: params.geometry
|
||||
})
|
||||
.call(iD.keyReference(context));
|
||||
} else {
|
||||
iD.ui.flash(context.container())
|
||||
.select('.content')
|
||||
.append('h3')
|
||||
.text(t('inspector.no_documentation_key'));
|
||||
}
|
||||
}
|
||||
|
||||
var helpBtn = row.append('button')
|
||||
.attr('tabindex', -1)
|
||||
.attr('class', 'tag-help minor')
|
||||
@@ -127,48 +193,9 @@ iD.ui.inspector = function() {
|
||||
geometry: entity.geometry(context.graph())
|
||||
});
|
||||
if (d.key && d.value) {
|
||||
taginfo.docs(params, function(err, docs) {
|
||||
var en;
|
||||
if (!err && docs) {
|
||||
en = _.find(docs, function(d) {
|
||||
return d.lang == 'en';
|
||||
});
|
||||
}
|
||||
if (en) {
|
||||
var types = [];
|
||||
if (en.on_area) types.push('area');
|
||||
if (en.on_node) types.push('point');
|
||||
if (en.on_way) types.push('line');
|
||||
en.types = types;
|
||||
iD.ui.modal(context.container())
|
||||
.select('.content')
|
||||
.datum(en)
|
||||
.call(iD.ui.tagReference);
|
||||
} else {
|
||||
iD.ui.flash(context.container())
|
||||
.select('.content')
|
||||
.append('h3')
|
||||
.text(t('inspector.no_documentation_combination'));
|
||||
}
|
||||
});
|
||||
taginfo.docs(params, keyValueReference);
|
||||
} else if (d.key) {
|
||||
taginfo.values(params, function(err, values) {
|
||||
if (!err && values.data.length) {
|
||||
iD.ui.modal(context.container())
|
||||
.select('.content')
|
||||
.datum({
|
||||
data: values.data,
|
||||
title: 'Key:' + params.key,
|
||||
geometry: params.geometry
|
||||
})
|
||||
.call(iD.keyReference(context));
|
||||
} else {
|
||||
iD.ui.flash(context.container())
|
||||
.select('.content')
|
||||
.append('h3')
|
||||
.text(t('inspector.no_documentation_key'));
|
||||
}
|
||||
});
|
||||
taginfo.values(params, keyReference);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user