@@ -4,7 +4,7 @@ import { drag as d3_drag } from 'd3-drag';
44import * as countryCoder from '@rapideditor/country-coder' ;
55
66import { fileFetcher } from '../../core/file_fetcher' ;
7- import { t } from '../../core/localizer' ;
7+ import { localizer , t } from '../../core/localizer' ;
88import { services } from '../../services' ;
99import { uiCombobox } from '../combobox' ;
1010import { 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