| 1 | package gallery |
| 2 | |
| 3 | import ( |
| 4 | _ "embed" |
| 5 | "encoding/json" |
| 6 | "sync" |
| 7 | ) |
| 8 | |
| 9 | // The Money sample, written the way each language writes it. Its three |
| 10 | // stored amounts are the same on every page and the currency codes never |
| 11 | // change; what changes is how the reader's language writes them, which |
| 12 | // is the whole of what the sample shows. Fiesta has no currency |
| 13 | // formatter and does not grow one for a sample, so the markup is |
| 14 | // Rastrillo's: hack/seed/run-translations.sh writes moneySampleMarkup's |
| 15 | // output for each of the twelve locales into i18n/money.json. The |
| 16 | // English entry is the seeded example's body, which |
| 17 | // TestTheMoneyTableStartsFromTheExample holds. |
| 18 | // |
| 19 | // The markup bypasses localMarkup, as Rastrillo's formatMarkup does: it |
| 20 | // is already written for its locale, and its ISO codes read as words to |
| 21 | // hasWords, so the parity gate would ask for eleven translations of a |
| 22 | // code that must never change. |
| 23 | |
| 24 | //go:embed i18n/money.json |
| 25 | var moneyJSON []byte |
| 26 | |
| 27 | // moneyExample is the example whose default state is the money table's. |
| 28 | const moneyExample = "format-money" |
| 29 | |
| 30 | // moneyTable is i18n/money.json, read once: a locale to its markup. |
| 31 | var moneyTable = sync.OnceValues(func() (map[string]string, error) { |
| 32 | var t map[string]string |
| 33 | err := json.Unmarshal(moneyJSON, &t) |
| 34 | return t, err |
| 35 | }) |
| 36 | |
| 37 | // moneyBody is the Money sample's markup in locale, and whether the |
| 38 | // table has one: the frame's body and the HTML tab of format-money's |
| 39 | // default state. |
| 40 | func (s *site) moneyBody(locale string) (string, bool) { |
| 41 | t, err := moneyTable() |
| 42 | if err != nil { |
| 43 | return "", false |
| 44 | } |
| 45 | m, ok := t[locale] |
| 46 | return m, ok |
| 47 | } |
| 48 | |