diff --git a/ui/src/app/edge/history/Controller/Ess/TimeOfUseTariff/chart/chart.ts b/ui/src/app/edge/history/Controller/Ess/TimeOfUseTariff/chart/chart.ts index a6f3fa0f36..b0df0e20a6 100644 --- a/ui/src/app/edge/history/Controller/Ess/TimeOfUseTariff/chart/chart.ts +++ b/ui/src/app/edge/history/Controller/Ess/TimeOfUseTariff/chart/chart.ts @@ -130,7 +130,7 @@ export class ChartComponent extends AbstractHistoryChart { this.chartType = "line"; this.chartObject = this.getChartData(); - const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, this.locale, dataResponse); + const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, dataResponse); this.datasets = displayValues.datasets; this.legendOptions = displayValues.legendOptions; this.labels = displayValues.labels; @@ -155,7 +155,7 @@ export class ChartComponent extends AbstractHistoryChart { const label = item.dataset.label; const value = item.dataset.data[item.dataIndex]; - return TimeOfUseTariffUtils.getLabel(value, label, this.translate, this.locale, this.currencyLabel); + return TimeOfUseTariffUtils.getLabel(value, label, this.translate, this.currencyLabel); }; this.options.scales[ChartAxis.LEFT]["title"].text = this.currencyLabel; diff --git a/ui/src/app/edge/history/abstracthistorychart.ts b/ui/src/app/edge/history/abstracthistorychart.ts index 950915413b..095e10ceef 100644 --- a/ui/src/app/edge/history/abstracthistorychart.ts +++ b/ui/src/app/edge/history/abstracthistorychart.ts @@ -152,7 +152,7 @@ export abstract class AbstractHistoryChart { const value = tooltipItem.dataset.data[tooltipItem.dataIndex]; const customUnit = tooltipItem.dataset.unit ?? null; - return label.split(":")[0] + ": " + NewAbstractHistoryChart.getToolTipsSuffix("", value, formatNumber, customUnit ?? unit, "line", locale, translate, locale, conf); + return label.split(":")[0] + ": " + NewAbstractHistoryChart.getToolTipsSuffix("", value, formatNumber, customUnit ?? unit, "line", translate, conf); }; options.plugins.tooltip.callbacks.labelColor = (item: Chart.TooltipItem) => { @@ -242,7 +242,7 @@ export abstract class AbstractHistoryChart { }); // Only one yAxis defined - options = NewAbstractHistoryChart.getYAxisOptions(options, yAxis, this.translate, "line", locale, this.datasets, true); + options = NewAbstractHistoryChart.getYAxisOptions(options, yAxis, this.translate, "line", this.datasets, true); options = NewAbstractHistoryChart.applyChartTypeSpecificOptionsChanges("line", options, this.service, chartObject); options.scales[ChartAxis.LEFT]["stacked"] = false; options.scales.x["stacked"] = true; diff --git a/ui/src/app/edge/history/storage/singlechart.component.ts b/ui/src/app/edge/history/storage/singlechart.component.ts index c72065b105..11f5fdc727 100644 --- a/ui/src/app/edge/history/storage/singlechart.component.ts +++ b/ui/src/app/edge/history/storage/singlechart.component.ts @@ -1,11 +1,12 @@ // @ts-strict-ignore import { formatNumber } from "@angular/common"; -import { Component, Input, OnChanges, OnDestroy, OnInit, LOCALE_ID, Inject } from "@angular/core"; +import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { TranslateService } from "@ngx-translate/core"; import * as Chart from "chart.js"; import { DefaultTypes } from "src/app/shared/service/defaulttypes"; import { ChartAxis, YAxisType } from "src/app/shared/service/utils"; +import { Language } from "src/app/shared/type/language" import { ChannelAddress, Edge, EdgeConfig, Service, Utils } from "../../../shared/shared"; import { AbstractHistoryChart } from "../abstracthistorychart"; @@ -23,7 +24,6 @@ export class StorageSingleChartComponent extends AbstractHistoryChart implements protected override service: Service, protected override translate: TranslateService, private route: ActivatedRoute, - @Inject(LOCALE_ID) private locale: string, ) { super("storage-single-chart", service, translate); } @@ -209,7 +209,7 @@ export class StorageSingleChartComponent extends AbstractHistoryChart implements private applyControllerSpecificChartOptions(options: Chart.ChartOptions) { const translate = this.translate; - const locale = this.locale; + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; options.scales[ChartAxis.LEFT].min = null; options.plugins.tooltip.callbacks.label = function (tooltipItem: Chart.TooltipItem) { diff --git a/ui/src/app/edge/history/storage/totalchart.component.ts b/ui/src/app/edge/history/storage/totalchart.component.ts index 53447b8d84..10dc564906 100644 --- a/ui/src/app/edge/history/storage/totalchart.component.ts +++ b/ui/src/app/edge/history/storage/totalchart.component.ts @@ -1,12 +1,13 @@ // @ts-strict-ignore import { formatNumber } from "@angular/common"; -import { Component, Input, OnChanges, OnDestroy, OnInit, LOCALE_ID, Inject } from "@angular/core"; +import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { TranslateService } from "@ngx-translate/core"; import * as Chart from "chart.js"; import { DefaultTypes } from "src/app/shared/service/defaulttypes"; import { ChartAxis, Utils, YAxisType } from "src/app/shared/service/utils"; import { ChannelAddress, Edge, EdgeConfig, Service } from "src/app/shared/shared"; +import { Language } from "src/app/shared/type/language" import { AbstractHistoryChart } from "../abstracthistorychart"; @@ -23,7 +24,6 @@ export class StorageTotalChartComponent extends AbstractHistoryChart implements protected override service: Service, protected override translate: TranslateService, private route: ActivatedRoute, - @Inject(LOCALE_ID) private locale: string, ) { super("storage-total-chart", service, translate); } @@ -246,7 +246,7 @@ export class StorageTotalChartComponent extends AbstractHistoryChart implements private applyControllerSpecificChartOptions(options: Chart.ChartOptions) { const translate = this.translate; - const locale = this.locale; + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; options.scales[ChartAxis.LEFT].min = null; options.plugins.tooltip.callbacks.label = function (tooltipItem: Chart.TooltipItem) { diff --git a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/powerSocChart.ts b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/powerSocChart.ts index 72c3e0736a..1aff34ca26 100644 --- a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/powerSocChart.ts +++ b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/powerSocChart.ts @@ -1,5 +1,5 @@ // @ts-strict-ignore -import { Component, Input, OnChanges, OnDestroy, OnInit, Inject, LOCALE_ID } from "@angular/core"; +import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { TranslateService } from "@ngx-translate/core"; import * as Chart from "chart.js"; @@ -28,7 +28,6 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl protected override translate: TranslateService, private route: ActivatedRoute, private websocket: Websocket, - @Inject(LOCALE_ID) protected locale: string, ) { super("powerSoc-chart", service, translate); } @@ -52,7 +51,6 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl protected setLabel() { this.options = this.createDefaultChartOptions(); const translate = this.translate; - const locale = this.locale; this.options.plugins = { tooltip: { callbacks: { @@ -61,7 +59,7 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl const label = item.dataset.label; const value = item.dataset.data[item.dataIndex]; - return TimeOfUseTariffUtils.getLabel(value, label, translate, locale); + return TimeOfUseTariffUtils.getLabel(value, label, translate); }, }, }, @@ -206,10 +204,9 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl private applyControllerSpecificOptions() { const rightYAxis: HistoryUtils.yAxes = { position: "right", unit: YAxisType.PERCENTAGE, yAxisId: ChartAxis.RIGHT }; const leftYAxis: HistoryUtils.yAxes = { position: "left", unit: YAxisType.POWER, yAxisId: ChartAxis.LEFT }; - const locale = this.service.translate.currentLang; - this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxis, this.translate, "line", locale, ChartConstants.EMPTY_DATASETS, true); - this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, leftYAxis, this.translate, "line", locale, ChartConstants.EMPTY_DATASETS, true); + this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxis, this.translate, "line", ChartConstants.EMPTY_DATASETS, true); + this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, leftYAxis, this.translate, "line", ChartConstants.EMPTY_DATASETS, true); this.datasets = this.datasets.map((el: Chart.ChartDataset) => { diff --git a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/statePriceChart.ts b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/statePriceChart.ts index 6061d016c1..53b22228ab 100644 --- a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/statePriceChart.ts +++ b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/modal/statePriceChart.ts @@ -106,12 +106,11 @@ export class ScheduleStateAndPriceChartComponent extends AbstractHistoryChart im } private applyControllerSpecificOptions() { - const locale = this.service.translate.currentLang; const rightYaxisSoc: HistoryUtils.yAxes = { position: "right", unit: YAxisType.PERCENTAGE, yAxisId: ChartAxis.RIGHT, displayGrid: true }; - this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYaxisSoc, this.translate, "line", locale, this.datasets, true); + this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYaxisSoc, this.translate, "line", this.datasets, true); const rightYAxisPower: HistoryUtils.yAxes = { position: "right", unit: YAxisType.POWER, yAxisId: ChartAxis.RIGHT_2 }; - this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxisPower, this.translate, "line", locale, this.datasets, true); + this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxisPower, this.translate, "line", this.datasets, true); this.options.scales.x["time"].unit = calculateResolution(this.service, this.service.historyPeriod.value.from, this.service.historyPeriod.value.to).timeFormat; this.options.scales.x["ticks"] = { source: "auto", autoSkip: false }; @@ -167,7 +166,7 @@ export class ScheduleStateAndPriceChartComponent extends AbstractHistoryChart im }); const leftYAxis: HistoryUtils.yAxes = { position: "left", unit: this.unit, yAxisId: ChartAxis.LEFT, customTitle: this.currencyLabel }; [rightYaxisSoc, rightYAxisPower].forEach((element) => { - this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, element, this.translate, "line", locale, this.datasets, true); + this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, element, this.translate, "line", this.datasets, true); }); this.options.scales[ChartAxis.LEFT] = { diff --git a/ui/src/app/edge/live/Controller/Evcs/flat/flat.ts b/ui/src/app/edge/live/Controller/Evcs/flat/flat.ts index 3fcfa880e9..ea589527b2 100644 --- a/ui/src/app/edge/live/Controller/Evcs/flat/flat.ts +++ b/ui/src/app/edge/live/Controller/Evcs/flat/flat.ts @@ -132,8 +132,8 @@ export class FlatComponent extends AbstractFlatWidget { this.phases = currentData.allComponents[this.componentId + "/Phases"]; this.chargeDischargePower = Utils.convertChargeDischargePower(this.translate, currentData.allComponents[this.component.id + "/ChargePower"]); - this.chargeTarget = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]), this.locale); - this.energySession = Utils.CONVERT_TO_WATT(currentData.allComponents[this.component.id + "/EnergySession"], this.locale); + this.chargeTarget = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"])); + this.energySession = Utils.CONVERT_TO_WATT(currentData.allComponents[this.component.id + "/EnergySession"]); this.minChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MinimumHardwarePower"]); this.maxChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MaximumHardwarePower"]); diff --git a/ui/src/app/edge/live/Controller/Evcs/modal/modal.ts b/ui/src/app/edge/live/Controller/Evcs/modal/modal.ts index 8a5ba675c8..0b2e5053bc 100644 --- a/ui/src/app/edge/live/Controller/Evcs/modal/modal.ts +++ b/ui/src/app/edge/live/Controller/Evcs/modal/modal.ts @@ -1,5 +1,5 @@ // @ts-strict-ignore -import { ChangeDetectorRef, Component, Inject, LOCALE_ID } from "@angular/core"; +import { ChangeDetectorRef, Component, Inject } from "@angular/core"; import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { ActivatedRoute } from "@angular/router"; import { ModalController, PopoverController } from "@ionic/angular"; @@ -48,11 +48,10 @@ export class ModalComponent extends AbstractModal { @Inject(PopoverController) public popoverctrl: PopoverController, @Inject(TranslateService) protected override translate: TranslateService, @Inject(FormBuilder) public override formBuilder: FormBuilder, - @Inject(LOCALE_ID) protected override locale: string, public override ref: ChangeDetectorRef) { super( websocket, route, service, modalController, translate, - formBuilder, locale, ref); + formBuilder, ref); ref.detach(); setInterval(() => { this.ref.detectChanges(); // manually trigger change detection @@ -129,9 +128,9 @@ export class ModalComponent extends AbstractModal { if (this.formGroup?.pristine) { this.status = this.getState(this.controller ? currentData.allComponents[this.controller.id + "/_PropertyEnabledCharging"] === 1 : null, currentData.allComponents[this.component.id + "/Status"], currentData.allComponents[this.component.id + "/Plug"]); this.chargePower = Utils.convertChargeDischargePower(this.translate, currentData.allComponents[this.component.id + "/ChargePower"]); - this.chargePowerLimit = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]), this.locale); + this.chargePowerLimit = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"])); this.state = currentData.allComponents[this.component.id + "/Status"]; - this.energySession = Utils.CONVERT_TO_WATTHOURS(currentData.allComponents[this.component.id + "/EnergySession"], this.locale); + this.energySession = Utils.CONVERT_TO_WATTHOURS(currentData.allComponents[this.component.id + "/EnergySession"]); this.minChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MinimumHardwarePower"]); this.maxChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MaximumHardwarePower"]); this.numberOfPhases = currentData.allComponents[this.component.id + "/Phases"] ? currentData.allComponents[this.component.id + "/Phases"] : 3; diff --git a/ui/src/app/edge/live/common/autarchy/modal/modal.ts b/ui/src/app/edge/live/common/autarchy/modal/modal.ts index a415909fb3..15ed4d3584 100644 --- a/ui/src/app/edge/live/common/autarchy/modal/modal.ts +++ b/ui/src/app/edge/live/common/autarchy/modal/modal.ts @@ -1,4 +1,4 @@ -import { Component, Inject, LOCALE_ID } from "@angular/core"; +import { Component } from "@angular/core"; import { TranslateService } from "@ngx-translate/core"; import { AbstractFormlyComponent, OeFormlyView } from "src/app/shared/components/shared/oe-formly-component"; import { EdgeConfig } from "src/app/shared/shared"; @@ -8,7 +8,6 @@ import { Role } from "src/app/shared/type/role"; templateUrl: "../../../../../shared/components/formly/formly-field-modal/template.html", }) export class ModalComponent extends AbstractFormlyComponent { - constructor(@Inject(LOCALE_ID) protected locale: string){ super(); } public static generateView(translate: TranslateService): OeFormlyView { return { diff --git a/ui/src/app/edge/live/common/consumption/modal/modal.constants.spec.ts b/ui/src/app/edge/live/common/consumption/modal/modal.constants.spec.ts index ff0bf47fa8..51914c80ef 100644 --- a/ui/src/app/edge/live/common/consumption/modal/modal.constants.spec.ts +++ b/ui/src/app/edge/live/common/consumption/modal/modal.constants.spec.ts @@ -7,7 +7,7 @@ import { ModalComponent } from "./modal"; export function expectView(config: EdgeConfig, viewContext: OeFormlyViewTester.Context, testContext: TestContext, view: OeFormlyViewTester.View): void { - const generatedView = OeFormlyViewTester.apply(ModalComponent.generateView(DummyConfig.convertDummyEdgeConfigToRealEdgeConfig(config), testContext.translate, "de"), viewContext); + const generatedView = OeFormlyViewTester.apply(ModalComponent.generateView(DummyConfig.convertDummyEdgeConfigToRealEdgeConfig(config), testContext.translate), viewContext); expect(generatedView).toEqual(view); } diff --git a/ui/src/app/edge/live/common/consumption/modal/modal.ts b/ui/src/app/edge/live/common/consumption/modal/modal.ts index 5ed9dcc64b..a228215317 100644 --- a/ui/src/app/edge/live/common/consumption/modal/modal.ts +++ b/ui/src/app/edge/live/common/consumption/modal/modal.ts @@ -1,4 +1,4 @@ -import { Component, Inject, LOCALE_ID } from "@angular/core"; +import { Component } from "@angular/core"; import { TranslateService } from "@ngx-translate/core"; import { TextIndentation } from "src/app/shared/components/modal/modal-line/modal-line"; import { Converter } from "src/app/shared/components/shared/converter"; @@ -12,9 +12,8 @@ import { ChannelAddress, CurrentData, EdgeConfig } from "../../../../../shared/s templateUrl: "../../../../../shared/components/formly/formly-field-modal/template.html", }) export class ModalComponent extends AbstractFormlyComponent { - constructor(@Inject(LOCALE_ID) protected locale: string){ super(); } - public static generateView(config: EdgeConfig, translate: TranslateService, locale: string): OeFormlyView { + public static generateView(config: EdgeConfig, translate: TranslateService): OeFormlyView { const evcss: EdgeConfig.Component[] | null = config.getComponentsImplementingNature("io.openems.edge.evcs.api.Evcs") .filter(component => @@ -124,7 +123,7 @@ export class ModalComponent extends AbstractFormlyComponent { } protected override generateView(config: EdgeConfig): OeFormlyView { - return ModalComponent.generateView(config, this.translate, this.locale); + return ModalComponent.generateView(config, this.translate); } } diff --git a/ui/src/app/edge/live/common/storage/storage.component.ts b/ui/src/app/edge/live/common/storage/storage.component.ts index 816903a355..5f55ad79a5 100644 --- a/ui/src/app/edge/live/common/storage/storage.component.ts +++ b/ui/src/app/edge/live/common/storage/storage.component.ts @@ -4,6 +4,7 @@ import { Component } from "@angular/core"; import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget"; import { CurrentData , ChannelAddress, EdgeConfig, Utils } from "src/app/shared/shared"; import { DateUtils } from "src/app/shared/utils/date/dateutils"; +import { Language, MyTranslateLoader } from "src/app/shared/type/language"; import { StorageModalComponent } from "./modal/modal.component"; @@ -50,6 +51,7 @@ export class StorageComponent extends AbstractFlatWidget { * @returns only positive and 0 */ public convertPower(value: number, isCharge?: boolean) { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (value == null) { return "-"; } @@ -58,7 +60,7 @@ export class StorageComponent extends AbstractFlatWidget { // Round thisValue to Integer when decimal place equals 0 if (thisValue > 0) { - return formatNumber(thisValue, this.locale, "1.0-1") + " kW"; + return formatNumber(thisValue, locale, "1.0-1") + " kW"; } else if (thisValue == 0 && isCharge) { // if thisValue is 0, then show only when charge and not discharge diff --git a/ui/src/app/edge/settings/powerassistant/powerassistant.ts b/ui/src/app/edge/settings/powerassistant/powerassistant.ts index d4a1366fdf..7c01068665 100644 --- a/ui/src/app/edge/settings/powerassistant/powerassistant.ts +++ b/ui/src/app/edge/settings/powerassistant/powerassistant.ts @@ -3,6 +3,7 @@ import { formatNumber } from "@angular/common"; import { Component } from "@angular/core"; import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget"; import { DataService } from "src/app/shared/components/shared/dataservice"; +import { Language } from "src/app/shared/type/language" import { ChannelAddress, CurrentData, EdgeConfig, Utils } from "../../../shared/shared"; import { LiveDataService } from "../../live/livedataservice"; @@ -221,10 +222,11 @@ export class PowerAssistantComponent extends AbstractFlatWidget { export namespace Converter { export function unit(unit: string): (value: any) => string { return function (value: any): string { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (value == null) { return "-"; } else if (value >= 0) { - return formatNumber(value, this.locale, "1.0-0") + " " + unit; + return formatNumber(value, locale, "1.0-0") + " " + unit; } }; } diff --git a/ui/src/app/shared/components/chart/abstracthistorychart.ts b/ui/src/app/shared/components/chart/abstracthistorychart.ts index aae0124943..75fc3721e8 100644 --- a/ui/src/app/shared/components/chart/abstracthistorychart.ts +++ b/ui/src/app/shared/components/chart/abstracthistorychart.ts @@ -1,6 +1,6 @@ // @ts-strict-ignore import { DecimalPipe, formatNumber } from "@angular/common"; -import { ChangeDetectorRef, Directive, Input, OnDestroy, OnInit, Inject, LOCALE_ID } from "@angular/core"; +import { ChangeDetectorRef, Directive, Input, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { TranslateService } from "@ngx-translate/core"; import * as Chart from "chart.js"; @@ -72,7 +72,6 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { protected translate: TranslateService, protected route: ActivatedRoute, protected logger: Logger, - @Inject(LOCALE_ID) protected locale: string, ) { this.service.historyPeriod.subscribe(() => { this.updateChart(); @@ -85,8 +84,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { * @param energyPeriodResponse the response of a {@link QueryHistoricTimeseriesEnergyPerPeriodRequest} or {@link QueryHistoricTimeseriesDataResponse} * @param energyResponse the response of a {@link QueryHistoricTimeseriesEnergyResponse} */ - public static fillChart(chartType: "line" | "bar", chartObject: HistoryUtils.ChartData, locale: string, - energyPeriodResponse: QueryHistoricTimeseriesDataResponse | QueryHistoricTimeseriesEnergyPerPeriodResponse, + public static fillChart(chartType: "line" | "bar", chartObject: HistoryUtils.ChartData, energyPeriodResponse: QueryHistoricTimeseriesDataResponse | QueryHistoricTimeseriesEnergyPerPeriodResponse, energyResponse?: QueryHistoricTimeseriesEnergyResponse) { if (Utils.isDataEmpty(energyPeriodResponse)) { return { @@ -132,6 +130,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { const datasets: Chart.ChartDataset[] = []; const displayValues: HistoryUtils.DisplayValue[] = chartObject.output(channelData.data, labels); const legendOptions: { label: string, strokeThroughHidingStyle: boolean, hideLabelInLegend: boolean; }[] = []; + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; displayValues.forEach((displayValue, index) => { let nameSuffix = null; @@ -144,7 +143,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { // Filter existing values if (displayValue) { - const label = AbstractHistoryChart.getTooltipsLabelName(displayValue.name, yAxis?.unit, locale, nameSuffix); + const label = AbstractHistoryChart.getTooltipsLabelName(displayValue.name, yAxis?.unit, nameSuffix); const data: number[] | null = displayValue.converter(); if (data === null || data === undefined) { @@ -354,19 +353,17 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { translate: TranslateService, legendOptions: { label: string, strokeThroughHidingStyle: boolean; }[], channelData: { data: { [name: string]: number[]; }; }, - locale: string, config: EdgeConfig, datasets: Chart.ChartDataset[], chartOptionsType: XAxisType, labels: (Date | string)[], ): Chart.ChartOptions { - let tooltipsLabel: string | null = null; let options: Chart.ChartOptions = Utils.deepCopy(Utils.deepCopy(AbstractHistoryChart.getDefaultOptions(chartOptionsType, service, labels))); const displayValues: HistoryUtils.DisplayValue[] = chartObject.output(channelData.data); chartObject.yAxes.forEach((element) => { - options = AbstractHistoryChart.getYAxisOptions(options, element, translate, chartType, locale, datasets, true); + options = AbstractHistoryChart.getYAxisOptions(options, element, translate, chartType, datasets, true); }); options.plugins.tooltip.callbacks.title = (tooltipItems: Chart.TooltipItem[]): string => { @@ -397,7 +394,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { tooltipsLabel = AbstractHistoryChart.getToolTipsAfterTitleLabel(unit, chartType, value, translate); } - return label.split(":")[0] + ": " + AbstractHistoryChart.getToolTipsSuffix(tooltipsLabel, value, displayValue.custom?.formatNumber ?? chartObject.tooltip.formatNumber, unit, chartType, locale, translate, locale, config); + return label.split(":")[0] + ": " + AbstractHistoryChart.getToolTipsSuffix(tooltipsLabel, value, displayValue.custom?.formatNumber ?? chartObject.tooltip.formatNumber, unit, chartType, translate, config); }; options.plugins.tooltip.callbacks.labelColor = (item: Chart.TooltipItem) => { @@ -438,6 +435,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { }; options.plugins.tooltip.callbacks.afterTitle = function (items: Chart.TooltipItem[]) { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (items?.length === 0) { return null; @@ -476,7 +474,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { function rebuildScales(chart: Chart.Chart) { let options = chart.options; chartObject.yAxes.forEach((element) => { - options = AbstractHistoryChart.getYAxisOptions(options, element, translate, chartType, locale, _dataSets, true); + options = AbstractHistoryChart.getYAxisOptions(options, element, translate, chartType, _dataSets, true); }); } @@ -526,8 +524,8 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { * @param locale the current locale * @returns the chart options {@link Chart.ChartOptions} */ - public static getYAxisOptions(options: Chart.ChartOptions, element: HistoryUtils.yAxes, translate: TranslateService, chartType: "line" | "bar", locale: string, datasets: Chart.ChartDataset[], showYAxisType?: boolean): Chart.ChartOptions { - + public static getYAxisOptions(options: Chart.ChartOptions, element: HistoryUtils.yAxes, translate: TranslateService, chartType: "line" | "bar", datasets: Chart.ChartDataset[], showYAxisType?: boolean): Chart.ChartOptions { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; const baseConfig = ChartConstants.DEFAULT_Y_SCALE_OPTIONS(element, translate, chartType, datasets, showYAxisType); switch (element.unit) { case YAxisType.RELAY: @@ -624,7 +622,8 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { * @param suffix the suffix, a number that will be added to the baseName * @returns a string, that is either the baseName, if no suffix is provided, or a baseName with a formatted number */ - public static getTooltipsLabelName(baseName: string, unit: YAxisType, locale: string, suffix?: number | string): string { + public static getTooltipsLabelName(baseName: string, unit: YAxisType, suffix?: number | string): string { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (suffix != null) { if (typeof suffix === "string") { return baseName + " " + suffix; @@ -653,7 +652,9 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { * @param title the YAxisType * @returns the tooltips suffix */ - public static getToolTipsSuffix(label: any, value: number, format: string, title: YAxisType, chartType: "bar" | "line", language: string, translate: TranslateService, locale: string, config: EdgeConfig): string { + public static getToolTipsSuffix(label: any, value: number, format: string, title: YAxisType, chartType: "bar" | "line", translate: TranslateService, config: EdgeConfig): string { + const language: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).key; + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; let tooltipsLabel: string | null = null; switch (title) { case YAxisType.RELAY: { @@ -892,7 +893,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { // TODO after chartjs migration, look for config energyPeriodResponse = DateTimeUtils.normalizeTimestamps(unit, energyPeriodResponse); - const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, this.locale, energyPeriodResponse, energyResponse); + const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, energyPeriodResponse, energyResponse); this.datasets = displayValues.datasets; this.legendOptions = displayValues.legendOptions; this.labels = displayValues.labels; @@ -911,7 +912,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { dataResponse = DateTimeUtils.normalizeTimestamps(unit, dataResponse); this.chartType = "line"; this.chartObject = this.getChartData(); - const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, this.locale, dataResponse, energyResponse); + const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, dataResponse, energyResponse); this.datasets = displayValues.datasets; this.legendOptions = displayValues.legendOptions; this.labels = displayValues.labels; @@ -1075,7 +1076,7 @@ export abstract class AbstractHistoryChart implements OnInit, OnDestroy { * Sets the Labels of the Chart */ protected setChartLabel() { - this.options = AbstractHistoryChart.getOptions(this.chartObject, this.chartType, this.service, this.translate, this.legendOptions, this.channelData, this.locale, this.config, this.datasets, this.xAxisScalingType, this.labels); + this.options = AbstractHistoryChart.getOptions(this.chartObject, this.chartType, this.service, this.translate, this.legendOptions, this.channelData, this.config, this.datasets, this.xAxisScalingType, this.labels); this.loading = false; this.stopSpinner(); } diff --git a/ui/src/app/shared/components/flat/abstract-flat-widget-line.ts b/ui/src/app/shared/components/flat/abstract-flat-widget-line.ts index a597730c87..04821ded12 100644 --- a/ui/src/app/shared/components/flat/abstract-flat-widget-line.ts +++ b/ui/src/app/shared/components/flat/abstract-flat-widget-line.ts @@ -1,5 +1,5 @@ // @ts-strict-ignore -import { Directive, Inject, Input, OnChanges, OnDestroy, LOCALE_ID } from "@angular/core"; +import { Directive, Inject, Input, OnChanges, OnDestroy } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalController } from "@ionic/angular"; import { Subject } from "rxjs"; @@ -49,7 +49,6 @@ export abstract class AbstractFlatWidgetLine implements OnChanges, OnDestroy { @Inject(Service) protected service: Service, @Inject(ModalController) protected modalCtrl: ModalController, @Inject(DataService) private dataService: DataService, - @Inject(LOCALE_ID) protected locale: string, ) { } @Input() set name(value: string | { channel: ChannelAddress, converter: (value: any) => string }) { diff --git a/ui/src/app/shared/components/flat/abstract-flat-widget.ts b/ui/src/app/shared/components/flat/abstract-flat-widget.ts index aee5d40a08..678be7b1b2 100644 --- a/ui/src/app/shared/components/flat/abstract-flat-widget.ts +++ b/ui/src/app/shared/components/flat/abstract-flat-widget.ts @@ -1,6 +1,6 @@ // @ts-strict-ignore import { FormBuilder, FormGroup } from "@angular/forms"; -import { Directive, Input, OnDestroy, OnInit, Inject, LOCALE_ID } from "@angular/core"; +import { Directive, Input, OnDestroy, OnInit, Inject } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { ModalController } from "@ionic/angular"; import { TranslateService } from "@ngx-translate/core"; @@ -41,7 +41,6 @@ export abstract class AbstractFlatWidget implements OnInit, OnDestroy { @Inject(Service) protected service: Service, @Inject(ModalController) protected modalController: ModalController, @Inject(TranslateService) protected translate: TranslateService, - @Inject(LOCALE_ID) protected locale: string, protected dataService: DataService, protected formBuilder: FormBuilder, protected router: Router, diff --git a/ui/src/app/shared/components/modal/abstract-modal-line.ts b/ui/src/app/shared/components/modal/abstract-modal-line.ts index 39ea46ed9b..0db855672e 100644 --- a/ui/src/app/shared/components/modal/abstract-modal-line.ts +++ b/ui/src/app/shared/components/modal/abstract-modal-line.ts @@ -1,5 +1,5 @@ // @ts-strict-ignore -import { ChangeDetectorRef, Directive, Inject, Input, OnChanges, OnDestroy, OnInit, LOCALE_ID } from "@angular/core"; +import { ChangeDetectorRef, Directive, Inject, Input, OnChanges, OnDestroy, OnInit } from "@angular/core"; import { FormBuilder, FormGroup } from "@angular/forms"; import { ActivatedRoute } from "@angular/router"; import { ModalController } from "@ionic/angular"; @@ -72,7 +72,6 @@ export abstract class AbstractModalLine implements OnInit, OnDestroy, OnChanges @Inject(Service) protected service: Service, @Inject(ModalController) protected modalCtrl: ModalController, @Inject(TranslateService) protected translate: TranslateService, - @Inject(LOCALE_ID) protected locale: string, @Inject(FormBuilder) public formBuilder: FormBuilder, private ref: ChangeDetectorRef, ) { diff --git a/ui/src/app/shared/components/modal/abstractModal.ts b/ui/src/app/shared/components/modal/abstractModal.ts index 295bab6c0f..b652099412 100644 --- a/ui/src/app/shared/components/modal/abstractModal.ts +++ b/ui/src/app/shared/components/modal/abstractModal.ts @@ -1,5 +1,5 @@ // @ts-strict-ignore -import { ChangeDetectorRef, Directive, Inject, Input, OnDestroy, OnInit, LOCALE_ID } from "@angular/core"; +import { ChangeDetectorRef, Directive, Inject, Input, OnDestroy, OnInit } from "@angular/core"; import { FormBuilder, FormGroup } from "@angular/forms"; import { ActivatedRoute } from "@angular/router"; import { ModalController } from "@ionic/angular"; @@ -45,7 +45,6 @@ export abstract class AbstractModal implements OnInit, OnDestroy { @Inject(ModalController) public modalController: ModalController, @Inject(TranslateService) protected translate: TranslateService, @Inject(FormBuilder) public formBuilder: FormBuilder, - @Inject(LOCALE_ID) protected locale: string, public ref: ChangeDetectorRef, ) { ref.detach(); diff --git a/ui/src/app/shared/components/modal/modal-phases/modal-phases.ts b/ui/src/app/shared/components/modal/modal-phases/modal-phases.ts index f4fadc0b8f..cb7c7431d9 100644 --- a/ui/src/app/shared/components/modal/modal-phases/modal-phases.ts +++ b/ui/src/app/shared/components/modal/modal-phases/modal-phases.ts @@ -1,6 +1,7 @@ import { formatNumber } from "@angular/common"; import { Component, Input } from "@angular/core"; import { ChannelAddress, CurrentData, Utils } from "src/app/shared/shared"; +import { Language } from "src/app/shared/type/language" import { AbstractModalLine } from "../abstract-modal-line"; import { TextIndentation } from "../modal-line/modal-line"; @@ -46,8 +47,8 @@ export class ModalPhasesComponent extends AbstractModalLine { * @returns converted value */ protected CONVERT_TO_POSITIVE_WATT = (value: number | null): string => { - + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; value = Utils.absSafely(value) ?? 0; - return formatNumber(value, this.locale, "1.0-0") + " W"; + return formatNumber(value, locale, "1.0-0") + " W"; }; } diff --git a/ui/src/app/shared/components/shared/oe-formly-component.ts b/ui/src/app/shared/components/shared/oe-formly-component.ts index 123ecd19a0..c300ea59c6 100644 --- a/ui/src/app/shared/components/shared/oe-formly-component.ts +++ b/ui/src/app/shared/components/shared/oe-formly-component.ts @@ -74,7 +74,7 @@ export namespace OeFormlyField { type: "item", channel: string, filter?: (value: number | null) => boolean, - converter?: (value: number | null, locale: string) => string + converter?: (value: number | null) => string }; export type ChildrenLine = { @@ -89,7 +89,7 @@ export namespace OeFormlyField { name: /* actual name string */ string | /* name string derived from channel value */ Converter, channel: string, filter?: (value: number | null) => boolean, - converter?: (value: number | null, locale: string) => string + converter?: (value: number | null) => string indentation?: TextIndentation, }; diff --git a/ui/src/app/shared/components/shared/testing/tester.ts b/ui/src/app/shared/components/shared/testing/tester.ts index 19db243e65..b9645de078 100644 --- a/ui/src/app/shared/components/shared/testing/tester.ts +++ b/ui/src/app/shared/components/shared/testing/tester.ts @@ -63,7 +63,7 @@ export class OeFormlyViewTester { // Read or generate name let name: string; if (typeof (field.name) === "function") { - name = field.name(tmp.rawValue, "de"); + name = field.name(tmp.rawValue); } else { name = field.name; } @@ -174,7 +174,7 @@ export class OeFormlyViewTester { // Apply converter const value: string = field.converter - ? field.converter(rawValue, "de") + ? field.converter(rawValue) : rawValue === null ? null : "" + rawValue; return { @@ -238,7 +238,7 @@ export class OeChartTester { }); // Fill Data - const configuration = AbstractHistoryChart.fillChart(chartType, chartData, "de", channelData, channels.energyChannelWithValues); + const configuration = AbstractHistoryChart.fillChart(chartType, chartData, channelData, channels.energyChannelWithValues); const data: OeChartTester.Dataset.Data[] = OeChartTester.convertChartDatasetsToDatasets(configuration.datasets); const labels: OeChartTester.Dataset.LegendLabel = OeChartTester.convertChartLabelsToLegendLabels(configuration.labels); const options: OeChartTester.Dataset.Option = OeChartTester.convertChartDataToOptions(chartData, chartType, testContext, channels, testContext.translate.currentLang, config, configuration.datasets, xAxisScalingType, configuration.labels); @@ -304,11 +304,11 @@ export class OeChartTester { displayValues.forEach(displayValue => { const yAxis = chartData.yAxes.find(yaxis => yaxis?.yAxisId == (displayValue?.yAxisId ?? chartData.yAxes[0].yAxisId)); - const label = AbstractHistoryChart.getTooltipsLabelName(displayValue.name, yAxis?.unit, "de", typeof displayValue.nameSuffix == "function" ? displayValue.nameSuffix(channels.energyChannelWithValues) : null); + const label = AbstractHistoryChart.getTooltipsLabelName(displayValue.name, yAxis?.unit, typeof displayValue.nameSuffix == "function" ? displayValue.nameSuffix(channels.energyChannelWithValues) : null); legendOptions.push(AbstractHistoryChart.getLegendOptions(label, displayValue)); }); - const options = AbstractHistoryChart.getOptions(chartData, chartType, testContext.service, testContext.translate, legendOptions, channelData.result, locale, config, datasets, xAxisType, labels); + const options = AbstractHistoryChart.getOptions(chartData, chartType, testContext.service, testContext.translate, legendOptions, channelData.result, config, datasets, xAxisType, labels); chartData.yAxes.filter(axis => axis.unit != null).forEach(axis => { // Remove custom scale calculations from unittest, seperate unittest existing @@ -395,7 +395,7 @@ export namespace OeFormlyViewTester { if (typeof field.name == "object") { rawValue = typeof field.name == "object" ? (field.name.channel.toString() in context ? context[field.name.channel.toString()] : null) : null; - value = field.name.converter(rawValue, "de"); + value = field.name.converter(rawValue); } if (typeof (field.name) === "string") { diff --git a/ui/src/app/shared/service/utils.ts b/ui/src/app/shared/service/utils.ts index 289830c0c9..485f723c39 100644 --- a/ui/src/app/shared/service/utils.ts +++ b/ui/src/app/shared/service/utils.ts @@ -8,6 +8,7 @@ import { JsonrpcResponseSuccess } from "../jsonrpc/base"; import { Base64PayloadResponse } from "../jsonrpc/response/base64PayloadResponse"; import { QueryHistoricTimeseriesEnergyResponse } from "../jsonrpc/response/queryHistoricTimeseriesEnergyResponse"; import { ChannelAddress, Currency, EdgeConfig } from "../shared"; +import { Language } from "src/app/shared/type/language" export class Utils { @@ -248,10 +249,10 @@ export class Utils { * Converts a value in Watt [W] to KiloWatt [kW]. * * @param value the value from passed value in html - * @param locale locale string * @returns converted value */ - public static CONVERT_TO_WATT = (value: number | null, locale: string): string => { + public static CONVERT_TO_WATT = (value: number | null): string => { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (value == null) { return "-"; } else if (value >= 0) { @@ -265,10 +266,10 @@ export class Utils { * Converts a value in Watt [W] to KiloWatt [kW]. * * @param value the value from passed value in html - * @param locale locale string * @returns converted value */ - public static CONVERT_WATT_TO_KILOWATT = (value: number | null, locale: string): string => { + public static CONVERT_WATT_TO_KILOWATT = (value: number | null): string => { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; if (value == null) { return "-"; } @@ -305,10 +306,10 @@ export class Utils { * Converts a value to WattHours [Wh] * * @param value the value from passed value in html - * @param locale locale string * @returns converted value */ - public static CONVERT_TO_WATTHOURS = (value: number, locale: string): string => { + public static CONVERT_TO_WATTHOURS = (value: number): string => { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; return formatNumber(value, locale, "1.0-1") + " Wh"; }; @@ -316,10 +317,10 @@ export class Utils { * Converts a value in WattHours [Wh] to KiloWattHours [kWh] * * @param value the value from passed value in html - * @param locale locale string * @returns converted value */ - public static CONVERT_TO_KILO_WATTHOURS = (value: number, locale: string): string => { + public static CONVERT_TO_KILO_WATTHOURS = (value: number): string => { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; return formatNumber(Utils.divideSafely(value, 1000), locale, "1.0-1") + " kWh"; }; @@ -396,10 +397,10 @@ export class Utils { * * @param decimal number of decimals after fraction * @param label label to be displayed along with price - * @param locale locale string * @returns converted value */ public static CONVERT_PRICE_TO_CENT_PER_KWH = (decimal: number, label: string) => { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; return (value: number | null | undefined): string => (value == null ? "-" : formatNumber(value / 10, "de", "1.0-" + decimal)) + " " + label; }; @@ -860,11 +861,11 @@ export namespace TimeOfUseTariffUtils { * @param value The numeric value to be formatted. * @param label The label type to determine the formatting. * @param translate The translation service for translating labels. - * @param locale locale string * @param currencyLabel Optional currency label for {@link TimeOfUseTariffState} labels. * @returns The formatted label, or exits if the value is not valid. */ - export function getLabel(value: number, label: string, translate: TranslateService, locale: string, currencyLabel?: Currency.Label): string { + export function getLabel(value: number, label: string, translate: TranslateService, currencyLabel?: Currency.Label): string { + const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey; // Error handling: Return undefined if value is not valid if (value === undefined || value === null || Number.isNaN(Number.parseInt(value.toString()))) { return;