feat: use i18n interpolation for minutes and hours

This commit is contained in:
Zamitto 2024-05-03 09:19:56 -03:00
parent a98a0eadd8
commit 30ed41be61
2 changed files with 17 additions and 10 deletions

View File

@ -61,6 +61,8 @@
"copied_link_to_clipboard": "Link copiado", "copied_link_to_clipboard": "Link copiado",
"hours": "horas", "hours": "horas",
"minutes": "minutos", "minutes": "minutos",
"amount_hours": "{{amount}} horas",
"amount_minutes": "{{amount}} minutos",
"accuracy": "{{accuracy}}% de precisão", "accuracy": "{{accuracy}}% de precisão",
"add_to_library": "Adicionar à biblioteca", "add_to_library": "Adicionar à biblioteca",
"remove_from_library": "Remover da biblioteca", "remove_from_library": "Remover da biblioteca",

View File

@ -57,19 +57,24 @@ export function HeroPanel({
} }
}, [game?.lastTimePlayed, formatDistance]); }, [game?.lastTimePlayed, formatDistance]);
const formatPlayTime = (milliseconds: number) => { const formatPlayTime = () => {
const seconds = milliseconds / 1000 const milliseconds = game?.playTimeInMilliseconds || 0;
const minutes = seconds / 60 const seconds = milliseconds / 1000;
const minutes = seconds / 60;
if (minutes < 120) { if (minutes < 120) {
return minutes.toFixed(0) + " " + t("minutes") return t("amount_minutes", {
} amount: minutes.toFixed(0),
});
}
const numberFormat = new Intl.NumberFormat(i18n.language, { maximumFractionDigits: 1 }) const numberFormat = new Intl.NumberFormat(i18n.language, {
maximumFractionDigits: 1,
});
const hours = minutes / 60 const hours = minutes / 60;
return numberFormat.format(hours) + " " + t("hours") return t("amount_hours", { amount: numberFormat.format(hours) });
} };
const finalDownloadSize = useMemo(() => { const finalDownloadSize = useMemo(() => {
if (!game) return "N/A"; if (!game) return "N/A";