24
24
<TableCell >
25
25
<span class =" text-lg-semibold" >
26
26
{{
27
- row.name[currentLocale ]
28
- ? row.name[currentLocale ]
27
+ row.name[primaryLocale ]
28
+ ? row.name[primaryLocale ]
29
29
: getAlternativeDisplayName(row.name)
30
30
}}
31
31
</span >
50
50
>
51
51
<div >
52
52
<label
53
- v-if =" supportedLocales .includes(localeName)"
53
+ v-if =" supportedFormLocalesKeys .includes(localeName)"
54
54
:for ="
55
55
'contributors-affiliations-' +
56
56
indexRow +
71
71
</div >
72
72
<div >
73
73
<input
74
- v-if =" supportedLocales .includes(localeName)"
74
+ v-if =" supportedFormLocalesKeys .includes(localeName)"
75
75
:id ="
76
76
'contributors-affiliations-' +
77
77
indexRow +
83
83
class =" pkpFormField__input pkpFormField--text__input"
84
84
type =" text"
85
85
name =" searchPhraseInput"
86
- aria-invalid =" 0 "
86
+ aria-invalid =" false "
87
87
/>
88
88
</div >
89
89
</div >
131
131
class =" pkpFormField__input pkpFormField--text__input"
132
132
type =" text"
133
133
name =" affiliationsSearchPhraseInput"
134
- aria-invalid =" 0 "
134
+ aria-invalid =" false "
135
135
@keyup =" searchPhraseChanged"
136
136
/>
137
137
  ;
158
158
@click =" selectRorOrganization(organization)"
159
159
>
160
160
{{
161
- organization.name[currentLocale ]
162
- ? organization.name[currentLocale ]
161
+ organization.name[primaryLocale ]
162
+ ? organization.name[primaryLocale ]
163
163
: organization.name[organization.displayLocale] +
164
164
' [' +
165
165
getLocaleDisplayName(organization.displayLocale) +
203
203
>
204
204
<div >
205
205
<span
206
- v-if =" supportedLocales .includes(localeAddMode)"
206
+ v-if =" supportedFormLocalesKeys .includes(localeAddMode)"
207
207
class =" text-lg-normal"
208
208
>
209
209
{{
218
218
</div >
219
219
<div >
220
220
<input
221
- v-if =" supportedLocales .includes(localeAddMode)"
221
+ v-if =" supportedFormLocalesKeys .includes(localeAddMode)"
222
222
:id ="
223
223
'contributors-affiliations-newAffiliation' +
224
224
'-' +
229
229
class =" pkpFormField__input pkpFormField--text__input"
230
230
type =" text"
231
231
name =" affiliationsNewAffiliationPendingInput"
232
- aria-invalid =" 0 "
232
+ aria-invalid =" false "
233
233
/>
234
234
</div >
235
235
</div >
@@ -275,31 +275,44 @@ import {useFetch} from '@/composables/useFetch';
275
275
import {useModal } from ' @/composables/useModal' ;
276
276
277
277
const 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
+ },
283
294
});
284
295
285
- const localeDisplayNames = props .localeDisplayNames ;
286
- const currentLocale = props .currentLocale ;
287
- const supportedLocales = props .supportedLocales ;
288
- const currentValue = props .value ;
289
296
const 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 ;
290
303
const apiResponse = ref ([]);
291
304
const newAffiliationPending = ref ({});
292
305
const searchPhrase = ref (' ' );
293
306
294
307
const selectCustomOrganization = function () {
295
308
newAffiliationPending .value = getNewItemTemplate ();
296
- newAffiliationPending .value .name [currentLocale ] = searchPhrase .value ;
309
+ newAffiliationPending .value .name [primaryLocale ] = searchPhrase .value ;
297
310
apiResponse .value = [];
298
311
};
299
312
const selectRorOrganization = function (item ) {
300
313
newAffiliationPending .value = getNewItemTemplate ();
301
314
newAffiliationPending .value .ror = item .ror ;
302
- supportedLocales .forEach ((locale ) => {
315
+ supportedFormLocalesKeys .forEach ((locale ) => {
303
316
if (typeof item .name [locale] !== ' undefined' ) {
304
317
newAffiliationPending .value .name [locale] = item .name [locale];
305
318
}
@@ -320,7 +333,7 @@ const deleteAffiliation = function (index) {
320
333
name: ' sendAuthorEmail' ,
321
334
title: t (' user.affiliations.deleteModal.title' , {}),
322
335
message: t (' user.affiliations.deleteModal.message' , {
323
- institution: currentValue[index][' name' ][currentLocale ],
336
+ institution: currentValue[index][' name' ][primaryLocale ],
324
337
}),
325
338
actions: [
326
339
{
@@ -407,11 +420,11 @@ const closeEditMode = function () {
407
420
};
408
421
const translations = function (row ) {
409
422
let names = row .name ;
410
- let total = supportedLocales .length ;
423
+ let total = supportedFormLocalesKeys .length ;
411
424
let translated = 0 ;
412
425
413
426
for (let key in names) {
414
- if (supportedLocales .includes (key) && names[key].length > 0 ) {
427
+ if (supportedFormLocalesKeys .includes (key) && names[key].length > 0 ) {
415
428
translated++ ;
416
429
}
417
430
}
@@ -444,7 +457,7 @@ async function searchPhraseChanged() {
444
457
445
458
if (searchPhrase .value .length >= 3 ) {
446
459
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' });
448
461
449
462
await fetch ();
450
463
@@ -461,7 +474,7 @@ async function searchPhraseChanged() {
461
474
462
475
function makeCurrentValueCompatible () {
463
476
Object .keys (currentValue).forEach ((index ) => {
464
- supportedLocales .forEach ((locale ) => {
477
+ supportedFormLocalesKeys .forEach ((locale ) => {
465
478
if (! (locale in currentValue[index].name )) {
466
479
currentValue[index].name [locale] = ' ' ;
467
480
}
@@ -477,24 +490,22 @@ function getNewItemTemplate() {
477
490
name: {},
478
491
};
479
492
480
- supportedLocales .forEach ((locale ) => {
493
+ supportedFormLocalesKeys .forEach ((locale ) => {
481
494
newItem .name [locale] = ' ' ;
482
495
});
483
496
484
497
return newItem;
485
498
}
486
499
487
500
function 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;
498
509
}
499
510
500
511
function getAlternativeDisplayName (names ) {
0 commit comments