diff --git a/share/we-lang/format.go b/share/we-lang/format.go index 65f89ab..041903a 100644 --- a/share/we-lang/format.go +++ b/share/we-lang/format.go @@ -223,12 +223,12 @@ func formatWind(c cond) string { return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, spd) } - unitWindString := unitWind[0] + unitWindString := unitWind(0, config.Lang) if config.WindMS { - unitWindString = unitWind[2] + unitWindString = unitWind(2, config.Lang) } else { if config.Imperial { - unitWindString = unitWind[1] + unitWindString = unitWind(1, config.Lang) } } @@ -250,7 +250,7 @@ func formatVisibility(c cond) string { if config.Imperial { 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 { @@ -259,9 +259,13 @@ func formatRain(c cond) string { rainUnit = float32(c.PrecipMM) * 0.039 } 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) { diff --git a/share/we-lang/locale.go b/share/we-lang/locale.go index 6458138..e57fac5 100644 --- a/share/we-lang/locale.go +++ b/share/we-lang/locale.go @@ -220,24 +220,98 @@ var ( "mg": {"Maraina", "Tolakandro", "Ariva", "Alina"}, } - unitRain = map[bool]string{ - false: "mm", - true: "in", - } - unitTemp = map[bool]string{ false: "C", true: "F", } - unitVis = map[bool]string{ - false: "km", - true: "mi", + 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", + }, } - unitWind = map[int]string{ - 0: "km/h", - 1: "mph", - 2: "m/s", + localizedVis = map[string]map[bool]string{ + "en": map[bool]string{ + false: "km", + true: "mi", + }, + "be": map[bool]string{ + false: "км", + true: "mi", + }, + "ru": map[bool]string{ + false: "км", + true: "mi", + }, + "uk": map[bool]string{ + false: "км", + true: "mi", + }, + } + + localizedWind = map[string]map[int]string{ + "en": map[int]string{ + 0: "km/h", + 1: "mph", + 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] +}