Skip to content

Commit

Permalink
fix(systemtags): translations and etag method casing
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Oct 25, 2024
1 parent e02df8e commit 02602f0
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 43 deletions.
109 changes: 75 additions & 34 deletions apps/systemtags/src/components/SystemTagPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<NcDialog data-cy-systemtags-picker
:name="t('systemtags', 'Manage tags')"
:open="opened"
:class="'systemtags-picker--' + status"
class="systemtags-picker"
close-on-click-outside
out-transition
Expand Down Expand Up @@ -99,7 +100,7 @@ import { defineComponent } from 'vue'
import { emit } from '@nextcloud/event-bus'
import { sanitize } from 'dompurify'
import { showError, showInfo } from '@nextcloud/dialogs'
import { getLanguage, t } from '@nextcloud/l10n'
import { getLanguage, n, t } from '@nextcloud/l10n'
import escapeHTML from 'escape-html'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -122,10 +123,10 @@ type TagListCount = {
}

enum Status {
BASE,
LOADING,
CREATING_TAG,
DONE,
BASE = 'base',
LOADING = 'loading',
CREATING_TAG = 'creating-tag',
DONE = 'done',
}

export default defineComponent({
Expand Down Expand Up @@ -190,43 +191,79 @@ export default defineComponent({

statusMessage(): string {
if (this.toAdd.length === 0 && this.toRemove.length === 0) {
// should not happen™
return ''
}

if (this.toAdd.length === 1 && this.toRemove.length === 1) {
return t('systemtags', '{tag1} will be set and {tag2} will be removed from {count} files.', {
tag1: this.formatTagChip(this.toAdd[0]),
tag2: this.formatTagChip(this.toRemove[0]),
count: this.nodes.length,
}, undefined, { escape: false })
return n(
'systemtags',
'{tag1} will be set and {tag2} will be removed from 1 file.',
'{tag1} and {tag2} will be set and removed from {count} files.',
this.nodes.length,
{
tag1: this.formatTagChip(this.toAdd[0]),
tag2: this.formatTagChip(this.toRemove[0]),
count: this.nodes.length,
},
{ escape: false },
)
}

const tagsAdd = this.toAdd.map(this.formatTagChip)
const lastTagAdd = tagsAdd.pop() as string
const tagsRemove = this.toRemove.map(this.formatTagChip)
const lastTagRemove = tagsRemove.pop() as string

const addStringSingular = t('systemtags', '{tag} will be set to {count} files.', {
tag: lastTagAdd,
count: this.nodes.length,
}, undefined, { escape: false })

const removeStringSingular = t('systemtags', '{tag} will be removed from {count} files.', {
tag: lastTagRemove,
count: this.nodes.length,
}, undefined, { escape: false })

const addStringPlural = t('systemtags', '{tags} and {lastTag} will be set to {count} files.', {
tags: tagsAdd.join(', '),
lastTag: lastTagAdd,
count: this.nodes.length,
}, undefined, { escape: false })

const removeStringPlural = t('systemtags', '{tags} and {lastTag} will be removed from {count} files.', {
tags: tagsRemove.join(', '),
lastTag: lastTagRemove,
count: this.nodes.length,
}, undefined, { escape: false })
const addStringSingular = n(
'systemtags',
'{tag} will be set to 1 file.',
'{tag} will be set to {count} files.',
this.nodes.length,
{
tag: lastTagAdd,
count: this.nodes.length,
},
{ escape: false },
)

const removeStringSingular = n(
'systemtags',
'{tag} will be removed from 1 file.',
'{tag} will be removed from {count} files.',
this.nodes.length,
{
tag: lastTagRemove,
count: this.nodes.length,
},
{ escape: false },
)

const addStringPlural = n(
'systemtags',
'{tags} and {lastTag} will be set to 1 file.',
'{tags} and {lastTag} will be set to {count} files.',
this.nodes.length,
{
tags: tagsAdd.join(', '),
lastTag: lastTagAdd,
count: this.nodes.length,
},
{ escape: false },
)

const removeStringPlural = n(
'systemtags',
'{tags} and {lastTag} will be removed from 1 file.',
'{tags} and {lastTag} will be removed from {count} files.',
this.nodes.length,
{
tags: tagsRemove.join(', '),
lastTag: lastTagRemove,
count: this.nodes.length,
},
{ escape: false },
)

// Singular
if (this.toAdd.length === 1 && this.toRemove.length === 0) {
Expand All @@ -246,14 +283,14 @@ export default defineComponent({

// Mixed
if (this.toAdd.length > 1 && this.toRemove.length === 1) {
return `${addStringPlural}<br>${removeStringSingular}`
return `${addStringPlural} ${removeStringSingular}`
}
if (this.toAdd.length === 1 && this.toRemove.length > 1) {
return `${addStringSingular}<br>${removeStringPlural}`
return `${addStringSingular} ${removeStringPlural}`
}

// Both plural
return `${addStringPlural}<br>${removeStringPlural}`
return `${addStringPlural} ${removeStringPlural}`
},
},

Expand Down Expand Up @@ -452,6 +489,10 @@ export default defineComponent({
}
}

.systemtags-picker--done :deep(.empty-content__icon) {
opacity: 1;
}

// Rendered chip in note
.nc-chip {
display: inline !important;
Expand Down
2 changes: 0 additions & 2 deletions dist/4848-4848.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/4848-4848.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/4848-4848.js.map.license

This file was deleted.

Loading

0 comments on commit 02602f0

Please sign in to comment.