mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Pluralize values instead of parenthesis
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export const pluralRules = {
|
||||
file: "files",
|
||||
insertion: "insertions",
|
||||
deletion: "deletions",
|
||||
commit: "commits",
|
||||
issue: "issues",
|
||||
contributor: "contributors",
|
||||
patch: "patches",
|
||||
} as const;
|
||||
|
||||
export function pluralize(
|
||||
singular: keyof typeof pluralRules,
|
||||
count: number,
|
||||
): string {
|
||||
return count === 1 ? singular : pluralRules[singular];
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
import PeerSelector from "@app/views/projects/PeerSelector.svelte";
|
||||
import { closeFocused } from "@app/components/Floating.svelte";
|
||||
import { config } from "@app/lib/config";
|
||||
import { pluralize } from "@app/lib/pluralize";
|
||||
|
||||
export let activeRoute: ProjectRoute;
|
||||
export let project: Project;
|
||||
@@ -120,7 +121,7 @@
|
||||
active={activeRoute.params.view.resource === "history"}
|
||||
on:click={() => toggleContent("history", true)}>
|
||||
<span class="txt-bold">{tree.stats.commits}</span>
|
||||
commit(s)
|
||||
{pluralize("commit", tree.stats.commits)}
|
||||
</HeaderToggleLabel>
|
||||
<HeaderToggleLabel
|
||||
ariaLabel="Issue count"
|
||||
@@ -128,7 +129,7 @@
|
||||
clickable
|
||||
on:click={() => toggleContent("issues", false)}>
|
||||
<span class="txt-bold">{project.issues.open ?? 0}</span>
|
||||
issue(s)
|
||||
{pluralize("issue", project.issues.open)}
|
||||
</HeaderToggleLabel>
|
||||
<HeaderToggleLabel
|
||||
ariaLabel="Patch count"
|
||||
@@ -136,10 +137,10 @@
|
||||
clickable
|
||||
on:click={() => toggleContent("patches", false)}>
|
||||
<span class="txt-bold">{project.patches.open ?? 0}</span>
|
||||
patch(es)
|
||||
{pluralize("patch", project.patches.open)}
|
||||
</HeaderToggleLabel>
|
||||
<HeaderToggleLabel ariaLabel="Contributor count">
|
||||
<span class="txt-bold">{tree.stats.contributors}</span>
|
||||
contributor(s)
|
||||
{pluralize("contributor", tree.stats.contributors)}
|
||||
</HeaderToggleLabel>
|
||||
</header>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Diff, DiffStats } from "@app/lib/diff";
|
||||
|
||||
import FileDiff from "@app/views/projects/SourceBrowser/FileDiff.svelte";
|
||||
import { pluralize } from "@app/lib/pluralize";
|
||||
|
||||
export let diff: Diff;
|
||||
export let stats: DiffStats;
|
||||
@@ -9,13 +11,15 @@
|
||||
const s = [];
|
||||
|
||||
if (modified.length) {
|
||||
s.push(`${modified.length} file(s) changed`);
|
||||
s.push(
|
||||
`${modified.length} ${pluralize("file", modified.length)} changed`,
|
||||
);
|
||||
}
|
||||
if (added.length) {
|
||||
s.push(`${added.length} file(s) added`);
|
||||
s.push(`${added.length} ${pluralize("file", added.length)} added`);
|
||||
}
|
||||
if (deleted.length) {
|
||||
s.push(`${deleted.length} file(s) deleted`);
|
||||
s.push(`${deleted.length} ${pluralize("file", deleted.length)} deleted`);
|
||||
}
|
||||
return s.join(", ");
|
||||
};
|
||||
@@ -37,9 +41,15 @@
|
||||
<div class="changeset-summary">
|
||||
<span>{diffDescription(diff)}</span>
|
||||
with
|
||||
<span class="additions">{stats.insertions} insertion(s)</span>
|
||||
<span class="additions">
|
||||
{stats.insertions}
|
||||
{pluralize("insertion", stats.insertions)}
|
||||
</span>
|
||||
and
|
||||
<span class="deletions">{stats.deletions} deletion(s)</span>
|
||||
<span class="deletions">
|
||||
{stats.deletions}
|
||||
{pluralize("deletion", stats.deletions)}
|
||||
</span>
|
||||
</div>
|
||||
<div class="diff-listing">
|
||||
{#each diff.added as file}
|
||||
|
||||
Reference in New Issue
Block a user