-
Notifications
You must be signed in to change notification settings - Fork 0
/
texts.go
42 lines (36 loc) · 1.99 KB
/
texts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package configure
import (
"errors"
"github.com/nicksnyder/go-i18n/v2/i18n"
)
// setDefaultTexts sets default language specific texts
func (c *CmdConfigure) setDefaultTexts() {
c.errItemNotPresent = errors.New(c.localizedString("Error_ItemNotPresent"))
c.errDeviceNotValid = errors.New(c.localizedString("Error_DeviceNotValid"))
c.updateDeviceCategoryTexts(DeviceCategoryCharger, "Category_ChargerTitle", "Category_ChargerArticle", "Category_ChargerAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryGuidedSetup, "Category_SystemTitle", "Category_SystemArticle", "Category_SystemAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryGridMeter, "Category_GridMeterTitle", "Category_GridMeterArticle", "Category_GridMeterAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryPVMeter, "Category_PVMeterTitle", "Category_PVMeterArticle", "Category_PVMeterAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryBatteryMeter, "Category_BatteryMeter", "Category_BatteryMeterArticle", "Category_BatteryMeterAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryChargeMeter, "Category_ChargeMeterTitle", "Category_ChargeMeterArticle", "Category_ChargeMeterAdditional")
c.updateDeviceCategoryTexts(DeviceCategoryVehicle, "Category_VehicleTitle", "Category_VehicleArticle", "Category_VehicleAdditional")
}
// updateDeviceCategoryTexts updates the texts for a device category
func (c *CmdConfigure) updateDeviceCategoryTexts(category DeviceCategory, title, article, additional string) {
data := DeviceCategories[category]
data.title = c.localizedString(title)
data.article = c.localizedString(article)
data.additional = c.localizedString(additional)
DeviceCategories[category] = data
}
// localizedString is a helper for getting a localized string
func (c *CmdConfigure) localizedString(key string, data ...localizeMap) string {
var templateData localizeMap
if len(data) == 1 {
templateData = data[0]
}
return c.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: key,
TemplateData: templateData,
})
}