summaryrefslogtreecommitdiffhomepage
path: root/cmd/exttmpl
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/exttmpl')
-rw-r--r--cmd/exttmpl/main.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/cmd/exttmpl/main.go b/cmd/exttmpl/main.go
index ca7c15f..599879a 100644
--- a/cmd/exttmpl/main.go
+++ b/cmd/exttmpl/main.go
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"slices"
+ "strings"
"text/template/parse"
"golang.org/x/text/language"
@@ -120,12 +121,11 @@ func process(tmplMsgs *[]pipeline.Message, node parse.Node) {
continue
}
if sn, ok := arg.(*parse.StringNode); ok {
+ txt := collapse(sn.Text)
*tmplMsgs = append(*tmplMsgs, pipeline.Message{
- ID: pipeline.IDList{sn.Text},
- Key: sn.Text,
- Message: pipeline.Text{
- Msg: sn.Text,
- },
+ ID: pipeline.IDList{txt},
+ Key: txt,
+ Message: pipeline.Text{Msg: txt},
})
}
}
@@ -177,6 +177,29 @@ func languages() []language.Tag {
return tags
}
+func collapse(s string) string {
+ var (
+ sb strings.Builder
+ prev bool
+ )
+ const spc = " \t\n"
+
+ for _, ch := range strings.Trim(s, spc) {
+ if strings.ContainsRune(spc, ch) {
+ if prev {
+ continue
+ }
+ ch = ' '
+ prev = true
+ } else {
+ prev = false
+ }
+ sb.WriteRune(ch)
+ }
+
+ return sb.String()
+}
+
func try(err error) {
if err != nil {
die(err)