Skip to content

Commit 6ae4ea1

Browse files
committed
refactor(vue): inline t() directly in AdminSelectOptionsSection, remove const labels
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4bb27a7 commit 6ae4ea1

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

src/components/admin/AdminSelectOptionsSection.vue

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ SPDX-License-Identifier: AGPL-3.0-or-later
77
<section class="profile-fields-admin-options">
88
<div class="profile-fields-admin-options__heading">
99
<div>
10-
<h4>Options</h4>
10+
<h4>{{ t('profile_fields', 'Options') }}</h4>
1111
</div>
1212
<div class="profile-fields-admin-options__meta">
1313
<strong>{{ normalizedOptionCount }}</strong>
14-
<span>{{ normalizedOptionCount === 1 ? 'option' : 'options' }}</span>
14+
<span>{{ optionsCountLabel }}</span>
1515
</div>
1616
</div>
1717

@@ -35,32 +35,32 @@ SPDX-License-Identifier: AGPL-3.0-or-later
3535
:data-testid="`profile-fields-admin-option-handle-${index}`"
3636
variant="tertiary-no-background"
3737
size="small"
38-
:aria-label="`Reorder option ${element.value}`">
38+
:aria-label="reorderOptionLabel(element.value)">
3939
<template #icon>
4040
<NcIconSvgWrapper :path="mdiDragVertical" :size="18" />
4141
</template>
4242
<NcActionButton :disabled="!canMoveOptionUp(index) || isSaving" @click="moveOption(index, -1)">
4343
<template #icon>
4444
<NcIconSvgWrapper :path="mdiArrowUp" :size="18" />
4545
</template>
46-
Move up
47-
</NcActionButton>
48-
<NcActionButton :disabled="!canMoveOptionDown(index) || isSaving" @click="moveOption(index, 1)">
49-
<template #icon>
50-
<NcIconSvgWrapper :path="mdiArrowDown" :size="18" />
51-
</template>
52-
Move down
46+
{{ t('profile_fields', 'Move up') }}
47+
</NcActionButton>
48+
<NcActionButton :disabled="!canMoveOptionDown(index) || isSaving" @click="moveOption(index, 1)">
49+
<template #icon>
50+
<NcIconSvgWrapper :path="mdiArrowDown" :size="18" />
51+
</template>
52+
{{ t('profile_fields', 'Move down') }}
5353
</NcActionButton>
5454
</NcActions>
5555
<div v-else class="profile-fields-admin-options__handle-spacer" aria-hidden="true" />
5656
</div>
5757
<NcInputField
5858
:model-value="element.value"
59-
label="Option value"
59+
:label="t('profile_fields', 'Option value')"
6060
label-outside
61-
:placeholder="`Option ${index + 1}`"
61+
:placeholder="optionPlaceholder(index + 1)"
6262
:error="isOptionDuplicate(index)"
63-
:helper-text="isOptionDuplicate(index) ? 'This option is duplicated.' : ''"
63+
:helper-text="isOptionDuplicate(index) ? t('profile_fields', 'This option is duplicated.') : ''"
6464
@update:model-value="updateOption(index, $event)"
6565
@keydown.enter.prevent="addOptionFromEnter(index, $event)"
6666
@keydown.backspace="removeEmptyOptionFromKeyboard(index, $event)"
@@ -70,7 +70,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
7070
<div class="profile-fields-admin-options__actions">
7171
<NcButton
7272
variant="tertiary-no-background"
73-
:aria-label="`Remove option ${element.value || String(index + 1)}`"
73+
:aria-label="removeOptionLabel(element.value || String(index + 1))"
7474
@click.prevent="removeOption(index)">
7575
<template #icon>
7676
<NcIconSvgWrapper :path="mdiClose" :size="20" />
@@ -83,43 +83,43 @@ SPDX-License-Identifier: AGPL-3.0-or-later
8383

