mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-02-01 04:24:32 +01:00
i18n for prettyPrintTime functions
`openLinkProgrammatically.ts` mentions that i18n doesn't work in utils; maybe that comment is outdated? I've also added the translations for Spanish and that tested well. Removed the `formatExpiration` function as it appears to no longer be used.
This commit is contained in:
committed by
Paul Miller
parent
875eeeb4e9
commit
76fff52f43
@@ -760,5 +760,25 @@
|
||||
"pick": "Pick a federation",
|
||||
"skip_confirm": "You'll need to pay chain and channel fees to use Mutiny, and miss out on advanced features such as lightning address. You can change your mind later in the settings."
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"hours_future_one": "one hour from now",
|
||||
"hours_future_other": "{{count}} hours from now",
|
||||
"hours_past_one": "one hour ago",
|
||||
"hours_past_other": "{{count}} hours ago",
|
||||
"hours_short": "{{count}}h",
|
||||
"days_future_one": "one day from now",
|
||||
"days_future_other": "{{count}} days from now",
|
||||
"days_past_one": "one day ago",
|
||||
"days_past_other": "{{count}} days ago",
|
||||
"days_short": "{{count}}d",
|
||||
"minutes_future_one": "one minute from now",
|
||||
"minutes_future_other": "{{count}} minutes from now",
|
||||
"minutes_past_one": "one minute ago",
|
||||
"minutes_past_other": "{{count}} minutes ago",
|
||||
"minutes_short": "{{count}}m",
|
||||
"nowish": "Nowish",
|
||||
"seconds_future": "seconds from now",
|
||||
"seconds_past": "Just now"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@
|
||||
"channel_size": "Tamaño canal",
|
||||
"channel_reserve": "- Reserva canal",
|
||||
"error_under_min_lightning": "En-cadena por defecto. El monto es demasiado pequeño para su recepción en Lightning.",
|
||||
"error_creating_unified": "En-cadena por defecto. Also salió mal al crear la dirección unificada",
|
||||
"error_creating_address": "Also salió mal al crear la dirección en-cadena",
|
||||
"error_creating_unified": "En-cadena por defecto. Algo salió mal al crear la dirección unificada",
|
||||
"error_creating_address": "Algo salió mal al crear la dirección en-cadena",
|
||||
"amount_editable": {
|
||||
"receive_too_small": "Una comisión de instalación de lightning puede ser deducida del monto solicitado.",
|
||||
"setup_fee_lightning": "Se cargará una comisión de instalación de lightning si se paga por lightning.",
|
||||
@@ -664,5 +664,25 @@
|
||||
},
|
||||
"profile": {
|
||||
"manage_federation": "Manejar Federaciones"
|
||||
},
|
||||
"utils": {
|
||||
"hours_future_one": "en una hora",
|
||||
"hours_future_other": "en {{count}} horas",
|
||||
"hours_past_one": "hace una hora",
|
||||
"hours_past_other": "hace {{count}} horas",
|
||||
"hours_short": "{{count}}h",
|
||||
"days_future_one": "en un día",
|
||||
"days_future_other": "en {{count}} días",
|
||||
"days_past_one": "hace un día",
|
||||
"days_past_other": "hace {{count}} días",
|
||||
"days_short": "{{count}}d",
|
||||
"minutes_future_one": "en un minuto",
|
||||
"minutes_future_other": "en {{count}} minutos",
|
||||
"minutes_past_one": "hace un minuto",
|
||||
"minutes_past_other": "hace {{count}} minutos",
|
||||
"minutes_short": "{{count}}m",
|
||||
"nowish": "Casi ahora",
|
||||
"seconds_future": "en algunos segundos",
|
||||
"seconds_past": "Justo ahora"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { useI18n } from "~/i18n/context";
|
||||
|
||||
export function prettyPrintTime(ts: number) {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: "numeric",
|
||||
@@ -15,11 +17,12 @@ export function timeAgo(
|
||||
ts?: number | bigint,
|
||||
_rerenderSignal?: number
|
||||
): string {
|
||||
if (!ts || ts === 0) return "Pending";
|
||||
const i18n = useI18n();
|
||||
|
||||
if (!ts || ts === 0) return i18n.t("common.pending");
|
||||
const timestamp = Number(ts) * 1000;
|
||||
const now = Date.now();
|
||||
const negative = now - timestamp < 0;
|
||||
const nowOrAgo = negative ? "from now" : "ago";
|
||||
const tense = now - timestamp < 0 ? "future" : "past";
|
||||
const elapsedMilliseconds = Math.abs(now - timestamp);
|
||||
const elapsedSeconds = Math.floor(elapsedMilliseconds / 1000);
|
||||
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
||||
@@ -27,15 +30,13 @@ export function timeAgo(
|
||||
const elapsedDays = Math.floor(elapsedHours / 24);
|
||||
|
||||
if (elapsedSeconds < 60) {
|
||||
return negative ? "seconds from now" : "Just now";
|
||||
return i18n.t(`utils.seconds_${tense}`);
|
||||
} else if (elapsedMinutes < 60) {
|
||||
return `${elapsedMinutes} minute${
|
||||
elapsedMinutes > 1 ? "s" : ""
|
||||
} ${nowOrAgo}`;
|
||||
return i18n.t(`utils.minutes_${tense}`, { count: elapsedMinutes });
|
||||
} else if (elapsedHours < 24) {
|
||||
return `${elapsedHours} hour${elapsedHours > 1 ? "s" : ""} ${nowOrAgo}`;
|
||||
return i18n.t(`utils.hours_${tense}`, { count: elapsedHours });
|
||||
} else if (elapsedDays < 7) {
|
||||
return `${elapsedDays} day${elapsedDays > 1 ? "s" : ""} ${nowOrAgo}`;
|
||||
return i18n.t(`utils.days_${tense}`, { count: elapsedDays });
|
||||
} else {
|
||||
const date = new Date(timestamp);
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
@@ -46,7 +47,9 @@ export function timeAgo(
|
||||
}
|
||||
|
||||
export function veryShortTimeStamp(ts?: number | bigint) {
|
||||
if (!ts || ts === 0) return "Pending";
|
||||
const i18n = useI18n();
|
||||
|
||||
if (!ts || ts === 0) return i18n.t("common.pending");
|
||||
const timestamp = Number(ts) * 1000;
|
||||
const now = Date.now();
|
||||
const elapsedMilliseconds = Math.abs(now - timestamp);
|
||||
@@ -56,13 +59,13 @@ export function veryShortTimeStamp(ts?: number | bigint) {
|
||||
const elapsedDays = Math.floor(elapsedHours / 24);
|
||||
|
||||
if (elapsedSeconds < 60) {
|
||||
return "Nowish";
|
||||
return i18n.t("utils.nowish");
|
||||
} else if (elapsedMinutes < 60) {
|
||||
return `${elapsedMinutes}m`;
|
||||
return i18n.t("utils.minutes_short", { count: elapsedMinutes });
|
||||
} else if (elapsedHours < 24) {
|
||||
return `${elapsedHours}h`;
|
||||
return i18n.t("utils.hours_short", { count: elapsedHours });
|
||||
} else if (elapsedDays < 7) {
|
||||
return `${elapsedDays}d`;
|
||||
return i18n.t("utils.days_short", { count: elapsedDays });
|
||||
} else {
|
||||
const date = new Date(timestamp);
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
@@ -71,15 +74,3 @@ export function veryShortTimeStamp(ts?: number | bigint) {
|
||||
return `${month}/${day}/${year}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatExpiration(expiration?: bigint) {
|
||||
if (!expiration) {
|
||||
return "Unknown expiration";
|
||||
}
|
||||
|
||||
if (expiration <= Date.now() / 1000) {
|
||||
return "Expired";
|
||||
}
|
||||
|
||||
return `Expires ${timeAgo(expiration)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user