...
1
2
3 package main
4
5 import (
6 "golang.org/x/text/language"
7 "golang.org/x/text/message"
8 "golang.org/x/text/message/catalog"
9 )
10
11 type dictionary struct {
12 index []uint32
13 data string
14 }
15
16 func (d *dictionary) Lookup(key string) (data string, ok bool) {
17 p, ok := messageKeyToIndex[key]
18 if !ok {
19 return "", false
20 }
21 start, end := d.index[p], d.index[p+1]
22 if start == end {
23 return "", false
24 }
25 return d.data[start:end], true
26 }
27
28 func init() {
29 dict := map[string]catalog.Dictionary{}
30 fallback := language.MustParse("en-US")
31 cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback))
32 if err != nil {
33 panic(err)
34 }
35 message.DefaultCatalog = cat
36 }
37
38 var messageKeyToIndex = map[string]int{}
39
View as plain text