8484
<div class="profile-fields-admin-options__toolbar">
8585
<NcButton variant="secondary" data-testid="profile-fields-admin-add-option" @click.prevent="addOption">
86-
Add single option
87-
</NcButton>
88-
<NcButton variant="secondary" data-testid="profile-fields-admin-add-multiple-options" @click.prevent="openBulkOptionsDialog">
89-
Add multiple options
86+
{{ t('profile_fields', 'Add single option') }}
87+
</NcButton>
88+
<NcButton variant="secondary" data-testid="profile-fields-admin-add-multiple-options" @click.prevent="openBulkOptionsDialog">
89+
{{ t('profile_fields', 'Add multiple options') }}
9090
</NcButton>
9191
</div>
9292

9393
<NcDialog
9494
:open="isBulkOptionsDialogOpen"
95-
name="Add multiple options"
95+
:name="t('profile_fields', 'Add multiple options')"
9696
content-classes="profile-fields-admin-options__bulk-options-dialog"
9797
size="normal"
9898
@update:open="updateBulkOptionsDialogOpen">
9999
<div class="profile-fields-admin-options__bulk-options-content">
100100
<NcTextArea
101101
data-testid="profile-fields-admin-bulk-options-input"
102102
:model-value="bulkOptionInput"
103-
label="Options list (one per line)"
104-
placeholder="One option per line"
103+
:label="t('profile_fields', 'Options list (one per line)')"
104+
:placeholder="t('profile_fields', 'One option per line')"
105105
resize="vertical"
106106
rows="10"
107107
@update:model-value="bulkOptionInput = $event" />
108108
<p class="profile-fields-admin-options__bulk-options-summary">
109-
{{ bulkOptionValues.length === 1 ? '1 option ready.' : `${bulkOptionValues.length} options ready.` }}
109+
{{ bulkOptionsSummary }}
110110
</p>
111111
</div>
112112

113113
<template #actions>
114114
<NcButton @click="closeBulkOptionsDialog">
115-
Cancel
115+
{{ t('profile_fields', 'Cancel') }}
116116
</NcButton>
117117
<NcButton
118118
variant="primary"
119119
data-testid="profile-fields-admin-bulk-options-submit"
120120
:disabled="bulkOptionValues.length === 0"
121121
@click="applyBulkOptions">
122-
Add selected options
122+
{{ t('profile_fields', 'Add selected options') }}
123123
</NcButton>
124124
</template>
125125
</NcDialog>
@@ -128,6 +128,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
128128

129129
<script setup lang="ts">
130130
import { mdiArrowDown, mdiArrowUp, mdiClose, mdiDragVertical } from '@mdi/js'
131+
import { n, t } from '@nextcloud/l10n'
131132
import { computed, ref } from 'vue'
132133
import Draggable from 'vuedraggable'
133134
import NcDialog from '@nextcloud/vue/components/NcDialog'
@@ -154,6 +155,8 @@ const createOptionId = () => `option-local-${nextOptionId++}`
154155
const options = computed(() => props.modelValue)
155156
const bulkOptionValues = computed(() => parseEditableSelectOptionValues(bulkOptionInput.value))
156157
const normalizedOptionCount = computed(() => extractEditableSelectOptionValues(options.value).filter((optionValue: string) => optionValue.trim() !== '').length)
158+
const optionsCountLabel = computed(() => n('profile_fields', 'option', 'options', normalizedOptionCount.value, { count: normalizedOptionCount.value }))
159+
const bulkOptionsSummary = computed(() => n('profile_fields', '1 option ready.', '{count} options ready.', bulkOptionValues.value.length, { count: bulkOptionValues.value.length }))
157160
158161
const duplicateOptionIndices = computed(() => {
159162
const seen = new Map<string, number>()
@@ -181,6 +184,9 @@ const hasOptionValue = (index: number) => options.value[index]?.value.trim() !==
181184
const canMoveOptionUp = (index: number) => index > 0
182185
const canMoveOptionDown = (index: number) => index < options.value.length - 1
183186
const isOptionDuplicate = (index: number) => duplicateOptionIndices.value.has(index)
187+
const reorderOptionLabel = (optionValue: string) => t('profile_fields', 'Reorder option {optionValue}', { optionValue })
188+
const optionPlaceholder = (position: number) => t('profile_fields', 'Option {position}', { position })
189+
const removeOptionLabel = (optionValue: string) => t('profile_fields', 'Remove option {optionValue}', { optionValue })
184190
185191
const focusOptionInput = async(index: number) => {
186192
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)