Skip to content

Commit

Permalink
testing: tame logs about missing translations (#2571)
Browse files Browse the repository at this point in the history
* tame logs about missing translations
  • Loading branch information
buck54321 authored Oct 20, 2023
1 parent 97741ba commit b378082
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 48 deletions.
27 changes: 5 additions & 22 deletions client/core/locale_ntfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1978,30 +1978,13 @@ func init() {
}

// CheckTopicLangs is used to report missing notification translations.
func CheckTopicLangs() (missing, stale map[string][]Topic) {
missing = make(map[string][]Topic, len(locales)-1)
stale = make(map[string][]Topic, len(locales)-1)

for lang, translations := range locales {
if lang == originLang {
continue
}
var missingTopics, staleTopics []Topic
for topic := range originLocale {
t, found := translations[topic]
if !found {
missingTopics = append(missingTopics, topic)
} else if t.stale {
staleTopics = append(staleTopics, topic)
func CheckTopicLangs() (missingTranslations int) {
for topic := range originLocale {
for _, m := range locales {
if m[topic] == nil {
missingTranslations += len(m)
}
}
if len(missingTopics) > 0 {
missing[lang] = missingTopics
}
if len(staleTopics) > 0 {
stale[lang] = staleTopics
}
}

return
}
20 changes: 1 addition & 19 deletions client/core/localetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,10 @@ package main

import (
"fmt"
"os"

"decred.org/dcrdex/client/core"
)

func main() {
missing, stale := core.CheckTopicLangs()
if len(missing) == 0 && len(stale) == 0 {
fmt.Println("No missing or stale notification translations!")
os.Exit(0)
}
for lang, topics := range missing {
fmt.Printf("%d missing notification translations for %v\n", len(topics), lang)
for i := range topics {
fmt.Printf("[%v] Translation missing for topic %v\n", lang, topics[i])
}
}
for lang, topics := range stale {
fmt.Printf("%d stale notification translations for %v\n", len(topics), lang)
for i := range topics {
fmt.Printf("[%v] Translation stale for topic %v\n", lang, topics[i])
}
}
// os.Exit(1) // if we want this to be fatal
fmt.Printf("Missing %d translations \n", core.CheckTopicLangs())
}
7 changes: 0 additions & 7 deletions client/webserver/site/template-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func main() {
if filepath.Ext(baseName) != ".tmpl" {
return nil
}
fmt.Println(baseName)
rawTmplPath := filepath.Join(templateDir, baseName)
rawTmpl, err := os.ReadFile(rawTmplPath)
if err != nil {
Expand All @@ -68,7 +67,6 @@ func main() {
enDict := locales.Locales["en-US"]

for lang := range locales.Locales {
fmt.Println("Prepping", lang)
tmpl := make([]byte, len(rawTmpl))
copy(tmpl, rawTmpl)
localizedTemplates[lang] = tmpl
Expand Down Expand Up @@ -100,7 +98,6 @@ func main() {
if replacement, found = enDict[key]; !found {
return fmt.Errorf("no %s translation in %q and no default replacement for %s", lang, baseName, key)
}
fmt.Printf("Warning: no %s replacement text for key %q, using 'en' value %s \n", lang, key, replacement)
}
}

Expand All @@ -116,10 +113,6 @@ func main() {
for lang, tmpl := range localizedTemplates {
langDir := filepath.Join(outputDirectory, lang)
localizedName := filepath.Join(langDir, baseName)
// ext := filepath.Ext(d.Name())
// name := baseName[:len(baseName)-len(ext)]
// localizedName := filepath.Join(outputDirectory, name+"_"+lang+ext)
fmt.Println("Writing", localizedName)
if err := os.WriteFile(localizedName, tmpl, 0644); err != nil {
return fmt.Errorf("error writing localized template %s: %v", localizedName, err)
}
Expand Down

0 comments on commit b378082

Please sign in to comment.