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
This commit is contained in:
Nikolaj Kappler 2024-01-15 22:40:23 +01:00 committed by Thomas Basler
parent 6233ad12ae
commit f26e824247
6 changed files with 16 additions and 12 deletions

View File

@ -31,7 +31,7 @@ export default defineComponent({
computed: { computed: {
timeInHours() { timeInHours() {
return (value: number) => { return (value: number) => {
return timestampToString(value); return timestampToString(this.$i18n.locale, value)[0];
}; };
}, },
}, },

View File

@ -49,7 +49,7 @@
</tr> </tr>
<tr> <tr>
<th>{{ $t('firmwareinfo.Uptime') }}</th> <th>{{ $t('firmwareinfo.Uptime') }}</th>
<td>{{ timeInHours(systemStatus.uptime) }}</td> <td>{{ $t('firmwareinfo.UptimeValue', timeInHours(systemStatus.uptime)) }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -73,7 +73,8 @@ export default defineComponent({
computed: { computed: {
timeInHours() { timeInHours() {
return (value: number) => { return (value: number) => {
return timestampToString(value, true); const [count, time] = timestampToString(this.$i18n.locale, value, true);
return {count, time};
}; };
}, },
versionInfoUrl(): string { versionInfoUrl(): string {

View File

@ -188,7 +188,8 @@
"ResetReason0": "Reset Grund CPU 0", "ResetReason0": "Reset Grund CPU 0",
"ResetReason1": "Reset Grund CPU 1", "ResetReason1": "Reset Grund CPU 1",
"ConfigSaveCount": "Anzahl der Konfigurationsspeicherungen", "ConfigSaveCount": "Anzahl der Konfigurationsspeicherungen",
"Uptime": "Betriebszeit" "Uptime": "Betriebszeit",
"UptimeValue": "0 Tage {time} | 1 Tag {time} | {count} Tage {time}"
}, },
"hardwareinfo": { "hardwareinfo": {
"HardwareInformation": "Hardwareinformationen", "HardwareInformation": "Hardwareinformationen",

View File

@ -188,7 +188,8 @@
"ResetReason0": "Reset Reason CPU 0", "ResetReason0": "Reset Reason CPU 0",
"ResetReason1": "Reset Reason CPU 1", "ResetReason1": "Reset Reason CPU 1",
"ConfigSaveCount": "Config save count", "ConfigSaveCount": "Config save count",
"Uptime": "Uptime" "Uptime": "Uptime",
"UptimeValue": "0 days {time} | 1 day {time} | {count} days {time}"
}, },
"hardwareinfo": { "hardwareinfo": {
"HardwareInformation": "Hardware Information", "HardwareInformation": "Hardware Information",

View File

@ -188,7 +188,8 @@
"ResetReason0": "Raison de la réinitialisation CPU 0", "ResetReason0": "Raison de la réinitialisation CPU 0",
"ResetReason1": "Raison de la réinitialisation CPU 1", "ResetReason1": "Raison de la réinitialisation CPU 1",
"ConfigSaveCount": "Nombre d'enregistrements de la configuration", "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": { "hardwareinfo": {
"HardwareInformation": "Informations sur le matériel", "HardwareInformation": "Informations sur le matériel",
@ -616,4 +617,4 @@
"ValueSelected": "Sélectionné", "ValueSelected": "Sélectionné",
"ValueActive": "Activé" "ValueActive": "Activé"
} }
} }

View File

@ -1,8 +1,8 @@
export const timestampToString = (timestampSeconds: number, includeDays = false): string => { export const timestampToString = (locale: string, timestampSeconds: number, includeDays = false): string[] => {
const timeString = new Date(timestampSeconds * 1000).toLocaleTimeString([], { timeZone: "UTC" }); const timeString = new Date(timestampSeconds * 1000).toLocaleTimeString(locale, { timeZone: "UTC", hour12: false });
if (!includeDays) return timeString; if (!includeDays) return [timeString];
const secondsPerDay = 60 * 60 * 24; const secondsPerDay = 60 * 60 * 24;
const days = Math.floor(timestampSeconds / secondsPerDay); const days = Math.floor(timestampSeconds / secondsPerDay).toFixed(0);
return new Intl.RelativeTimeFormat().format(-days, "day") + " " + timeString; return [days, timeString];
} }