summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/message/catalog/dict.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/message/catalog/dict.go')
-rw-r--r--vendor/golang.org/x/text/message/catalog/dict.go49
1 files changed, 44 insertions, 5 deletions
diff --git a/vendor/golang.org/x/text/message/catalog/dict.go b/vendor/golang.org/x/text/message/catalog/dict.go
index 1810fabc6..a0eb81810 100644
--- a/vendor/golang.org/x/text/message/catalog/dict.go
+++ b/vendor/golang.org/x/text/message/catalog/dict.go
@@ -33,7 +33,11 @@ func (d *dict) Lookup(key string) (data string, ok bool) {
return d.s.lookup(d.tag, key)
}
-func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) error {
+func (b *Builder) lookup(tag language.Tag, key string) (data string, ok bool) {
+ return b.index.lookup(tag, key)
+}
+
+func (c *Builder) set(tag language.Tag, key string, s *store, msg ...Message) error {
data, err := catmsg.Compile(tag, &dict{&c.macros, tag}, firstInSequence(msg))
s.mutex.Lock()
@@ -45,6 +49,7 @@ func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) er
if s.index == nil {
s.index = map[language.Tag]msgMap{}
}
+ c.matcher = nil
s.index[tag] = m
}
@@ -52,6 +57,23 @@ func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) er
return err
}
+func (c *Builder) Matcher() language.Matcher {
+ c.index.mutex.RLock()
+ m := c.matcher
+ c.index.mutex.RUnlock()
+ if m != nil {
+ return m
+ }
+
+ c.index.mutex.Lock()
+ if c.matcher == nil {
+ c.matcher = language.NewMatcher(c.unlockedLanguages())
+ }
+ m = c.matcher
+ c.index.mutex.Unlock()
+ return m
+}
+
type store struct {
mutex sync.RWMutex
index map[language.Tag]msgMap
@@ -76,15 +98,32 @@ func (s *store) lookup(tag language.Tag, key string) (data string, ok bool) {
return "", false
}
-// Languages returns all languages for which the store contains variants.
-func (s *store) languages() []language.Tag {
+// Languages returns all languages for which the Catalog contains variants.
+func (b *Builder) Languages() []language.Tag {
+ s := &b.index
s.mutex.RLock()
defer s.mutex.RUnlock()
+ return b.unlockedLanguages()
+}
+
+func (b *Builder) unlockedLanguages() []language.Tag {
+ s := &b.index
+ if len(s.index) == 0 {
+ return nil
+ }
tags := make([]language.Tag, 0, len(s.index))
+ _, hasFallback := s.index[b.options.fallback]
+ offset := 0
+ if hasFallback {
+ tags = append(tags, b.options.fallback)
+ offset = 1
+ }
for t := range s.index {
- tags = append(tags, t)
+ if t != b.options.fallback {
+ tags = append(tags, t)
+ }
}
- internal.SortTags(tags)
+ internal.SortTags(tags[offset:])
return tags
}