Skip to content

Commit 8a922b8

Browse files
Razen041ec5
andauthored
Now multiCombo Languages will show human readable languages instead of ISO codes (#11699)
* Now multiCombo Languages will show human readable languages * Exposed a function to get all the languages we have * Now the language fields will have all the languages and proper chip styling * others will be localized now, codes which are unknown will be omitted, and sorting will be done on the basis of local language * Language codes not known by iD will appear as monospaced font including others * Update CHANGELOG.md --------- Co-authored-by: Minh Nguyễn <mxn@1ec5.org>
1 parent a48ea8b commit 8a922b8

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
4545
#### :bug: Bugfixes
4646
* Fix some gpx/geojson properties not visible, such as numbers or complex data structures ([#11636], thanks [@k-yle])
4747
#### :earth_asia: Localization
48+
* The Languages field shows language names in your preferred language. ([#11699], thanks [@Razen04])
4849
#### :hourglass: Performance
4950
#### :mortar_board: Walkthrough / Help
5051
#### :hammer: Development
@@ -53,6 +54,8 @@ _Breaking developer changes, which may affect downstream projects or sites that
5354

5455
[#11522]: https://github.com/openstreetmap/iD/issues/11522
5556
[#11636]: https://github.com/openstreetmap/iD/pull/11636
57+
[#11699]: https://github.com/openstreetmap/iD/pull/11699
58+
[@Razen04]: https://github.com/Razen04
5659

5760
# v2.37.3
5861
##### 2025-10-31

modules/core/localizer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function coreLocalizer() {
6161
localizer.usesMetric = () => _usesMetric;
6262
localizer.languageNames = () => _languageNames;
6363
localizer.scriptNames = () => _scriptNames;
64+
localizer.languages = () => _dataLanguages; // Expose all the languages supported
6465

6566

6667
// The client app may want to manually set the locale, regardless of the

modules/ui/fields/combo.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { drag as d3_drag } from 'd3-drag';
44
import * as countryCoder from '@rapideditor/country-coder';
55

66
import { fileFetcher } from '../../core/file_fetcher';
7-
import { t } from '../../core/localizer';
7+
import { localizer, t } from '../../core/localizer';
88
import { services } from '../../services';
99
import { uiCombobox } from '../combobox';
1010
import { svgIcon } from '../../svg/icon';
@@ -114,6 +114,14 @@ export function uiFieldCombo(field, context) {
114114
// (for multiCombo, tval should be the key suffix, not the entire key)
115115
function displayValue(tval) {
116116
tval = tval || '';
117+
// Issue #11652
118+
// Ignore language: key and when tval is not others
119+
if (field.key === 'language:' && tval !== 'others'){
120+
let langName = localizer.languageName(tval);
121+
if (langName) {
122+
return langName;
123+
}
124+
}
117125

118126
var stringsField = field.resolveReference('stringsCrossReference');
119127
const labelId = getLabelId(stringsField, tval);
@@ -134,6 +142,13 @@ export function uiFieldCombo(field, context) {
134142
function renderValue(tval) {
135143
tval = tval || '';
136144

145+
// Issue #11652
146+
// Ignore language: key and when tval is not others
147+
if (field.key === 'language:' && tval !== 'others'){
148+
let langName = localizer.languageName(tval);
149+
if (langName) return selection => selection.text(langName);
150+
}
151+
137152
var stringsField = field.resolveReference('stringsCrossReference');
138153
const labelId = getLabelId(stringsField, tval);
139154
if (stringsField.hasTextForStringId(labelId)) {
@@ -178,6 +193,45 @@ export function uiFieldCombo(field, context) {
178193

179194
function getOptions(allOptions) {
180195
var stringsField = field.resolveReference('stringsCrossReference');
196+
// Get dropdown list for language: key via localizer instead of taginfo
197+
if (field.key === 'language:') {
198+
let codes = Object.keys(localizer.languages());
199+
200+
let options = codes.map((c) => {
201+
let name = localizer.languageName(c);
202+
203+
// Omit names which are null or equal to the code itself
204+
if (!name || name === c) return null;
205+
return {
206+
key: c,
207+
value: name,
208+
title: name,
209+
display: selection => selection.text(name)
210+
};
211+
}).filter(Boolean);
212+
213+
const localeCode = localizer.localeCode();
214+
215+
options.sort((a, b) => {
216+
return a.value.localeCompare(b.value, localeCode);
217+
});
218+
219+
const v = 'others';
220+
const labelId = getLabelId(stringsField, v);
221+
222+
// inserting others because it does not come via _dataLanguages
223+
options.push({
224+
key: v,
225+
value: stringsField.t(labelId, { default: v }),
226+
title: stringsField.t(`options.${v}.description`, { default: v }),
227+
display: addComboboxIcons(stringsField.t.append(labelId, { default: v }), v),
228+
klass: stringsField.hasTextForStringId(labelId) ? '' : 'raw-option'
229+
});
230+
231+
232+
return options;
233+
}
234+
181235
if (!(field.options || stringsField.options)) return [];
182236

183237
let options;
@@ -228,6 +282,9 @@ export function uiFieldCombo(field, context) {
228282
var queryFilter = d => d.value.toLowerCase().includes(q.toLowerCase()) || d.key.toLowerCase().includes(q.toLowerCase());
229283
if (hasStaticValues()) {
230284
setStaticValues(callback, queryFilter);
285+
286+
// If it is language field, we don't need to request for values, we get it from getOptions
287+
if (field.key === 'language:') return;
231288
}
232289

233290
var stringsField = field.resolveReference('stringsCrossReference');
@@ -293,8 +350,8 @@ export function uiFieldCombo(field, context) {
293350
key: v,
294351
value: label,
295352
title: stringsField.t(`options.${v}.description`, { default:
296-
isLocalizable ? v : (d.title !== label ? d.title : '') }),
297-
display: addComboboxIcons(stringsField.t.append(labelId, { default: v }), v),
353+
isLocalizable ? label : (d.title !== label ? d.title : '') }),
354+
display: addComboboxIcons(stringsField.t.append(labelId, { default: label }), v),
298355
klass: isLocalizable ? '' : 'raw-option'
299356
};
300357
});
@@ -716,6 +773,8 @@ export function uiFieldCombo(field, context) {
716773
.classed('raw-value', function(d) {
717774
var k = d.key;
718775
if (_isMulti) k = k.replace(field.key, '');
776+
// Ignore the raw-value class for key language:
777+
if (field.key === 'language:' && localizer.languageName(k) !== k) return false;
719778
return !stringsField.hasTextForStringId('options.' + k);
720779
})
721780
.classed('draggable', allowDragAndDrop)

0 commit comments

Comments
 (0)