Skip to content

Commit 870f4b7

Browse files
committed
refactor(vue): inline t() directly in PersonalSettings, remove const label block
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0b63a13 commit 870f4b7

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

src/views/PersonalSettings.vue

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
1010
:class="{ 'profile-fields-personal--embedded': embedded }">
1111
<header v-if="!embedded" class="profile-fields-personal__hero">
1212
<div>
13-
<h2>Additional profile fields</h2>
13+
<h2>{{ t('profile_fields', 'Additional profile fields') }}</h2>
1414
</div>
1515
</header>
1616

@@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
2222
<NcLoadingIcon :size="32" />
2323
</div>
2424

25-
<NcEmptyContent v-else-if="sortedFields.length === 0" name="No additional fields yet" description="Your administrator has not assigned additional profile fields to your account yet." />
25+
<NcEmptyContent v-else-if="sortedFields.length === 0" :name="t('profile_fields', 'No additional fields yet')" :description="t('profile_fields', 'Your administrator has not assigned additional profile fields to your account yet.')" />
2626

2727
<div v-else class="profile-fields-personal__grid" :class="{ 'profile-fields-personal__grid--embedded': embedded }">
2828
<article
@@ -41,11 +41,11 @@ SPDX-License-Identifier: AGPL-3.0-or-later
4141
<span class="profile-fields-personal__readonly-text">{{ resolvedDisplayValue(field) }}</span>
4242
<NcPopover placement="bottom" :triggers="['hover', 'focus']" :popover-triggers="['hover']" no-focus-trap>
4343
<template #trigger="{ attrs }">
44-
<span v-bind="attrs" class="profile-fields-personal__info-trigger" :aria-label="`${field.definition.label}: managed by your administrator`">
44+
<span v-bind="attrs" class="profile-fields-personal__info-trigger" :aria-label="t('profile_fields', '{fieldLabel}: managed by your administrator', { fieldLabel: field.definition.label })">
4545
<NcIconSvgWrapper :path="mdiInformationOutline" :size="14" />
4646
</span>
4747
</template>
48-
<p class="profile-fields-personal__popover-copy">Managed by your administrator.</p>
48+
<p class="profile-fields-personal__popover-copy">{{ t('profile_fields', 'Managed by your administrator.') }}</p>
4949
</NcPopover>
5050
</div>
5151
</div>
@@ -57,13 +57,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later
5757
<label :for="field.can_edit ? fieldInputId(field.definition.id) : undefined">{{ field.definition.label }}</label>
5858
<NcPopover v-if="!embedded && !field.can_edit" placement="end" :triggers="['hover', 'focus']" :popover-triggers="['hover']" no-focus-trap>
5959
<template #trigger="{ attrs }">
60-
<span v-bind="attrs" class="profile-fields-personal__chip-trigger" aria-label="Read-only field">
60+
<span v-bind="attrs" class="profile-fields-personal__chip-trigger" :aria-label="t('profile_fields', 'Read-only field')">
6161
<span class="profile-fields-personal__readonly-indicator" aria-hidden="true">
6262
<NcIconSvgWrapper :path="mdiLockOutline" :size="12" />
6363
</span>
6464
</span>
6565
</template>
66-
<p class="profile-fields-personal__popover-copy">Managed by your administrator.</p>
66+
<p class="profile-fields-personal__popover-copy">{{ t('profile_fields', 'Managed by your administrator.') }}</p>
6767
</NcPopover>
6868
</div>
6969
</div>
@@ -105,7 +105,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
105105
</span>
106106

107107
<div v-if="!embedded" class="profile-fields-personal__embedded-toolbar">
108-
<label class="profile-fields-personal__embedded-visibility-label" :for="`profile-fields-personal-visibility-${field.definition.id}`">{{ visibilityControlLabel }}</label>
108+
<label class="profile-fields-personal__embedded-visibility-label" :for="`profile-fields-personal-visibility-${field.definition.id}`">{{ t('profile_fields', 'Who can see this') }}</label>
109109
<NcSelect
110110
:input-id="`profile-fields-personal-visibility-${field.definition.id}`"
111111
class="profile-fields-personal__visibility-select"
@@ -120,7 +120,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
120120
/>
121121

122122
<NcButton variant="primary" :disabled="isSaving(field.definition.id) || !hasFieldChanges(field)" @click="saveField(field)">
123-
{{ isSaving(field.definition.id) ? 'Saving changes...' : 'Save changes' }}
123+
{{ isSaving(field.definition.id) ? t('profile_fields', 'Saving changes...') : t('profile_fields', 'Save changes') }}
124124
</NcButton>
125125
</div>
126126

@@ -131,8 +131,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
131131

