rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1// Command english writes every English string the design system's
2// pages can say, keyed by the id its translation is filed under, as
3// one JSON object sorted by id. hack/seed/run-translations.sh runs it
4// and hands the file to the translation exporter, which matches each
5// string against Rastrillo's tables.
6//
7// go run ./hack/seed/english -out english.json
8package main
9
10import (
11 "bytes"
12 "encoding/json"
13 "flag"
14 "fmt"
15 "os"
16
17 "amadan.net/rastrillo/fiesta"
18 "amadan.net/rastrillo/fiesta/internal/gallery"
19)
20
21func main() {
22 out := flag.String("out", "", "the file to write")
23 flag.Parse()
24 if *out == "" || flag.NArg() != 0 {
25 fmt.Fprintln(os.Stderr, "usage: english -out FILE")
26 os.Exit(2)
27 }
28 if err := write(*out); err != nil {
29 fmt.Fprintln(os.Stderr, "english:", err)
30 os.Exit(1)
31 }
32}
33
34// write dumps gallery.EnglishStrings to path. The strings are written
35// as they are, with no HTML escaping, since the exporter matches them
36// byte for byte.
37func write(path string) error {
38 strs, err := gallery.EnglishStrings(fiesta.FS())
39 if err != nil {
40 return err
41 }
42 var b bytes.Buffer
43 enc := json.NewEncoder(&b)
44 enc.SetEscapeHTML(false)
45 enc.SetIndent("", " ")
46 if err := enc.Encode(strs); err != nil {
47 return err
48 }
49 return os.WriteFile(path, b.Bytes(), 0o644)
50}
51