2424						<TableCell >
2525							<span  class =" text-lg-semibold"  >
2626								{{
27- 									row.name[currentLocale ]
28- 										? row.name[currentLocale ]
27+ 									row.name[primaryLocale ]
28+ 										? row.name[primaryLocale ]
2929										: getAlternativeDisplayName(row.name)
3030								}}
3131							</span >
5050								>
5151									<div >
5252										<label 
53- 											v-if =" supportedLocales .includes(localeName)" 
53+ 											v-if =" supportedFormLocalesKeys .includes(localeName)" 
5454											:for =" 
5555												'contributors-affiliations-' + 
5656												indexRow + 
7171									</div >
7272									<div >
7373										<input 
74- 											v-if =" supportedLocales .includes(localeName)" 
74+ 											v-if =" supportedFormLocalesKeys .includes(localeName)" 
7575											:id =" 
7676												'contributors-affiliations-' + 
7777												indexRow + 
8383											class =" pkpFormField__input pkpFormField--text__input" 
8484											type =" text" 
8585											name =" searchPhraseInput" 
86- 											aria-invalid =" 0 " 
86+ 											aria-invalid =" false " 
8787										/>
8888									</div >
8989								</div >
131131									class =" pkpFormField__input pkpFormField--text__input" 
132132									type =" text" 
133133									name =" affiliationsSearchPhraseInput" 
134- 									aria-invalid =" 0 " 
134+ 									aria-invalid =" false " 
135135									@keyup =" searchPhraseChanged" 
136136								/>
137137								  ; 
158158											@click =" selectRorOrganization(organization)" 
159159										>
160160											{{
161- 												organization.name[currentLocale ]
162- 													? organization.name[currentLocale ]
161+ 												organization.name[primaryLocale ]
162+ 													? organization.name[primaryLocale ]
163163													: organization.name[organization.displayLocale] +
164164														' [' +
165165														getLocaleDisplayName(organization.displayLocale) +
203203								>
204204									<div >
205205										<span 
206- 											v-if =" supportedLocales .includes(localeAddMode)" 
206+ 											v-if =" supportedFormLocalesKeys .includes(localeAddMode)" 
207207											class =" text-lg-normal" 
208208										>
209209											{{
218218									</div >
219219									<div >
220220										<input 
221- 											v-if =" supportedLocales .includes(localeAddMode)" 
221+ 											v-if =" supportedFormLocalesKeys .includes(localeAddMode)" 
222222											:id =" 
223223												'contributors-affiliations-newAffiliation' + 
224224												'-' + 
229229											class =" pkpFormField__input pkpFormField--text__input" 
230230											type =" text" 
231231											name =" affiliationsNewAffiliationPendingInput" 
232- 											aria-invalid =" 0 " 
232+ 											aria-invalid =" false " 
233233										/>
234234									</div >
235235								</div >
@@ -275,31 +275,44 @@ import {useFetch} from '@/composables/useFetch';
275275import  {useModal } from  ' @/composables/useModal'  ;
276276
277277const  props  =  defineProps ({
278- 	currentLocale:  {type:  String , default:  ' en'  }, 
279- 	supportedLocales:  {type:  Object , default :  () =>  {}}, 
280- 	localeDisplayNames:  {type:  Object , default :  () =>  {}}, 
281- 	value:  {type:  Array , default :  () =>  []}, 
282- 	authorId:  {type:  Number , default:  null }, 
278+ 	authorId:  { 
279+ 		type:  Number , 
280+ 		default:  null , 
281+ 	}, 
282+ 	primaryLocale:  { 
283+ 		type:  String , 
284+ 		default:  ' en'  , 
285+ 	}, 
286+ 	supportedFormLocales:  { 
287+ 		type:  Array , 
288+ 		default :  () =>  {}, 
289+ 	}, 
290+ 	value:  { 
291+ 		type:  Array , 
292+ 		default :  () =>  [], 
293+ 	}, 
283294}); 
284295
285- const  localeDisplayNames  =  props .localeDisplayNames ;
286- const  currentLocale  =  props .currentLocale ;
287- const  supportedLocales  =  props .supportedLocales ;
288- const  currentValue  =  props .value ;
289296const  authorId  =  props .authorId ;
297+ const  primaryLocale  =  props .primaryLocale ;
298+ const  supportedFormLocales  =  props .supportedFormLocales ;
299+ const  supportedFormLocalesKeys  =  supportedFormLocales .map (function  (language ) {
300+ 	return  language .key ; 
301+ }); 
302+ const  currentValue  =  props .value ;
290303const  apiResponse  =  ref ([]);
291304const  newAffiliationPending  =  ref ({});
292305const  searchPhrase  =  ref (' '  );
293306
294307const  selectCustomOrganization  =  function  () {
295308	newAffiliationPending .value  =  getNewItemTemplate (); 
296- 	newAffiliationPending .value .name [currentLocale ] =  searchPhrase .value ; 
309+ 	newAffiliationPending .value .name [primaryLocale ] =  searchPhrase .value ; 
297310	apiResponse .value  =  []; 
298311}; 
299312const  selectRorOrganization  =  function  (item ) {
300313	newAffiliationPending .value  =  getNewItemTemplate (); 
301314	newAffiliationPending .value .ror  =  item .ror ; 
302- 	supportedLocales .forEach ((locale ) =>  { 
315+ 	supportedFormLocalesKeys .forEach ((locale ) =>  { 
303316		if  (typeof  item .name [locale] !==  ' undefined'  ) { 
304317			newAffiliationPending .value .name [locale] =  item .name [locale]; 
305318		} 
@@ -320,7 +333,7 @@ const deleteAffiliation = function (index) {
320333		name:  ' sendAuthorEmail'  , 
321334		title:  t (' user.affiliations.deleteModal.title'  , {}), 
322335		message:  t (' user.affiliations.deleteModal.message'  , { 
323- 			institution:  currentValue[index][' name'  ][currentLocale ], 
336+ 			institution:  currentValue[index][' name'  ][primaryLocale ], 
324337		}), 
325338		actions:  [ 
326339			{ 
@@ -407,11 +420,11 @@ const closeEditMode = function () {
407420}; 
408421const  translations  =  function  (row ) {
409422	let  names =  row .name ; 
410- 	let  total =  supportedLocales .length ; 
423+ 	let  total =  supportedFormLocalesKeys .length ; 
411424	let  translated =  0 ; 
412425
413426	for  (let  key in  names) { 
414- 		if  (supportedLocales .includes (key) &&  names[key].length  >  0 ) { 
427+ 		if  (supportedFormLocalesKeys .includes (key) &&  names[key].length  >  0 ) { 
415428			translated++ ; 
416429		} 
417430	} 
@@ -444,7 +457,7 @@ async function searchPhraseChanged() {
444457
445458	if  (searchPhrase .value .length  >=  3 ) { 
446459		const  {apiUrl } =  useApiUrl (` rors/?searchPhrase=${ searchPhrase .value } `  ); 
447- 		const  {data , isSuccess , fetch } =  useFetch (apiUrl, {method:  ' GET'  }); 
460+ 		const  {data , isSuccess , fetch } =  useFetch (apiUrl . value , {method:  ' GET'  }); 
448461
449462		await  fetch (); 
450463
@@ -461,7 +474,7 @@ async function searchPhraseChanged() {
461474
462475function  makeCurrentValueCompatible () {
463476	Object .keys (currentValue).forEach ((index ) =>  { 
464- 		supportedLocales .forEach ((locale ) =>  { 
477+ 		supportedFormLocalesKeys .forEach ((locale ) =>  { 
465478			if  (! (locale in  currentValue[index].name )) { 
466479				currentValue[index].name [locale] =  ' '  ; 
467480			} 
@@ -477,24 +490,22 @@ function getNewItemTemplate() {
477490		name:  {}, 
478491	}; 
479492
480- 	supportedLocales .forEach ((locale ) =>  { 
493+ 	supportedFormLocalesKeys .forEach ((locale ) =>  { 
481494		newItem .name [locale] =  ' '  ; 
482495	}); 
483496
484497	return  newItem; 
485498} 
486499
487500function  getLocaleDisplayName (locale ) {
488- 	return  typeof  localeDisplayNames[locale] !==  ' undefined'  
489- 		?  localeDisplayNames[locale] 
490- 		:  locale; 
491- 
492- 	//  Gives sometimes errors 
493- 	//  if (typeof Intl === 'undefined') { 
494- 	//  	return locale; 
495- 	//  } 
496- 	//  const localeNames = new Intl.DisplayNames([currentLocale], {type: 'language'}); 
497- 	//  return localeNames.of(locale.replace('_', '-')); 
501+ 	let  displayName =  locale; 
502+ 	supportedFormLocales .forEach ((language ) =>  { 
503+ 		if  (language[' key'  ] ===  locale) { 
504+ 			displayName =  language[' label'  ]; 
505+ 		} 
506+ 	}); 
507+ 
508+ 	return  displayName; 
498509} 
499510
500511function  getAlternativeDisplayName (names ) {
0 commit comments