Make the dictionary startup line report rows, not capabilities
It logged dictionary.Langs(), which is a compile-time constant of the languages DreamDict *supports*. The database deployed until today supported Spanish and contained none of it, so the line printed a confident "[en fr pt-PT es zh]" over a file where every Spanish lookup came back empty — the exact failure the line exists to catch, reported as success. Contents() counts rows per language instead. For a file somebody has to copy onto the box by hand, "what is in it" is the only question worth asking, and the answer is now en=136615 es=102971 fr=56096 pt-PT=136300 zh=120883. Claude-Session: https://claude.ai/code/session_016y6gyuHkQXPiEuW8RGQyua
This commit is contained in:
@@ -2,8 +2,10 @@ package lexicon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -56,9 +58,34 @@ func (dd *DreamDict) Close() error {
|
||||
return dd.d.Close()
|
||||
}
|
||||
|
||||
// Langs returns the language codes dict.db was built with, so startup can log
|
||||
// what it actually got rather than what it hoped for.
|
||||
func (dd *DreamDict) Langs() []string { return dictionary.Langs() }
|
||||
// Contents reports how many words the open dict.db holds per language, so
|
||||
// startup can log what it actually got.
|
||||
//
|
||||
// It counts rows rather than returning DreamDict's list of supported languages.
|
||||
// Those are not the same thing and the difference is the whole point: a
|
||||
// database built before Spanish existed still *supports* Spanish, and a log
|
||||
// line naming the supported set would have said so cheerfully while every
|
||||
// Spanish lookup came back empty. Counting rows is the question worth asking of
|
||||
// a file somebody had to copy onto the box by hand.
|
||||
func (dd *DreamDict) Contents() string {
|
||||
counts, err := dd.d.WordCount()
|
||||
if err != nil {
|
||||
return "unreadable: " + err.Error()
|
||||
}
|
||||
langs := make([]string, 0, len(counts))
|
||||
for lang := range counts {
|
||||
langs = append(langs, lang)
|
||||
}
|
||||
sort.Strings(langs)
|
||||
parts := make([]string, 0, len(langs))
|
||||
for _, lang := range langs {
|
||||
parts = append(parts, fmt.Sprintf("%s=%d", lang, counts[lang]))
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return "no words"
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
// dreamProvider serves one writer: English lookups from dict.db, glossed into
|
||||
// native. The struct is a value, created per request by [Set.For] — it holds no
|
||||
@@ -180,8 +207,8 @@ const maxGlossSenses = 3
|
||||
//
|
||||
// A language dict.db was built without simply has no rows, so this returns "" —
|
||||
// which is exactly what an unglossed word returns, and the popover already
|
||||
// renders that case. Spanish today is precisely this: supported by DreamDict,
|
||||
// absent from the deployed database until it is rebuilt.
|
||||
// renders that case. Spanish was precisely this until the database was rebuilt
|
||||
// with it on 2026-07-27; the code path did not change, the file did.
|
||||
func (p dreamProvider) translate(norm string) (string, error) {
|
||||
for _, c := range candidates(norm) {
|
||||
trs, err := p.dict.d.Equivalents(c, langEN, p.native)
|
||||
|
||||
Reference in New Issue
Block a user