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",
"hours": "horas",
"minutes": "minutos",
"amount_hours": "{{amount}} horas",
"amount_minutes": "{{amount}} minutos",
"accuracy": "{{accuracy}}% de precisão",
"add_to_library": "Adicionar à biblioteca",
"remove_from_library": "Remover da biblioteca",

View File

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