Files
kandev/apps/web/lib/utils/file-change-status.ts
T
João Salavisa 5257dfbaab fix(web): close the i18n coverage gaps in the non-JSX scanner and locale catalogs (#2727)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 23:03:29 +00:00

44 lines
1.2 KiB
TypeScript

import { t } from "@/lib/i18n";
export type FileChangeStatus = "modified" | "added" | "deleted" | "untracked" | "renamed";
export function normalizeFileChangeStatus(status?: string): FileChangeStatus {
switch (status) {
case "added":
case "modified":
case "deleted":
case "untracked":
case "renamed":
return status;
case "removed":
return "deleted";
default:
return "modified";
}
}
/**
* Accessible name and tooltip for a changed file's status marker.
*
* Resolves at call time (`FileStatusIcon` calls it from its render body), so a
* locale switch re-labels the markers.
*/
export function fileChangeStatusLabel(status: FileChangeStatus, oldPath?: string): string {
switch (status) {
case "added":
return t("diff:fileStatusAdded");
case "untracked":
return t("diff:fileStatusUntracked");
case "modified":
return t("diff:fileStatusModified");
case "deleted":
return t("diff:fileStatusDeleted");
case "renamed":
return oldPath ? t("diff:fileStatusMovedFrom", { oldPath }) : t("diff:fileStatusMoved");
default: {
const exhaustiveStatus: never = status;
return exhaustiveStatus;
}
}
}