From b365fdfcd3a8031cd41470d0bdbe6a2c9f52f9c8 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Mon, 4 Oct 2021 20:23:54 -0700 Subject: [PATCH] Update variable names and comments for interface-based transliteration --- notifs.go | 2 +- socket.go | 2 +- translit/translit.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/notifs.go b/notifs.go index 5a06e0d..27cfabc 100644 --- a/notifs.go +++ b/notifs.go @@ -73,7 +73,7 @@ func initNotifRelay(dev *infinitime.Device) error { } maps := viper.GetStringSlice("notifs.translit.use") - translit.Maps["custom"] = translit.Map(viper.GetStringSlice("notifs.translit.custom")) + translit.Transliterators["custom"] = translit.Map(viper.GetStringSlice("notifs.translit.custom")) sender = translit.Transliterate(sender, maps...) summary = translit.Transliterate(summary, maps...) body = translit.Transliterate(body, maps...) diff --git a/socket.go b/socket.go index 250c73f..575be20 100644 --- a/socket.go +++ b/socket.go @@ -171,7 +171,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) { break } maps := viper.GetStringSlice("notifs.translit.use") - translit.Maps["custom"] = translit.Map(viper.GetStringSlice("notifs.translit.custom")) + translit.Transliterators["custom"] = translit.Map(viper.GetStringSlice("notifs.translit.custom")) title := translit.Transliterate(reqData.Title, maps...) body := translit.Transliterate(reqData.Body, maps...) // Send notification to watch diff --git a/translit/translit.go b/translit/translit.go index 4703383..63f8492 100644 --- a/translit/translit.go +++ b/translit/translit.go @@ -9,7 +9,7 @@ func Transliterate(s string, useMaps ...string) string { // Create variable to store modified string out := s // If custom map exists - if customMap, ok := Maps["custom"]; ok { + if customMap, ok := Transliterators["custom"]; ok { // Perform transliteration with it out = customMap.Transliterate(out) } @@ -20,7 +20,7 @@ func Transliterate(s string, useMaps ...string) string { continue } // Get requested map - translitMap, ok := Maps[useMap] + translitMap, ok := Transliterators[useMap] if !ok { continue } @@ -47,9 +47,9 @@ func (mt Map) Transliterate(s string) string { return strings.NewReplacer(mt...).Replace(s) } -// Maps stores transliteration maps as slices to preserve order. -// Some of these maps were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge -var Maps = map[string]Transliterator{ +// Transliterators stores transliterator implementations for each supported language. +// Some of these were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge +var Transliterators = map[string]Transliterator{ "eASCII": Map{ "œ", "oe", "ª", "a",