diff --git a/cmd/gotext/main.go b/cmd/gotext/main.go index ed0f7eca..5171eb15 100644 --- a/cmd/gotext/main.go +++ b/cmd/gotext/main.go @@ -48,11 +48,18 @@ func config() (*pipeline.Config, error) { if err != nil { return nil, wrap(err, "invalid srclang") } + + // Use a default value since rewrite and extract don't have an out flag. + genFile := "" + if out != nil { + genFile = *out + } + return &pipeline.Config{ SourceLanguage: tag, Supported: getLangs(), TranslationsPattern: `messages\.(.*)\.json$`, - GenFile: *out, + GenFile: genFile, Dir: *dir, }, nil } diff --git a/go.mod b/go.mod index ff064ec7..b49ccc63 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,8 @@ module golang.org/x/text go 1.18 -require golang.org/x/tools v0.6.0 // tagx:ignore +require golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // tagx:ignore -require ( - golang.org/x/mod v0.8.0 // indirect; tagx:ignore - golang.org/x/sys v0.5.0 // indirect; tagx:ignore -) +require golang.org/x/mod v0.17.0 // indirect; tagx:ignore + +require golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index 44d387ef..d046f937 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,6 @@ -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= diff --git a/message/message.go b/message/message.go index 48d76630..91a97264 100644 --- a/message/message.go +++ b/message/message.go @@ -138,21 +138,20 @@ func (p *Printer) Printf(key Reference, a ...interface{}) (n int, err error) { func lookupAndFormat(p *printer, r Reference, a []interface{}) { p.fmt.Reset(a) - var id, msg string switch v := r.(type) { case string: - id, msg = v, v + if p.catContext.Execute(v) == catalog.ErrNotFound { + p.Render(v) + return + } case key: - id, msg = v.id, v.fallback - default: - panic("key argument is not a Reference") - } - - if p.catContext.Execute(id) == catalog.ErrNotFound { - if p.catContext.Execute(msg) == catalog.ErrNotFound { - p.Render(msg) + if p.catContext.Execute(v.id) == catalog.ErrNotFound && + p.catContext.Execute(v.fallback) == catalog.ErrNotFound { + p.Render(v.fallback) return } + default: + panic("key argument is not a Reference") } }