Add translation support for units

pull/750/head
Igor Chubin 2 years ago
parent 8fc5c84e95
commit bf6c71a4e8

@ -223,12 +223,12 @@ func formatWind(c cond) string {
return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, spd) return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, spd)
} }
unitWindString := unitWind[0] unitWindString := unitWind(0, config.Lang)
if config.WindMS { if config.WindMS {
unitWindString = unitWind[2] unitWindString = unitWind(2, config.Lang)
} else { } else {
if config.Imperial { if config.Imperial {
unitWindString = unitWind[1] unitWindString = unitWind(1, config.Lang)
} }
} }
@ -250,7 +250,7 @@ func formatVisibility(c cond) string {
if config.Imperial { if config.Imperial {
c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000 c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000
} }
return pad(fmt.Sprintf("%d %s", c.VisibleDistKM, unitVis[config.Imperial]), 15) return pad(fmt.Sprintf("%d %s", c.VisibleDistKM, unitVis(config.Imperial, config.Lang)), 15)
} }
func formatRain(c cond) string { func formatRain(c cond) string {
@ -259,9 +259,13 @@ func formatRain(c cond) string {
rainUnit = float32(c.PrecipMM) * 0.039 rainUnit = float32(c.PrecipMM) * 0.039
} }
if c.ChanceOfRain != "" { if c.ChanceOfRain != "" {
return pad(fmt.Sprintf("%.1f %s | %s%%", rainUnit, unitRain[config.Imperial], c.ChanceOfRain), 15) return pad(fmt.Sprintf(
"%.1f %s | %s%%",
rainUnit,
unitRain(config.Imperial, config.Lang),
c.ChanceOfRain), 15)
} }
return pad(fmt.Sprintf("%.1f %s", rainUnit, unitRain[config.Imperial]), 15) return pad(fmt.Sprintf("%.1f %s", rainUnit, unitRain(config.Imperial, config.Lang)), 15)
} }
func formatCond(cur []string, c cond, current bool) (ret []string) { func formatCond(cur []string, c cond, current bool) (ret []string) {

@ -220,24 +220,98 @@ var (
"mg": {"Maraina", "Tolakandro", "Ariva", "Alina"}, "mg": {"Maraina", "Tolakandro", "Ariva", "Alina"},
} }
unitRain = map[bool]string{
false: "mm",
true: "in",
}
unitTemp = map[bool]string{ unitTemp = map[bool]string{
false: "C", false: "C",
true: "F", true: "F",
} }
unitVis = map[bool]string{ localizedRain = map[string]map[bool]string{
"en": map[bool]string{
false: "mm",
true: "in",
},
"be": map[bool]string{
false: "мм",
true: "in",
},
"ru": map[bool]string{
false: "мм",
true: "in",
},
"uk": map[bool]string{
false: "мм",
true: "in",
},
}
localizedVis = map[string]map[bool]string{
"en": map[bool]string{
false: "km", false: "km",
true: "mi", true: "mi",
},
"be": map[bool]string{
false: "км",
true: "mi",
},
"ru": map[bool]string{
false: "км",
true: "mi",
},
"uk": map[bool]string{
false: "км",
true: "mi",
},
} }
unitWind = map[int]string{ localizedWind = map[string]map[int]string{
"en": map[int]string{
0: "km/h", 0: "km/h",
1: "mph", 1: "mph",
2: "m/s", 2: "m/s",
},
"be": map[int]string{
0: "км/г",
1: "mph",
2: "м/c",
},
"ru": map[int]string{
0: "км/ч",
1: "mph",
2: "м/c",
},
"tr": map[int]string{
0: "km/sa",
1: "mph",
2: "m/s",
},
"uk": map[int]string{
0: "км/год",
1: "mph",
2: "м/c",
},
} }
) )
func unitWind(unit int, lang string) string {
translation, ok := localizedWind[lang]
if !ok {
translation = localizedWind[lang]
}
return translation[unit]
}
func unitVis(unit bool, lang string) string {
translation, ok := localizedVis[lang]
if !ok {
translation = localizedVis[lang]
}
return translation[unit]
}
func unitRain(unit bool, lang string) string {
translation, ok := localizedRain[lang]
if !ok {
translation = localizedRain[lang]
}
return translation[unit]
}

Loading…
Cancel
Save