mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
Add lang atttribute on multilingual names, wikidata/wikipedia fields (#10716)
This improves rendering of CJK names that contain unified ideographs that share a unicode codepoint, such as 化.
This commit is contained in:
@@ -470,6 +470,9 @@ export function uiFieldLocalized(field, context) {
|
||||
.attr('placeholder', function(d) {
|
||||
return Array.isArray(d.value) ? t('inspector.multiple_values') : t('translate.localized_translation_name');
|
||||
})
|
||||
.attr('lang', function (d) {
|
||||
return d.lang;
|
||||
})
|
||||
.classed('mixed', function(d) {
|
||||
return Array.isArray(d.value);
|
||||
});
|
||||
|
||||
@@ -275,14 +275,17 @@ export function uiFieldWikidata(field, context) {
|
||||
}
|
||||
|
||||
function setLabelForEntity() {
|
||||
var label = '';
|
||||
var label = {
|
||||
value: ''
|
||||
};
|
||||
if (_wikidataEntity) {
|
||||
label = entityPropertyForDisplay(_wikidataEntity, 'labels');
|
||||
if (label.length === 0) {
|
||||
label = _wikidataEntity.id.toString();
|
||||
if (label.value.length === 0) {
|
||||
label.value = _wikidataEntity.id.toString();
|
||||
}
|
||||
}
|
||||
utilGetSetValue(_searchInput, label);
|
||||
utilGetSetValue(_searchInput, label.value)
|
||||
.attr('lang', label.language);
|
||||
}
|
||||
|
||||
|
||||
@@ -319,10 +322,11 @@ export function uiFieldWikidata(field, context) {
|
||||
|
||||
_selection.select('.preset-wikidata-description')
|
||||
.style('display', function(){
|
||||
return description.length > 0 ? 'flex' : 'none';
|
||||
return description.value.length > 0 ? 'flex' : 'none';
|
||||
})
|
||||
.select('input')
|
||||
.attr('value', description);
|
||||
.attr('value', description.value)
|
||||
.attr('lang', description.language);
|
||||
|
||||
_selection.select('.preset-wikidata-identifier')
|
||||
.style('display', function(){
|
||||
@@ -355,19 +359,20 @@ export function uiFieldWikidata(field, context) {
|
||||
};
|
||||
|
||||
function entityPropertyForDisplay(wikidataEntity, propKey) {
|
||||
if (!wikidataEntity[propKey]) return '';
|
||||
var blankResponse = { value: '' };
|
||||
if (!wikidataEntity[propKey]) return blankResponse;
|
||||
var propObj = wikidataEntity[propKey];
|
||||
var langKeys = Object.keys(propObj);
|
||||
if (langKeys.length === 0) return '';
|
||||
if (langKeys.length === 0) return blankResponse;
|
||||
// sorted by priority, since we want to show the user's language first if possible
|
||||
var langs = wikidata.languagesToQuery();
|
||||
for (var i in langs) {
|
||||
var lang = langs[i];
|
||||
var valueObj = propObj[lang];
|
||||
if (valueObj && valueObj.value && valueObj.value.length > 0) return valueObj.value;
|
||||
if (valueObj && valueObj.value && valueObj.value.length > 0) return valueObj;
|
||||
}
|
||||
// default to any available value
|
||||
return propObj[langKeys[0]].value;
|
||||
return propObj[langKeys[0]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -204,7 +204,8 @@ export function uiFieldWikipedia(field, context) {
|
||||
value += '#' + anchor.replace(/_/g, ' ');
|
||||
}
|
||||
value = value.slice(0, 1).toUpperCase() + value.slice(1);
|
||||
utilGetSetValue(_langInput, nativeLangName);
|
||||
utilGetSetValue(_langInput, nativeLangName)
|
||||
.attr('lang', langInfo[2]);
|
||||
utilGetSetValue(_titleInput, value);
|
||||
}
|
||||
|
||||
@@ -281,6 +282,7 @@ export function uiFieldWikipedia(field, context) {
|
||||
if (tagLangInfo) {
|
||||
const nativeLangName = tagLangInfo[1];
|
||||
utilGetSetValue(_langInput, nativeLangName);
|
||||
_titleInput.attr('lang', tagLangInfo[2]); // for CJK and other display issues
|
||||
utilGetSetValue(_titleInput, tagArticleTitle + (anchor ? ('#' + anchor) : ''));
|
||||
_wikiURL = `${scheme}${tagLang}.${domain}/wiki/${wiki.encodePath(tagArticleTitle, anchor)}`;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user