diff --git a/webapp/src/components/InverterChannelInfo.vue b/webapp/src/components/InverterChannelInfo.vue index 0b4830c..0025a3b 100644 --- a/webapp/src/components/InverterChannelInfo.vue +++ b/webapp/src/components/InverterChannelInfo.vue @@ -19,7 +19,12 @@ @@ -31,7 +36,6 @@ diff --git a/webapp/src/components/InverterTotalInfo.vue b/webapp/src/components/InverterTotalInfo.vue index 1fceb19..5952c24 100644 --- a/webapp/src/components/InverterTotalInfo.vue +++ b/webapp/src/components/InverterTotalInfo.vue @@ -4,7 +4,11 @@
{{ $t('invertertotalinfo.TotalYieldTotal') }}
-

{{ formatNumber(totalData.YieldTotal.v, totalData.YieldTotal.d) }} +

+ {{ $n(totalData.YieldTotal.v, 'decimal', { + minimumFractionDigits: totalData.YieldTotal.d, + maximumFractionDigits: totalData.YieldTotal.d + })}} {{ totalData.YieldTotal.u }}

@@ -14,7 +18,11 @@
{{ $t('invertertotalinfo.TotalYieldDay') }}
-

{{ formatNumber(totalData.YieldDay.v, totalData.YieldDay.d) }} +

+ {{ $n(totalData.YieldDay.v, 'decimal', { + minimumFractionDigits: totalData.YieldDay.d, + maximumFractionDigits: totalData.YieldDay.d + })}} {{ totalData.YieldDay.u }}

@@ -24,7 +32,11 @@
{{ $t('invertertotalinfo.TotalPower') }}
-

{{ formatNumber(totalData.Power.v, totalData.Power.d) }} +

+ {{ $n(totalData.Power.v, 'decimal', { + minimumFractionDigits: totalData.Power.d, + maximumFractionDigits: totalData.Power.d + })}} {{ totalData.Power.u }}

@@ -35,15 +47,11 @@ \ No newline at end of file diff --git a/webapp/src/locales/index.ts b/webapp/src/locales/index.ts index cf15b27..64104da 100644 --- a/webapp/src/locales/index.ts +++ b/webapp/src/locales/index.ts @@ -57,4 +57,49 @@ export const dateTimeFormats: I18nOptions["datetimeFormats"] = { } }; +export const numberFormats: I18nOptions["numberFormats"] = { + [Locales.EN]: { + decimal: { + style: 'decimal', + }, + decimalNoDigits: { + style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0 + }, + decimalTwoDigits: { + style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 + }, + percent: { + style: 'percent', + }, + }, + [Locales.DE]: { + decimal: { + style: 'decimal', + }, + decimalNoDigits: { + style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0 + }, + decimalTwoDigits: { + style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 + }, + percent: { + style: 'percent', + }, + }, + [Locales.FR]: { + decimal: { + style: 'decimal', + }, + decimalNoDigits: { + style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0 + }, + decimalTwoDigits: { + style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 + }, + percent: { + style: 'percent', + }, + }, +}; + export const defaultLocale = Locales.EN; \ No newline at end of file diff --git a/webapp/src/main.ts b/webapp/src/main.ts index c4e6c3a..8424370 100644 --- a/webapp/src/main.ts +++ b/webapp/src/main.ts @@ -2,7 +2,7 @@ import mitt from 'mitt' import { createApp } from 'vue' import { createI18n } from 'vue-i18n' import App from './App.vue' -import { defaultLocale, messages, dateTimeFormats } from './locales' +import { defaultLocale, messages, dateTimeFormats, numberFormats } from './locales' import { tooltip } from './plugins/bootstrap' import router from './router' @@ -23,6 +23,7 @@ const i18n = createI18n({ fallbackLocale: defaultLocale, messages, datetimeFormats: dateTimeFormats, + numberFormats: numberFormats }) app.use(router) diff --git a/webapp/src/utils/index.ts b/webapp/src/utils/index.ts index 2273bac..3f33d6e 100644 --- a/webapp/src/utils/index.ts +++ b/webapp/src/utils/index.ts @@ -1,10 +1,8 @@ import { isLoggedIn, login, logout } from './authentication'; -import { formatNumber } from './number'; import { timestampToString } from './time'; export { timestampToString, - formatNumber, login, logout, isLoggedIn, @@ -12,7 +10,6 @@ export { export default { timestampToString, - formatNumber, login, logout, isLoggedIn, diff --git a/webapp/src/utils/number.ts b/webapp/src/utils/number.ts deleted file mode 100644 index bcd7612..0000000 --- a/webapp/src/utils/number.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const formatNumber = (num: number, digits: number): string => { - return new Intl.NumberFormat( - undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits } - ).format(num); -} \ No newline at end of file diff --git a/webapp/src/views/HomeView.vue b/webapp/src/views/HomeView.vue index 398ee1a..9ec6859 100644 --- a/webapp/src/views/HomeView.vue +++ b/webapp/src/views/HomeView.vue @@ -41,8 +41,8 @@
{{ $t('home.CurrentLimit') }}{{ formatNumber(inverter.limit_relative, 0) }} % + $n(inverter.limit_absolute, 'decimalNoDigits') + }} W | {{ $n(inverter.limit_relative / 100, 'percent') }}
{{ $t('home.DataAge') }} {{ $t('home.Seconds', {'val': inverter.data_age }) }} @@ -320,7 +320,6 @@ import type { EventlogItems } from '@/types/EventlogStatus'; import type { LimitConfig } from '@/types/LimitConfig'; import type { LimitStatus } from '@/types/LimitStatus'; import type { Inverter, LiveData } from '@/types/LiveDataStatus'; -import { formatNumber } from '@/utils'; import { authHeader, authUrl, handleResponse, isLoggedIn } from '@/utils/authentication'; import * as bootstrap from 'bootstrap'; import { @@ -439,19 +438,20 @@ export default defineComponent({ computed: { currentLimitAbsolute(): string { if (this.currentLimitList.max_power > 0) { - return formatNumber(this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100, 2); + return this.$n(this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100, + 'decimalTwoDigits'); } return "0"; }, currentLimitRelative(): string { - return formatNumber(this.currentLimitList.limit_relative, 2); + return this.$n(this.currentLimitList.limit_relative, + 'decimalTwoDigits'); }, inverterData(): Inverter[] { return this.liveData.inverters; } }, methods: { - formatNumber, isLoggedIn, getInitialData() { this.dataLoading = true;