summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nicksnyder
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/nicksnyder')
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/LICENSE19
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/bundle.go136
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/doc.go24
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/localizer.go234
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/message.go221
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/message_template.go65
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/i18n/parse.go166
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/doc.go3
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/form.go16
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/operands.go120
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/rule.go44
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/rule_gen.go589
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/rules.go24
-rw-r--r--vendor/github.com/nicksnyder/go-i18n/v2/internal/template.go51
14 files changed, 0 insertions, 1712 deletions
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/LICENSE b/vendor/github.com/nicksnyder/go-i18n/v2/LICENSE
deleted file mode 100644
index 609cce797..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2014 Nick Snyder https://github.com/nicksnyder
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/bundle.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/bundle.go
deleted file mode 100644
index 62bcd4355..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/bundle.go
+++ /dev/null
@@ -1,136 +0,0 @@
-package i18n
-
-import (
- "fmt"
- "io/ioutil"
-
- "github.com/nicksnyder/go-i18n/v2/internal/plural"
-
- "golang.org/x/text/language"
-)
-
-// UnmarshalFunc unmarshals data into v.
-type UnmarshalFunc func(data []byte, v interface{}) error
-
-// Bundle stores a set of messages and pluralization rules.
-// Most applications only need a single bundle
-// that is initialized early in the application's lifecycle.
-// It is not goroutine safe to modify the bundle while Localizers
-// are reading from it.
-type Bundle struct {
- defaultLanguage language.Tag
- unmarshalFuncs map[string]UnmarshalFunc
- messageTemplates map[language.Tag]map[string]*MessageTemplate
- pluralRules plural.Rules
- tags []language.Tag
- matcher language.Matcher
-}
-
-// artTag is the language tag used for artifical languages
-// https://en.wikipedia.org/wiki/Codes_for_constructed_languages
-var artTag = language.MustParse("art")
-
-// NewBundle returns a bundle with a default language and a default set of plural rules.
-func NewBundle(defaultLanguage language.Tag) *Bundle {
- b := &Bundle{
- defaultLanguage: defaultLanguage,
- pluralRules: plural.DefaultRules(),
- }
- b.pluralRules[artTag] = b.pluralRules.Rule(language.English)
- b.addTag(defaultLanguage)
- return b
-}
-
-// RegisterUnmarshalFunc registers an UnmarshalFunc for format.
-func (b *Bundle) RegisterUnmarshalFunc(format string, unmarshalFunc UnmarshalFunc) {
- if b.unmarshalFuncs == nil {
- b.unmarshalFuncs = make(map[string]UnmarshalFunc)
- }
- b.unmarshalFuncs[format] = unmarshalFunc
-}
-
-// LoadMessageFile loads the bytes from path
-// and then calls ParseMessageFileBytes.
-func (b *Bundle) LoadMessageFile(path string) (*MessageFile, error) {
- buf, err := ioutil.ReadFile(path)
- if err != nil {
- return nil, err
- }
- return b.ParseMessageFileBytes(buf, path)
-}
-
-// MustLoadMessageFile is similar to LoadTranslationFile
-// except it panics if an error happens.
-func (b *Bundle) MustLoadMessageFile(path string) {
- if _, err := b.LoadMessageFile(path); err != nil {
- panic(err)
- }
-}
-
-// ParseMessageFileBytes parses the bytes in buf to add translations to the bundle.
-//
-// The format of the file is everything after the last ".".
-//
-// The language tag of the file is everything after the second to last "." or after the last path separator, but before the format.
-func (b *Bundle) ParseMessageFileBytes(buf []byte, path string) (*MessageFile, error) {
- messageFile, err := ParseMessageFileBytes(buf, path, b.unmarshalFuncs)
- if err != nil {
- return nil, err
- }
- if err := b.AddMessages(messageFile.Tag, messageFile.Messages...); err != nil {
- return nil, err
- }
- return messageFile, nil
-}
-
-// MustParseMessageFileBytes is similar to ParseMessageFileBytes
-// except it panics if an error happens.
-func (b *Bundle) MustParseMessageFileBytes(buf []byte, path string) {
- if _, err := b.ParseMessageFileBytes(buf, path); err != nil {
- panic(err)
- }
-}
-
-// AddMessages adds messages for a language.
-// It is useful if your messages are in a format not supported by ParseMessageFileBytes.
-func (b *Bundle) AddMessages(tag language.Tag, messages ...*Message) error {
- pluralRule := b.pluralRules.Rule(tag)
- if pluralRule == nil {
- return fmt.Errorf("no plural rule registered for %s", tag)
- }
- if b.messageTemplates == nil {
- b.messageTemplates = map[language.Tag]map[string]*MessageTemplate{}
- }
- if b.messageTemplates[tag] == nil {
- b.messageTemplates[tag] = map[string]*MessageTemplate{}
- b.addTag(tag)
- }
- for _, m := range messages {
- b.messageTemplates[tag][m.ID] = NewMessageTemplate(m)
- }
- return nil
-}
-
-// MustAddMessages is similar to AddMessages except it panics if an error happens.
-func (b *Bundle) MustAddMessages(tag language.Tag, messages ...*Message) {
- if err := b.AddMessages(tag, messages...); err != nil {
- panic(err)
- }
-}
-
-func (b *Bundle) addTag(tag language.Tag) {
- for _, t := range b.tags {
- if t == tag {
- // Tag already exists
- return
- }
- }
- b.tags = append(b.tags, tag)
- b.matcher = language.NewMatcher(b.tags)
-}
-
-// LanguageTags returns the list of language tags
-// of all the translations loaded into the bundle
-func (b *Bundle) LanguageTags() []language.Tag {
- return b.tags
-}
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/doc.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/doc.go
deleted file mode 100644
index 73d7a0697..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/doc.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Package i18n provides support for looking up messages
-// according to a set of locale preferences.
-//
-// Create a Bundle to use for the lifetime of your application.
-// bundle := i18n.NewBundle(language.English)
-//
-// Load translations into your bundle during initialization.
-// bundle.LoadMessageFile("en-US.yaml")
-//
-// Create a Localizer to use for a set of language preferences.
-// func(w http.ResponseWriter, r *http.Request) {
-// lang := r.FormValue("lang")
-// accept := r.Header.Get("Accept-Language")
-// localizer := i18n.NewLocalizer(bundle, lang, accept)
-// }
-//
-// Use the Localizer to lookup messages.
-// localizer.MustLocalize(&i18n.LocalizeConfig{
-// DefaultMessage: &i18n.Message{
-// ID: "HelloWorld",
-// Other: "Hello World!",
-// },
-// })
-package i18n
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/localizer.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/localizer.go
deleted file mode 100644
index 5d3b0df13..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/localizer.go
+++ /dev/null
@@ -1,234 +0,0 @@
-package i18n
-
-import (
- "fmt"
-
- "text/template"
-
- "github.com/nicksnyder/go-i18n/v2/internal/plural"
- "golang.org/x/text/language"
-)
-
-// Localizer provides Localize and MustLocalize methods that return localized messages.
-type Localizer struct {
- // bundle contains the messages that can be returned by the Localizer.
- bundle *Bundle
-
- // tags is the list of language tags that the Localizer checks
- // in order when localizing a message.
- tags []language.Tag
-}
-
-// NewLocalizer returns a new Localizer that looks up messages
-// in the bundle according to the language preferences in langs.
-// It can parse Accept-Language headers as defined in http://www.ietf.org/rfc/rfc2616.txt.
-func NewLocalizer(bundle *Bundle, langs ...string) *Localizer {
- return &Localizer{
- bundle: bundle,
- tags: parseTags(langs),
- }
-}
-
-func parseTags(langs []string) []language.Tag {
- tags := []language.Tag{}
- for _, lang := range langs {
- t, _, err := language.ParseAcceptLanguage(lang)
- if err != nil {
- continue
- }
- tags = append(tags, t...)
- }
- return tags
-}
-
-// LocalizeConfig configures a call to the Localize method on Localizer.
-type LocalizeConfig struct {
- // MessageID is the id of the message to lookup.
- // This field is ignored if DefaultMessage is set.
- MessageID string
-
- // TemplateData is the data passed when executing the message's template.
- // If TemplateData is nil and PluralCount is not nil, then the message template
- // will be executed with data that contains the plural count.
- TemplateData interface{}
-
- // PluralCount determines which plural form of the message is used.
- PluralCount interface{}
-
- // DefaultMessage is used if the message is not found in any message files.
- DefaultMessage *Message
-
- // Funcs is used to extend the Go template engine's built in functions
- Funcs template.FuncMap
-}
-
-type invalidPluralCountErr struct {
- messageID string
- pluralCount interface{}
- err error
-}
-
-func (e *invalidPluralCountErr) Error() string {
- return fmt.Sprintf("invalid plural count %#v for message id %q: %s", e.pluralCount, e.messageID, e.err)
-}
-
-// MessageNotFoundErr is returned from Localize when a message could not be found.
-type MessageNotFoundErr struct {
- messageID string
-}
-
-func (e *MessageNotFoundErr) Error() string {
- return fmt.Sprintf("message %q not found", e.messageID)
-}
-
-type pluralizeErr struct {
- messageID string
- tag language.Tag
-}
-
-func (e *pluralizeErr) Error() string {
- return fmt.Sprintf("unable to pluralize %q because there no plural rule for %q", e.messageID, e.tag)
-}
-
-type messageIDMismatchErr struct {
- messageID string
- defaultMessageID string
-}
-
-func (e *messageIDMismatchErr) Error() string {
- return fmt.Sprintf("message id %q does not match default message id %q", e.messageID, e.defaultMessageID)
-}
-
-// Localize returns a localized message.
-func (l *Localizer) Localize(lc *LocalizeConfig) (string, error) {
- msg, _, err := l.LocalizeWithTag(lc)
- return msg, err
-}
-
-// Localize returns a localized message.
-func (l *Localizer) LocalizeMessage(msg *Message) (string, error) {
- return l.Localize(&LocalizeConfig{
- DefaultMessage: msg,
- })
-}
-
-// TODO: uncomment this (and the test) when extract has been updated to extract these call sites too.
-// Localize returns a localized message.
-// func (l *Localizer) LocalizeMessageID(messageID string) (string, error) {
-// return l.Localize(&LocalizeConfig{
-// MessageID: messageID,
-// })
-// }
-
-// LocalizeWithTag returns a localized message and the language tag.
-// It may return a best effort localized message even if an error happens.
-func (l *Localizer) LocalizeWithTag(lc *LocalizeConfig) (string, language.Tag, error) {
- messageID := lc.MessageID
- if lc.DefaultMessage != nil {
- if messageID != "" && messageID != lc.DefaultMessage.ID {
- return "", language.Und, &messageIDMismatchErr{messageID: messageID, defaultMessageID: lc.DefaultMessage.ID}
- }
- messageID = lc.DefaultMessage.ID
- }
-
- var operands *plural.Operands
- templateData := lc.TemplateData
- if lc.PluralCount != nil {
- var err error
- operands, err = plural.NewOperands(lc.PluralCount)
- if err != nil {
- return "", language.Und, &invalidPluralCountErr{messageID: messageID, pluralCount: lc.PluralCount, err: err}
- }
- if templateData == nil {
- templateData = map[string]interface{}{
- "PluralCount": lc.PluralCount,
- }
- }
- }
-
- tag, template := l.getTemplate(messageID, lc.DefaultMessage)
- if template == nil {
- return "", language.Und, &MessageNotFoundErr{messageID: messageID}
- }
-
- pluralForm := l.pluralForm(tag, operands)
- if pluralForm == plural.Invalid {
- return "", language.Und, &pluralizeErr{messageID: messageID, tag: tag}
- }
-
- msg, err := template.Execute(pluralForm, templateData, lc.Funcs)
- if err != nil {
- // Attempt to fallback to "Other" pluralization in case translations are incomplete.
- if pluralForm != plural.Other {
- msg2, err2 := template.Execute(plural.Other, templateData, lc.Funcs)
- if err2 == nil {
- return msg2, tag, err
- }
- }
- return "", language.Und, err
- }
- return msg, tag, nil
-}
-
-func (l *Localizer) getTemplate(id string, defaultMessage *Message) (language.Tag, *MessageTemplate) {
- // Fast path.
- // Optimistically assume this message id is defined in each language.
- fastTag, template := l.matchTemplate(id, defaultMessage, l.bundle.matcher, l.bundle.tags)
- if template != nil {
- return fastTag, template
- }
-
- if len(l.bundle.tags) <= 1 {
- return l.bundle.defaultLanguage, nil
- }
-
- // Slow path.
- // We didn't find a translation for the tag suggested by the default matcher
- // so we need to create a new matcher that contains only the tags in the bundle
- // that have this message.
- foundTags := make([]language.Tag, 0, len(l.bundle.messageTemplates)+1)
- foundTags = append(foundTags, l.bundle.defaultLanguage)
-
- for t, templates := range l.bundle.messageTemplates {
- template := templates[id]
- if template == nil || template.Other == "" {
- continue
- }
- foundTags = append(foundTags, t)
- }
-
- return l.matchTemplate(id, defaultMessage, language.NewMatcher(foundTags), foundTags)
-}
-
-func (l *Localizer) matchTemplate(id string, defaultMessage *Message, matcher language.Matcher, tags []language.Tag) (language.Tag, *MessageTemplate) {
- _, i, _ := matcher.Match(l.tags...)
- tag := tags[i]
- templates := l.bundle.messageTemplates[tag]
- if templates != nil && templates[id] != nil {
- return tag, templates[id]
- }
- if tag == l.bundle.defaultLanguage && defaultMessage != nil {
- return tag, NewMessageTemplate(defaultMessage)
- }
- return tag, nil
-}
-
-func (l *Localizer) pluralForm(tag language.Tag, operands *plural.Operands) plural.Form {
- if operands == nil {
- return plural.Other
- }
- pluralRule := l.bundle.pluralRules.Rule(tag)
- if pluralRule == nil {
- return plural.Invalid
- }
- return pluralRule.PluralFormFunc(operands)
-}
-
-// MustLocalize is similar to Localize, except it panics if an error happens.
-func (l *Localizer) MustLocalize(lc *LocalizeConfig) string {
- localized, err := l.Localize(lc)
- if err != nil {
- panic(err)
- }
- return localized
-}
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message.go
deleted file mode 100644
index f8f789a50..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message.go
+++ /dev/null
@@ -1,221 +0,0 @@
-package i18n
-
-import (
- "fmt"
- "strings"
-)
-
-// Message is a string that can be localized.
-type Message struct {
- // ID uniquely identifies the message.
- ID string
-
- // Hash uniquely identifies the content of the message
- // that this message was translated from.
- Hash string
-
- // Description describes the message to give additional
- // context to translators that may be relevant for translation.
- Description string
-
- // LeftDelim is the left Go template delimiter.
- LeftDelim string
-
- // RightDelim is the right Go template delimiter.``
- RightDelim string
-
- // Zero is the content of the message for the CLDR plural form "zero".
- Zero string
-
- // One is the content of the message for the CLDR plural form "one".
- One string
-
- // Two is the content of the message for the CLDR plural form "two".
- Two string
-
- // Few is the content of the message for the CLDR plural form "few".
- Few string
-
- // Many is the content of the message for the CLDR plural form "many".
- Many string
-
- // Other is the content of the message for the CLDR plural form "other".
- Other string
-}
-
-// NewMessage parses data and returns a new message.
-func NewMessage(data interface{}) (*Message, error) {
- m := &Message{}
- if err := m.unmarshalInterface(data); err != nil {
- return nil, err
- }
- return m, nil
-}
-
-// MustNewMessage is similar to NewMessage except it panics if an error happens.
-func MustNewMessage(data interface{}) *Message {
- m, err := NewMessage(data)
- if err != nil {
- panic(err)
- }
- return m
-}
-
-// unmarshalInterface unmarshals a message from data.
-func (m *Message) unmarshalInterface(v interface{}) error {
- strdata, err := stringMap(v)
- if err != nil {
- return err
- }
- for k, v := range strdata {
- switch strings.ToLower(k) {
- case "id":
- m.ID = v
- case "description":
- m.Description = v
- case "hash":
- m.Hash = v
- case "leftdelim":
- m.LeftDelim = v
- case "rightdelim":
- m.RightDelim = v
- case "zero":
- m.Zero = v
- case "one":
- m.One = v
- case "two":
- m.Two = v
- case "few":
- m.Few = v
- case "many":
- m.Many = v
- case "other":
- m.Other = v
- }
- }
- return nil
-}
-
-type keyTypeErr struct {
- key interface{}
-}
-
-func (err *keyTypeErr) Error() string {
- return fmt.Sprintf("expected key to be a string but got %#v", err.key)
-}
-
-type valueTypeErr struct {
- value interface{}
-}
-
-func (err *valueTypeErr) Error() string {
- return fmt.Sprintf("unsupported type %#v", err.value)
-}
-
-func stringMap(v interface{}) (map[string]string, error) {
- switch value := v.(type) {
- case string:
- return map[string]string{
- "other": value,
- }, nil
- case map[string]string:
- return value, nil
- case map[string]interface{}:
- strdata := make(map[string]string, len(value))
- for k, v := range value {
- err := stringSubmap(k, v, strdata)
- if err != nil {
- return nil, err
- }
- }
- return strdata, nil
- case map[interface{}]interface{}:
- strdata := make(map[string]string, len(value))
- for k, v := range value {
- kstr, ok := k.(string)
- if !ok {
- return nil, &keyTypeErr{key: k}
- }
- err := stringSubmap(kstr, v, strdata)
- if err != nil {
- return nil, err
- }
- }
- return strdata, nil
- default:
- return nil, &valueTypeErr{value: value}
- }
-}
-
-func stringSubmap(k string, v interface{}, strdata map[string]string) error {
- if k == "translation" {
- switch vt := v.(type) {
- case string:
- strdata["other"] = vt
- default:
- v1Message, err := stringMap(v)
- if err != nil {
- return err
- }
- for kk, vv := range v1Message {
- strdata[kk] = vv
- }
- }
- return nil
- }
-
- switch vt := v.(type) {
- case string:
- strdata[k] = vt
- return nil
- case nil:
- return nil
- default:
- return fmt.Errorf("expected value for key %q be a string but got %#v", k, v)
- }
-}
-
-// isMessage tells whether the given data is a message, or a map containing
-// nested messages.
-// A map is assumed to be a message if it contains any of the "reserved" keys:
-// "id", "description", "hash", "leftdelim", "rightdelim", "zero", "one", "two", "few", "many", "other"
-// with a string value.
-// e.g.,
-// - {"message": {"description": "world"}} is a message
-// - {"message": {"description": "world", "foo": "bar"}} is a message ("foo" key is ignored)
-// - {"notmessage": {"description": {"hello": "world"}}} is not
-// - {"notmessage": {"foo": "bar"}} is not
-func isMessage(v interface{}) bool {
- reservedKeys := []string{"id", "description", "hash", "leftdelim", "rightdelim", "zero", "one", "two", "few", "many", "other"}
- switch data := v.(type) {
- case string:
- return true
- case map[string]interface{}:
- for _, key := range reservedKeys {
- val, ok := data[key]
- if !ok {
- continue
- }
- _, ok = val.(string)
- if !ok {
- continue
- }
- // v is a message if it contains a "reserved" key holding a string value
- return true
- }
- case map[interface{}]interface{}:
- for _, key := range reservedKeys {
- val, ok := data[key]
- if !ok {
- continue
- }
- _, ok = val.(string)
- if !ok {
- continue
- }
- // v is a message if it contains a "reserved" key holding a string value
- return true
- }
- }
- return false
-}
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message_template.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message_template.go
deleted file mode 100644
index a1a619e2f..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/message_template.go
+++ /dev/null
@@ -1,65 +0,0 @@
-package i18n
-
-import (
- "fmt"
-
- "text/template"
-
- "github.com/nicksnyder/go-i18n/v2/internal"
- "github.com/nicksnyder/go-i18n/v2/internal/plural"
-)
-
-// MessageTemplate is an executable template for a message.
-type MessageTemplate struct {
- *Message
- PluralTemplates map[plural.Form]*internal.Template
-}
-
-// NewMessageTemplate returns a new message template.
-func NewMessageTemplate(m *Message) *MessageTemplate {
- pluralTemplates := map[plural.Form]*internal.Template{}
- setPluralTemplate(pluralTemplates, plural.Zero, m.Zero, m.LeftDelim, m.RightDelim)
- setPluralTemplate(pluralTemplates, plural.One, m.One, m.LeftDelim, m.RightDelim)
- setPluralTemplate(pluralTemplates, plural.Two, m.Two, m.LeftDelim, m.RightDelim)
- setPluralTemplate(pluralTemplates, plural.Few, m.Few, m.LeftDelim, m.RightDelim)
- setPluralTemplate(pluralTemplates, plural.Many, m.Many, m.LeftDelim, m.RightDelim)
- setPluralTemplate(pluralTemplates, plural.Other, m.Other, m.LeftDelim, m.RightDelim)
- if len(pluralTemplates) == 0 {
- return nil
- }
- return &MessageTemplate{
- Message: m,
- PluralTemplates: pluralTemplates,
- }
-}
-
-func setPluralTemplate(pluralTemplates map[plural.Form]*internal.Template, pluralForm plural.Form, src, leftDelim, rightDelim string) {
- if src != "" {
- pluralTemplates[pluralForm] = &internal.Template{
- Src: src,
- LeftDelim: leftDelim,
- RightDelim: rightDelim,
- }
- }
-}
-
-type pluralFormNotFoundError struct {
- pluralForm plural.Form
- messageID string
-}
-
-func (e pluralFormNotFoundError) Error() string {
- return fmt.Sprintf("message %q has no plural form %q", e.messageID, e.pluralForm)
-}
-
-// Execute executes the template for the plural form and template data.
-func (mt *MessageTemplate) Execute(pluralForm plural.Form, data interface{}, funcs template.FuncMap) (string, error) {
- t := mt.PluralTemplates[pluralForm]
- if t == nil {
- return "", pluralFormNotFoundError{
- pluralForm: pluralForm,
- messageID: mt.Message.ID,
- }
- }
- return t.Execute(funcs, data)
-}
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/parse.go b/vendor/github.com/nicksnyder/go-i18n/v2/i18n/parse.go
deleted file mode 100644
index 57dd7fe7f..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/i18n/parse.go
+++ /dev/null
@@ -1,166 +0,0 @@
-package i18n
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "os"
-
- "golang.org/x/text/language"
-)
-
-// MessageFile represents a parsed message file.
-type MessageFile struct {
- Path string
- Tag language.Tag
- Format string
- Messages []*Message
-}
-
-// ParseMessageFileBytes returns the messages parsed from file.
-func ParseMessageFileBytes(buf []byte, path string, unmarshalFuncs map[string]UnmarshalFunc) (*MessageFile, error) {
- lang, format := parsePath(path)
- tag := language.Make(lang)
- messageFile := &MessageFile{
- Path: path,
- Tag: tag,
- Format: format,
- }
- if len(buf) == 0 {
- return messageFile, nil
- }
- unmarshalFunc := unmarshalFuncs[messageFile.Format]
- if unmarshalFunc == nil {
- if messageFile.Format == "json" {
- unmarshalFunc = json.Unmarshal
- } else {
- return nil, fmt.Errorf("no unmarshaler registered for %s", messageFile.Format)
- }
- }
- var err error
- var raw interface{}
- if err = unmarshalFunc(buf, &raw); err != nil {
- return nil, err
- }
-
- if messageFile.Messages, err = recGetMessages(raw, isMessage(raw), true); err != nil {
- return nil, err
- }
-
- return messageFile, nil
-}
-
-const nestedSeparator = "."
-
-var errInvalidTranslationFile = errors.New("invalid translation file, expected key-values, got a single value")
-
-// recGetMessages looks for translation messages inside "raw" parameter,
-// scanning nested maps using recursion.
-func recGetMessages(raw interface{}, isMapMessage, isInitialCall bool) ([]*Message, error) {
- var messages []*Message
- var err error
-
- switch data := raw.(type) {
- case string:
- if isInitialCall {
- return nil, errInvalidTranslationFile
- }
- m, err := NewMessage(data)
- return []*Message{m}, err
-
- case map[string]interface{}:
- if isMapMessage {
- m, err := NewMessage(data)
- return []*Message{m}, err
- }
- messages = make([]*Message, 0, len(data))
- for id, data := range data {
- // recursively scan map items
- messages, err = addChildMessages(id, data, messages)
- if err != nil {
- return nil, err
- }
- }
-
- case map[interface{}]interface{}:
- if isMapMessage {
- m, err := NewMessage(data)
- return []*Message{m}, err
- }
- messages = make([]*Message, 0, len(data))
- for id, data := range data {
- strid, ok := id.(string)
- if !ok {
- return nil, fmt.Errorf("expected key to be string but got %#v", id)
- }
- // recursively scan map items
- messages, err = addChildMessages(strid, data, messages)
- if err != nil {
- return nil, err
- }
- }
-
- case []interface{}:
- // Backward compatibility for v1 file format.
- messages = make([]*Message, 0, len(data))
- for _, data := range data {
- // recursively scan slice items
- childMessages, err := recGetMessages(data, isMessage(data), false)
- if err != nil {
- return nil, err
- }
- messages = append(messages, childMessages...)
- }
-
- default:
- return nil, fmt.Errorf("unsupported file format %T", raw)
- }
-
- return messages, nil
-}
-
-func addChildMessages(id string, data interface{}, messages []*Message) ([]*Message, error) {
- isChildMessage := isMessage(data)
- childMessages, err := recGetMessages(data, isChildMessage, false)
- if err != nil {
- return nil, err
- }
- for _, m := range childMessages {
- if isChildMessage {
- if m.ID == "" {
- m.ID = id // start with innermost key
- }
- } else {
- m.ID = id + nestedSeparator + m.ID // update ID with each nested key on the way
- }
- messages = append(messages, m)
- }
- return messages, nil
-}
-
-func parsePath(path string) (langTag, format string) {
- formatStartIdx := -1
- for i := len(path) - 1; i >= 0; i-- {
- c := path[i]
- if os.IsPathSeparator(c) {
- if formatStartIdx != -1 {
- langTag = path[i+1 : formatStartIdx]
- }
- return
- }
- if path[i] == '.' {
- if formatStartIdx != -1 {
- langTag = path[i+1 : formatStartIdx]
- return
- }
- if formatStartIdx == -1 {
- format = path[i+1:]
- formatStartIdx = i
- }
- }
- }
- if formatStartIdx != -1 {
- langTag = path[:formatStartIdx]
- }
- return
-}
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/doc.go b/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/doc.go
deleted file mode 100644
index c2a71d53e..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/doc.go
+++ /dev/null
@@ -1,3 +0,0 @@
-// Package plural provides support for pluralizing messages
-// according to CLDR rules http://cldr.unicode.org/index/cldr-spec/plural-rules
-package plural
diff --git a/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/form.go b/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/form.go
deleted file mode 100644
index 287a87f22..000000000
--- a/vendor/github.com/nicksnyder/go-i18n/v2/internal/plural/form.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package plural
-
-// Form represents a language pluralization form as defined here:
-// http://cldr.unicode.org/index/cldr-spec/plural-rules
-type Form string
-
-// All defined plural forms.
-const (
- Invalid Form = ""
- Zero Form = "zero"
- One Form = "one"
- Two Form = "two"
- Few Form = "few"