132132
<Teleport v-if="embedded && embeddedVisibilityAnchorReady && editableVisibilityFields.length > 0" to="#profile-fields-personal-visibility-anchor">
133133
<div class="profile-fields-personal__visibility-teleport-root" data-testid="profile-fields-personal-visibility-panel" role="group" :aria-labelledby="visibilitySectionHeadingId" :aria-describedby="visibilitySectionDescriptionId">
134-
<h3 :id="visibilitySectionHeadingId" class="profile-fields-personal__sr-only">Additional profile field visibility</h3>
135-
<p :id="visibilitySectionDescriptionId" class="profile-fields-personal__sr-only">Choose who can see each additional profile field on your profile.</p>
134+
<h3 :id="visibilitySectionHeadingId" class="profile-fields-personal__sr-only">{{ t('profile_fields', 'Additional profile field visibility') }}</h3>
135+
<p :id="visibilitySectionDescriptionId" class="profile-fields-personal__sr-only">{{ t('profile_fields', 'Choose who can see each additional profile field on your profile.') }}</p>
136136
<div
137137
v-for="field in editableVisibilityFields"
138138
:key="`embedded-visibility-${field.definition.id}`"
@@ -164,8 +164,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
164164
:aria-labelledby="visibilitySectionHeadingId"
165165
:aria-describedby="visibilitySectionDescriptionId"
166166
data-testid="profile-fields-personal-visibility-panel">
167-
<h3 :id="visibilitySectionHeadingId" class="profile-fields-personal__sr-only">Additional profile field visibility</h3>
168-
<p :id="visibilitySectionDescriptionId" class="profile-fields-personal__sr-only">Choose who can see each additional profile field on your profile.</p>
167+
<h3 :id="visibilitySectionHeadingId" class="profile-fields-personal__sr-only">{{ t('profile_fields', 'Additional profile field visibility') }}</h3>
168+
<p :id="visibilitySectionDescriptionId" class="profile-fields-personal__sr-only">{{ t('profile_fields', 'Choose who can see each additional profile field on your profile.') }}</p>
169169
<div class="profile-fields-personal__visibility-grid">
170170
<div
171171
v-for="field in editableVisibilityFields"
@@ -206,8 +206,6 @@ import { visibilityOptions } from '../utils/visibilityOptions.js'
206206
const embedded = inject<boolean>('profileFieldsEmbedded', false)
207207
const visibilitySectionHeadingId = 'profile-fields-personal-visibility-heading'
208208
const visibilitySectionDescriptionId = 'profile-fields-personal-visibility-description'
209-
const visibilityControlLabel = t('profile_fields', 'Who can see this')
210-
211209
const fields = ref<EditableField[]>([])
212210
const isLoading = ref(true)
213211
const globalError = ref('')
@@ -252,7 +250,7 @@ const placeholderForField = (field: EditableField) => {
252250
}
253251
254252
if (field.definition.type === 'select') {
255-
return 'Select an option'
253+
return t('profile_fields', 'Select an option')
256254
}
257255
258256
return ''
@@ -272,7 +270,7 @@ const loadFields = async() => {
272270
fields.value = await listEditableFields()
273271
fields.value.forEach(normaliseEditableField)
274272
} catch (error) {
275-
globalError.value = error instanceof Error ? error.message : 'Could not load your additional profile fields.'
273+
globalError.value = error instanceof Error ? error.message : t('profile_fields', 'Could not load your additional profile fields.')
276274
} finally {
277275
isLoading.value = false
278276
}
@@ -304,15 +302,18 @@ const currentDraftValue = (field: EditableField) => draftValues[field.definition
304302
const autosaveAnnouncement = (field: EditableField) => {
305303
const fieldId = field.definition.id
306304
if (fieldHasError(fieldId)) {
307-
return `${field.definition.label}: ${fieldHelperText(fieldId)}`
305+
return t('profile_fields', '{fieldLabel}: {message}', {
306+
fieldLabel: field.definition.label,
307+
message: fieldHelperText(fieldId),
308+
})
308309
}
309310
310311
if (fieldSaveSucceeded(fieldId)) {
311-
return `${field.definition.label} saved.`
312+
return t('profile_fields', '{fieldLabel} saved.', { fieldLabel: field.definition.label })
312313
}
313314
314315
if (isSaving(fieldId)) {
315-
return `Saving ${field.definition.label}.`
316+
return t('profile_fields', 'Saving {fieldLabel}.', { fieldLabel: field.definition.label })
316317
}
317318
318319
return ''
@@ -339,7 +340,7 @@ const currentStoredValue = (field: EditableField) => {
339340
340341
const resolvedDisplayValue = (field: EditableField) => {
341342
const value = currentStoredValue(field) || draftValues[field.definition.id] || ''
342-
return value === '' ? 'Not set' : value
343+
return value === '' ? t('profile_fields', 'Not set') : value
343344
}
344345
345346
const findField = (fieldId: number) => fields.value.find((field: EditableField) => field.definition.id === fieldId)
@@ -473,7 +474,7 @@ const saveField = async(field: EditableField) => {
473474
normaliseEditableField(field)
474475
queueSuccessState(fieldId)
475476
} catch (error: any) {
476-
fieldErrors[fieldId] = error?.response?.data?.ocs?.data?.message ?? error?.message ?? 'Could not save this field. Please try again.'
477+
fieldErrors[fieldId] = error?.response?.data?.ocs?.data?.message ?? error?.message ?? t('profile_fields', 'Could not save this field. Please try again.')
477478
} finally {
478479
savingIds.value = savingIds.value.filter((id: number) => id !== fieldId)
479480
}

0 commit comments

Comments
 (0)