Skip to content

Commit

Permalink
Language TR added due to not correct working of supported form locale…
Browse files Browse the repository at this point in the history
…s; refactor because of removing labels for ror affiliations
  • Loading branch information
GaziYucel committed Jan 20, 2025
1 parent 01d93be commit 81b0017
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 122 deletions.
222 changes: 101 additions & 121 deletions src/components/Form/fields/FieldAffiliations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
:key="affiliationIndex"
>
<TableCell>
<div v-if="affiliation.name[primaryLocale]">
<div v-if="affiliation.name[primaryLocale].trim()">
<span class="text-lg-semibold">
{{ affiliation.name[primaryLocale] }}
</span>
Expand Down Expand Up @@ -68,7 +68,6 @@
:class="'h-6 w-6'"
:inline="true"
/>
&nbsp;
{{ translations(affiliation).label }}
</a>
<div v-if="affiliationIndex === indexEditMode">
Expand All @@ -78,61 +77,48 @@
)"
:key="affiliationNameLocale"
>
<div>
<span
v-if="
supportedFormLocaleKeys.includes(
affiliationNameLocale,
)
"
class="text-lg-semibold"
>
{{
t(
'user.affiliations.typeTranslationNameInLanguageLabel',
{
language: getLocaleDisplayName(
affiliationNameLocale,
),
},
)
}}
</span>
<span
v-if="affiliationNameLocale === primaryLocale"
class="pkpFormFieldLabel__required"
>
<span class="aria-hidden">*</span>
<span class="-screenReader">Required</span>
</span>
</div>
<div class="pkpFormField--sizelarge">
<input
v-if="
supportedFormLocaleKeys.includes(
affiliationNameLocale,
)
"
:id="
'contributors-affiliations-' +
affiliationIndex +
'-' +
affiliationNameLocale
"
v-model="affiliation.name[affiliationNameLocale]"
:readonly="!!affiliation.ror"
class="pkpFormField__input pkpFormField--text__input"
type="text"
name="searchPhraseInput"
:aria-invalid="false"
/>
<FieldError
v-if="
affiliationNameLocale === primaryLocale &&
!affiliation.name[affiliationNameLocale]
"
:messages="[t('validator.required', {})]"
/>
<div
v-if="supportedLocales.includes(affiliationNameLocale)"
>
<div>
<span class="text-lg-semibold">
{{ getTextFieldLabel(affiliationNameLocale) }}
</span>
<span
v-if="affiliationNameLocale === primaryLocale"
class="pkpFormFieldLabel__required"
>
<span class="aria-hidden">*</span>
<span class="-screenReader">Required</span>
</span>
</div>
<div class="pkpFormField--sizelarge">
<input
:id="
'contributors-affiliations-' +
affiliationIndex +
'-' +
affiliationNameLocale
"
v-model="affiliation.name[affiliationNameLocale]"
:name="
'contributors-affiliations-' +
affiliationIndex +
'-' +
affiliationNameLocale
"
class="pkpFormField__input pkpFormField--text__input"
type="text"
:aria-invalid="false"
/>
<FieldError
v-if="
affiliationNameLocale === primaryLocale &&
!affiliation.name[affiliationNameLocale].trim()
"
:messages="[t('validator.required', {})]"
/>
</div>
</div>
</div>
</div>
Expand All @@ -156,13 +142,13 @@
</TableRow>
<TableRow>
<TableCell>
<label class="text-lg-semibold">
<span class="text-lg-semibold">
{{
t('user.affiliations.searchPhraseLabel', {
language: getLocaleDisplayName(defaultLocale),
})
}}
</label>
</span>
<FieldAffiliationsRorAutoSuggest ref="autoSuggestRef" />
</TableCell>
<TableCell>
Expand Down Expand Up @@ -205,60 +191,48 @@
)"
:key="newAffiliationNameLocale"
>
<div>
<span
v-if="
supportedFormLocaleKeys.includes(
newAffiliationNameLocale,
)
"
class="text-lg-normal"
>
{{
t(
'user.affiliations.typeTranslationNameInLanguageLabel',
{
language: getLocaleDisplayName(
newAffiliationNameLocale,
),
},
)
}}
</span>
<span
v-if="newAffiliationNameLocale === primaryLocale"
class="pkpFormFieldLabel__required"
>
<span class="aria-hidden">*</span>
<span class="-screenReader">Required</span>
</span>
</div>
<div class="pkpFormField--sizelarge">
<input
v-if="
supportedFormLocaleKeys.includes(
newAffiliationNameLocale,
)
"
:id="
'contributors-affiliations-newAffiliation' +
'-' +
newAffiliationNameLocale
"
v-model="newAffiliation.name[newAffiliationNameLocale]"
:readonly="!!newAffiliation.ror"
class="pkpFormField__input pkpFormField--text__input"
type="text"
name="affiliationsNewAffiliationPendingInput"
aria-invalid="false"
/>
<FieldError
v-if="
newAffiliationNameLocale === primaryLocale &&
!newAffiliation.name[newAffiliationNameLocale]
"
:messages="[t('validator.required', {})]"
/>
<div
v-if="supportedLocales.includes(newAffiliationNameLocale)"
>
<div>
<span class="text-lg-normal">
{{ getTextFieldLabel(newAffiliationNameLocale) }}
</span>
<span
v-if="newAffiliationNameLocale === primaryLocale"
class="pkpFormFieldLabel__required"
>
<span class="aria-hidden">*</span>
<span class="-screenReader">Required</span>
</span>
</div>
<div class="pkpFormField--sizelarge">
<input
:id="
'contributors-affiliations-newAffiliation-' +
newAffiliationNameLocale
"
v-model="
newAffiliation.name[newAffiliationNameLocale]
"
:name="
'contributors-affiliations-newAffiliation-' +
newAffiliationNameLocale
"
class="pkpFormField__input pkpFormField--text__input"
type="text"
aria-invalid="false"
/>
<FieldError
v-if="
newAffiliationNameLocale === primaryLocale &&
!newAffiliation.name[
newAffiliationNameLocale
].trim()
"
:messages="[t('validator.required', {})]"
/>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -297,17 +271,17 @@
<script setup>
import {ref, computed, onMounted, watch, onBeforeUnmount} from 'vue';
import {t} from '@/utils/i18n';
import {useModal} from '@/composables/useModal';
import DropdownActions from '@/components/DropdownActions/DropdownActions.vue';
import FieldError from '@/components/Form/FieldError.vue';
import FieldAffiliationsRorAutoSuggest from '@/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue';
import Icon from '@/components/Icon/Icon.vue';
import PkpTable from '@/components/Table/Table.vue';
import TableHeader from '@/components/Table/TableHeader.vue';
import TableBody from '@/components/Table/TableBody.vue';
import TableRow from '@/components/Table/TableRow.vue';
import TableColumn from '@/components/Table/TableColumn.vue';
import TableCell from '@/components/Table/TableCell.vue';
import {useModal} from '@/composables/useModal';
import FieldAffiliationsRorAutoSuggest from '@/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue';
import FieldError from '@/components/Form/FieldError.vue';
const props = defineProps({
/** Field key used for form submission */
Expand Down Expand Up @@ -360,7 +334,7 @@ const currentValue = computed({
get: () => props.value,
set: (newVal) => emit('change', props.name, 'value', newVal),
});
const supportedFormLocaleKeys = props.locales.map((language) => language.key);
const supportedLocales = props.locales.map((language) => language.key);
const defaultLocale = 'en';
const autoSuggestRef = ref(null);
const autoSuggestSelected = computed({
Expand Down Expand Up @@ -438,7 +412,7 @@ function insertToAffiliationsList() {
function getNewAffiliationTemplate() {
let names = {};
names[primaryLocale] = '';
supportedFormLocaleKeys.forEach((locale) => {
supportedLocales.forEach((locale) => {
names[locale] = '';
});
names = sortNamesPrimaryLocaleFirst(names);
Expand Down Expand Up @@ -539,7 +513,7 @@ function deleteRow(index) {
function makeCurrentValueCompatible() {
currentValue.value.forEach((affiliation, index) => {
supportedFormLocaleKeys.forEach((locale) => {
supportedLocales.forEach((locale) => {
if (!(locale in currentValue.value[index].name)) {
currentValue.value[index].name[locale] = '';
}
Expand Down Expand Up @@ -577,11 +551,11 @@ function translations(affiliation) {
let result = {
label: '',
count: 0,
total: supportedFormLocaleKeys.length,
total: supportedLocales.length,
};
let names = affiliation.name;
Object.keys(names).forEach((key) => {
if (supportedFormLocaleKeys.includes(key) && names[key].length > 0) {
if (supportedLocales.includes(key) && names[key].length > 0) {
result.count++;
}
});
Expand All @@ -596,6 +570,12 @@ function translations(affiliation) {
return result;
}
function getTextFieldLabel(locale) {
return t('user.affiliations.typeTranslationNameInLanguageLabel', {
language: getLocaleDisplayName(locale),
});
}
onMounted(() => {
makeCurrentValueCompatible();
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/Form/mocks/field-affiliations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
en: 'Simon Fraser University',
fr_CA: 'Simon Fraser University',
de: 'Simon Fraser University',
tr: 'TR',
tr: 'Simon Fraser Üniversitesi',
},
},
{
Expand All @@ -28,6 +28,7 @@ export default {
en: 'Delft University of Technology',
fr_CA: '',
de: 'Technische Universität Delft',
tr: 'Delft Teknik Üniversitesi',
},
},
{
Expand All @@ -38,6 +39,7 @@ export default {
en: 'German National Library of Science and Technology',
fr_CA: '',
de: 'Technische Informationsbibliothek (TIB)',
tr: 'Teknik Bilgi Kütübanesi',
},
},
],
Expand Down

0 comments on commit 81b0017

Please sign in to comment.