Skip to content

Commit

Permalink
fix #1649
Browse files Browse the repository at this point in the history
one of the goals of my pull request, besides simplifying the code was to have localization.

It's nice that the browser can handle this, but for consistency, we'll go with vue-i18n since it is already available
  • Loading branch information
nkappler authored and tbnobody committed Jan 18, 2024
1 parent 6233ad1 commit f26e824
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/EventLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineComponent({
computed: {
timeInHours() {
return (value: number) => {
return timestampToString(value);
return timestampToString(this.$i18n.locale, value)[0];
};
},
},
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/FirmwareInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</tr>
<tr>
<th>{{ $t('firmwareinfo.Uptime') }}</th>
<td>{{ timeInHours(systemStatus.uptime) }}</td>
<td>{{ $t('firmwareinfo.UptimeValue', timeInHours(systemStatus.uptime)) }}</td>
</tr>
</tbody>
</table>
Expand All @@ -73,7 +73,8 @@ export default defineComponent({
computed: {
timeInHours() {
return (value: number) => {
return timestampToString(value, true);
const [count, time] = timestampToString(this.$i18n.locale, value, true);
return {count, time};
};
},
versionInfoUrl(): string {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"ResetReason0": "Reset Grund CPU 0",
"ResetReason1": "Reset Grund CPU 1",
"ConfigSaveCount": "Anzahl der Konfigurationsspeicherungen",
"Uptime": "Betriebszeit"
"Uptime": "Betriebszeit",
"UptimeValue": "0 Tage {time} | 1 Tag {time} | {count} Tage {time}"
},
"hardwareinfo": {
"HardwareInformation": "Hardwareinformationen",
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"ResetReason0": "Reset Reason CPU 0",
"ResetReason1": "Reset Reason CPU 1",
"ConfigSaveCount": "Config save count",
"Uptime": "Uptime"
"Uptime": "Uptime",
"UptimeValue": "0 days {time} | 1 day {time} | {count} days {time}"
},
"hardwareinfo": {
"HardwareInformation": "Hardware Information",
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"ResetReason0": "Raison de la réinitialisation CPU 0",
"ResetReason1": "Raison de la réinitialisation CPU 1",
"ConfigSaveCount": "Nombre d'enregistrements de la configuration",
"Uptime": "Temps de fonctionnement"
"Uptime": "Durée de fonctionnement",
"UptimeValue": "0 jour {time} | 1 jour {time} | {count} jours {time}"
},
"hardwareinfo": {
"HardwareInformation": "Informations sur le matériel",
Expand Down Expand Up @@ -616,4 +617,4 @@
"ValueSelected": "Sélectionné",
"ValueActive": "Activé"
}
}
}
10 changes: 5 additions & 5 deletions webapp/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const timestampToString = (timestampSeconds: number, includeDays = false): string => {
const timeString = new Date(timestampSeconds * 1000).toLocaleTimeString([], { timeZone: "UTC" });
if (!includeDays) return timeString;
export const timestampToString = (locale: string, timestampSeconds: number, includeDays = false): string[] => {
const timeString = new Date(timestampSeconds * 1000).toLocaleTimeString(locale, { timeZone: "UTC", hour12: false });
if (!includeDays) return [timeString];

const secondsPerDay = 60 * 60 * 24;
const days = Math.floor(timestampSeconds / secondsPerDay);
return new Intl.RelativeTimeFormat().format(-days, "day") + " " + timeString;
const days = Math.floor(timestampSeconds / secondsPerDay).toFixed(0);
return [days, timeString];
}

0 comments on commit f26e824

Please sign in to comment.