diff options
Diffstat (limited to 'vendor/golang.org/x/text/message/pipeline')
14 files changed, 48 insertions, 1444 deletions
diff --git a/vendor/golang.org/x/text/message/pipeline/extract.go b/vendor/golang.org/x/text/message/pipeline/extract.go index 379cc6d..20ad914 100644 --- a/vendor/golang.org/x/text/message/pipeline/extract.go +++ b/vendor/golang.org/x/text/message/pipeline/extract.go @@ -28,12 +28,8 @@ import ( // - handle features (gender, plural) // - message rewriting -// - %m substitutions -// - `msg:"etc"` tags -// - msg/Msg top-level vars and strings. - // Extract extracts all strings form the package defined in Config. -func Extract(c *Config) (*State, error) { +func Extract(c *Config) (*Locale, error) { conf := loader.Config{} prog, err := loadPackages(&conf, c.Packages) if err != nil { @@ -145,11 +141,9 @@ func Extract(c *Config) (*State, error) { ph := placeholders{index: map[string]string{}} - trimmed, _, _ := trimWS(fmtMsg) - p := fmtparser.Parser{} p.Reset(simArgs) - for p.SetFormat(trimmed); p.Scan(); { + for p.SetFormat(fmtMsg); p.Scan(); { switch p.Status { case fmtparser.StatusText: msg += p.Text() @@ -195,14 +189,11 @@ func Extract(c *Config) (*State, error) { } } - return &State{ - Config: *c, - program: prog, - Extracted: Messages{ - Language: c.SourceLanguage, - Messages: messages, - }, - }, nil + out := &Locale{ + Language: c.SourceLanguage, + Messages: messages, + } + return out, nil } func posString(conf loader.Config, info *loader.PackageInfo, pos token.Pos) string { @@ -251,7 +242,7 @@ func strip(s string) string { if unicode.IsSpace(r) || r == '-' { return '_' } - if !unicode.In(r, unicode.Letter, unicode.Mark, unicode.Number) { + if !unicode.In(r, unicode.Letter, unicode.Mark) { return -1 } return r diff --git a/vendor/golang.org/x/text/message/pipeline/generate.go b/vendor/golang.org/x/text/message/pipeline/generate.go index 8d6f07b..c5e51bd 100644 --- a/vendor/golang.org/x/text/message/pipeline/generate.go +++ b/vendor/golang.org/x/text/message/pipeline/generate.go @@ -6,9 +6,7 @@ package pipeline import ( "fmt" - "go/build" "io" - "path/filepath" "regexp" "sort" "strings" @@ -20,66 +18,13 @@ import ( "golang.org/x/text/internal/catmsg" "golang.org/x/text/internal/gen" "golang.org/x/text/language" - "golang.org/x/tools/go/loader" ) var transRe = regexp.MustCompile(`messages\.(.*)\.json`) -// Generate writes a Go file that defines a Catalog with translated messages. -func (s *State) Generate() error { - path := s.Config.GenPackage - if path == "" { - path = "." - } - isDir := path[0] == '.' - prog, err := loadPackages(&loader.Config{}, []string{path}) - if err != nil { - return wrap(err, "could not load package") - } - pkgs := prog.InitialPackages() - if len(pkgs) != 1 { - return errorf("more than one package selected: %v", pkgs) - } - pkg := pkgs[0].Pkg.Name() - - cw, err := s.generate() - if err != nil { - return err - } - if !isDir { - gopath := build.Default.GOPATH - path = filepath.Join(gopath, filepath.FromSlash(pkgs[0].Pkg.Path())) - } - path = filepath.Join(path, s.Config.GenFile) - cw.WriteGoFile(path, pkg) // TODO: WriteGoFile should return error. - return err -} - -// WriteGen writes a Go file with the given package name to w that defines a +// Generate writes a Go file with the given package name to w, which defines a // Catalog with translated messages. -func (s *State) WriteGen(w io.Writer, pkg string) error { - cw, err := s.generate() - if err != nil { - return err - } - _, err = cw.WriteGo(w, pkg, "") - return err -} - -// Generate is deprecated; use (*State).Generate(). -func Generate(w io.Writer, pkg string, extracted *Messages, trans ...Messages) (n int, err error) { - s := State{ - Extracted: *extracted, - Translations: trans, - } - cw, err := s.generate() - if err != nil { - return 0, err - } - return cw.WriteGo(w, pkg, "") -} - -func (s *State) generate() (*gen.CodeWriter, error) { +func Generate(w io.Writer, pkg string, extracted *Locale, trans ...*Locale) (n int, err error) { // TODO: add in external input. Right now we assume that all files are // manually created and stored in the textdata directory. @@ -89,7 +34,7 @@ func (s *State) generate() (*gen.CodeWriter, error) { langVars := []string{} usedKeys := map[string]int{} - for _, loc := range s.Translations { + for _, loc := range trans { tag := loc.Language if _, ok := translations[tag]; !ok { translations[tag] = map[string]Message{} @@ -99,7 +44,7 @@ func (s *State) generate() (*gen.CodeWriter, error) { if !m.Translation.IsEmpty() { for _, id := range m.ID { if _, ok := translations[tag][id]; ok { - warnf("Duplicate translation in locale %q for message %q", tag, id) + logf("Duplicate translation in locale %q for message %q", tag, id) } translations[tag][id] = m } @@ -113,7 +58,7 @@ func (s *State) generate() (*gen.CodeWriter, error) { for _, tag := range languages { langVars = append(langVars, strings.Replace(tag.String(), "-", "_", -1)) dict := translations[tag] - for _, msg := range s.Extracted.Messages { + for _, msg := range extracted.Messages { for _, id := range msg.ID { if trans, ok := dict[id]; ok && !trans.Translation.IsEmpty() { if _, ok := usedKeys[msg.Key]; !ok { @@ -122,7 +67,7 @@ func (s *State) generate() (*gen.CodeWriter, error) { break } // TODO: log missing entry. - warnf("%s: Missing entry for %q.", tag, id) + logf("%s: Missing entry for %q.", tag, id) } } } @@ -133,12 +78,12 @@ func (s *State) generate() (*gen.CodeWriter, error) { Fallback language.Tag Languages []string }{ - Fallback: s.Extracted.Language, + Fallback: extracted.Language, Languages: langVars, } if err := lookup.Execute(cw, x); err != nil { - return nil, wrap(err, "error") + return 0, wrap(err, "error") } keyToIndex := []string{} @@ -155,29 +100,21 @@ func (s *State) generate() (*gen.CodeWriter, error) { for i, tag := range languages { dict := translations[tag] a := make([]string, len(usedKeys)) - for _, msg := range s.Extracted.Messages { + for _, msg := range extracted.Messages { for _, id := range msg.ID { if trans, ok := dict[id]; ok && !trans.Translation.IsEmpty() { m, err := assemble(&msg, &trans.Translation) if err != nil { - return nil, wrap(err, "error") - } - _, leadWS, trailWS := trimWS(msg.Key) - if leadWS != "" || trailWS != "" { - m = catmsg.Affix{ - Message: m, - Prefix: leadWS, - Suffix: trailWS, - } + return 0, wrap(err, "error") } // TODO: support macros. data, err := catmsg.Compile(tag, nil, m) if err != nil { - return nil, wrap(err, "error") + return 0, wrap(err, "error") } key := usedKeys[msg.Key] if d := a[key]; d != "" && d != data { - warnf("Duplicate non-consistent translation for key %q, picking the one for message %q", msg.Key, id) + logf("Duplicate non-consistent translation for key %q, picking the one for message %q", msg.Key, id) } a[key] = string(data) break @@ -194,7 +131,7 @@ func (s *State) generate() (*gen.CodeWriter, error) { cw.WriteVar(langVars[i]+"Index", index) cw.WriteConst(langVars[i]+"Data", strings.Join(a, "")) } - return cw, nil + return cw.WriteGo(w, pkg, "") } func assemble(m *Message, t *Text) (msg catmsg.Message, err error) { diff --git a/vendor/golang.org/x/text/message/pipeline/message.go b/vendor/golang.org/x/text/message/pipeline/message.go index b9b0b3a..8e54700 100644 --- a/vendor/golang.org/x/text/message/pipeline/message.go +++ b/vendor/golang.org/x/text/message/pipeline/message.go @@ -23,8 +23,28 @@ import ( // the format string "%d file(s) remaining". // See the examples directory for examples of extracted messages. -// Messages is used to store translations for a single language. -type Messages struct { +// Config contains configuration for the translation pipeline. +type Config struct { + SourceLanguage language.Tag + + // Supported indicates the languages for which data should be generated. + // If unspecified, it will attempt to derive the set of supported languages + // from the context. + Supported []language.Tag + + Packages []string + + // TODO: + // - Printf-style configuration + // - Template-style configuration + // - Extraction options + // - Rewrite options + // - Generation options +} + +// A Locale is used to store all information for a single locale. This type is +// used both for extraction and injection. +type Locale struct { Language language.Tag `json:"language"` Messages []Message `json:"messages"` Macros map[string]Text `json:"macros,omitempty"` diff --git a/vendor/golang.org/x/text/message/pipeline/pipeline.go b/vendor/golang.org/x/text/message/pipeline/pipeline.go index 8087bf6..733a50c 100644 --- a/vendor/golang.org/x/text/message/pipeline/pipeline.go +++ b/vendor/golang.org/x/text/message/pipeline/pipeline.go @@ -8,284 +8,33 @@ package pipeline import ( - "bytes" - "encoding/json" "fmt" "go/build" "go/parser" - "io/ioutil" "log" - "path/filepath" - "regexp" - "strings" - "text/template" - "unicode" - "golang.org/x/text/language" - "golang.org/x/text/runes" "golang.org/x/tools/go/loader" ) const ( extractFile = "extracted.gotext.json" outFile = "out.gotext.json" - gotextSuffix = "gotext.json" + gotextSuffix = ".gotext.json" ) -// Config contains configuration for the translation pipeline. -type Config struct { - // Supported indicates the languages for which data should be generated. - // The default is to support all locales for which there are matching - // translation files. - Supported []language.Tag - - // --- Extraction - - SourceLanguage language.Tag - - Packages []string - - // --- File structure - - // Dir is the root dir for all operations. - Dir string - - // TranslationsPattern is a regular expression to match incoming translation - // files. These files may appear in any directory rooted at Dir. - // language for the translation files is determined as follows: - // 1. From the Language field in the file. - // 2. If not present, from a valid language tag in the filename, separated - // by dots (e.g. "en-US.json" or "incoming.pt_PT.xmb"). - // 3. If not present, from a the closest subdirectory in which the file - // is contained that parses as a valid language tag. - TranslationsPattern string - - // OutPattern defines the location for translation files for a certain - // language. The default is "{{.Dir}}/{{.Language}}/out.{{.Ext}}" - OutPattern string - - // Format defines the file format for generated translation files. - // The default is XMB. Alternatives are GetText, XLIFF, L20n, GoText. - Format string - - Ext string - - // TODO: - // Actions are additional actions to be performed after the initial extract - // and merge. - // Actions []struct { - // Name string - // Options map[string]string - // } - - // --- Generation - - // GenFile may be in a different package. It is not defined, it will - // be written to stdout. - GenFile string - - // GenPackage is the package or relative path into which to generate the - // file. If not specified it is relative to the current directory. - GenPackage string - - // DeclareVar defines a variable to which to assing the generated Catalog. - DeclareVar string - - // SetDefault determines whether to assign the generated Catalog to - // message.DefaultCatalog. The default for this is true if DeclareVar is - // not defined, false otherwise. - SetDefault bool - - // TODO: - // - Printf-style configuration - // - Template-style configuration - // - Extraction options - // - Rewrite options - // - Generation options -} - -// Operations: -// - extract: get the strings -// - disambiguate: find messages with the same key, but possible different meaning. -// - create out: create a list of messages that need translations -// - load trans: load the list of current translations -// - merge: assign list of translations as done -// - (action)expand: analyze features and create example sentences for each version. -// - (action)googletrans: pre-populate messages with automatic translations. -// - (action)export: send out messages somewhere non-standard -// - (action)import: load messages from somewhere non-standard -// - vet program: don't pass "foo" + var + "bar" strings. Not using funcs for translated strings. -// - vet trans: coverage: all translations/ all features. -// - generate: generate Go code - -// State holds all accumulated information on translations during processing. -type State struct { - Config Config - - Package string - program *loader.Program - - Extracted Messages `json:"messages"` - - // Messages includes all messages for which there need to be translations. - // Duplicates may be eliminated. Generation will be done from these messages - // (usually after merging). - Messages []Messages - - // Translations are incoming translations for the application messages. - Translations []Messages -} - -func (s *State) dir() string { - if d := s.Config.Dir; d != "" { - return d - } - return "./locales" -} - -func outPattern(s *State) (string, error) { - c := s.Config - pat := c.OutPattern - if pat == "" { - pat = "{{.Dir}}/{{.Language}}/out.{{.Ext}}" - } - - ext := c.Ext - if ext == "" { - ext = c.Format - } - if ext == "" { - ext = gotextSuffix - } - t, err := template.New("").Parse(pat) - if err != nil { - return "", wrap(err, "error parsing template") - } - buf := bytes.Buffer{} - err = t.Execute(&buf, map[string]string{ - "Dir": s.dir(), - "Language": "%s", - "Ext": ext, - }) - return filepath.FromSlash(buf.String()), wrap(err, "incorrect OutPattern") -} - -var transRE = regexp.MustCompile(`.*\.` + gotextSuffix) - -// Import loads existing translation files. -func (s *State) Import() error { - outPattern, err := outPattern(s) - if err != nil { - return err - } - re := transRE - if pat := s.Config.TranslationsPattern; pat != "" { - if re, err = regexp.Compile(pat); err != nil { - return wrapf(err, "error parsing regexp %q", s.Config.TranslationsPattern) - } - } - x := importer{s, outPattern, re} - return x.walkImport(s.dir(), s.Config.SourceLanguage) -} - -type importer struct { - state *State - outPattern string - transFile *regexp.Regexp -} - -func (i *importer) walkImport(path string, tag language.Tag) error { - files, err := ioutil.ReadDir(path) - if err != nil { - return nil - } - for _, f := range files { - name := f.Name() - tag := tag - if f.IsDir() { - if t, err := language.Parse(name); err == nil { - tag = t - } - // We ignore errors - if err := i.walkImport(filepath.Join(path, name), tag); err != nil { - return err - } - continue - } - for _, l := range strings.Split(name, ".") { - if t, err := language.Parse(l); err == nil { - tag = t - } - } - file := filepath.Join(path, name) - // TODO: Should we skip files that match output files? - if fmt.Sprintf(i.outPattern, tag) == file { - continue - } - // TODO: handle different file formats. - if !i.transFile.MatchString(name) { - continue - } - b, err := ioutil.ReadFile(file) - if err != nil { - return wrap(err, "read file failed") - } - var translations Messages - if err := json.Unmarshal(b, &translations); err != nil { - return wrap(err, "parsing translation file failed") - } - i.state.Translations = append(i.state.Translations, translations) - } - return nil -} - -// Merge merges the extracted messages with the existing translations. -func (s *State) Merge() error { - panic("unimplemented") - return nil - -} - -// Export writes out the messages to translation out files. -func (s *State) Export() error { - panic("unimplemented") - return nil -} - -var ( - ws = runes.In(unicode.White_Space).Contains - notWS = runes.NotIn(unicode.White_Space).Contains -) - -func trimWS(s string) (trimmed, leadWS, trailWS string) { - trimmed = strings.TrimRightFunc(s, ws) - trailWS = s[len(trimmed):] - if i := strings.IndexFunc(trimmed, notWS); i > 0 { - leadWS = trimmed[:i] - trimmed = trimmed[i:] - } - return trimmed, leadWS, trailWS -} - // NOTE: The command line tool already prefixes with "gotext:". var ( wrap = func(err error, msg string) error { - if err == nil { - return nil - } return fmt.Errorf("%s: %v", msg, err) } wrapf = func(err error, msg string, args ...interface{}) error { - if err == nil { - return nil - } return wrap(err, fmt.Sprintf(msg, args...)) } errorf = fmt.Errorf ) -func warnf(format string, args ...interface{}) { - // TODO: don't log. +// TODO: don't log. +func logf(format string, args ...interface{}) { log.Printf(format, args...) } diff --git a/vendor/golang.org/x/text/message/pipeline/pipeline_test.go b/vendor/golang.org/x/text/message/pipeline/pipeline_test.go deleted file mode 100644 index 327e90d..0000000 --- a/vendor/golang.org/x/text/message/pipeline/pipeline_test.go +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package pipeline - -import ( - "bufio" - "bytes" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "os" - "path" - "path/filepath" - "strings" - "testing" - - "golang.org/x/text/language" -) - -var genFiles = flag.Bool("gen", false, "generate output files instead of comparing") - -func TestFullCycle(t *testing.T) { - const path = "./testdata" - dirs, err := ioutil.ReadDir(path) - if err != nil { - t.Fatal(err) - } - for _, f := range dirs { - t.Run(f.Name(), func(t *testing.T) { - chk := func(t *testing.T, err error) { - t.Helper() - if err != nil { - t.Fatal(err) - } - } - dir := filepath.Join(path, f.Name()) - pkgPath := fmt.Sprintf("%s/%s", path, f.Name()) - config := Config{ - SourceLanguage: language.AmericanEnglish, - Packages: []string{pkgPath}, - Dir: filepath.Join(dir, "locales"), - GenFile: "catalog_gen.go", - GenPackage: pkgPath, - } - // TODO: load config if available. - s, err := Extract(&config) - chk(t, err) - chk(t, s.Import()) - // chk(t, s.Merge()) // TODO - // TODO: - // for range s.Config.Actions { - // // TODO: do the actions. - // } - // chk(t, s.Export()) // TODO - chk(t, s.Generate()) - - writeJSON(t, filepath.Join(dir, "extracted.gotext.json"), s.Extracted) - checkOutput(t, dir) - }) - } -} - -func checkOutput(t *testing.T, p string) { - filepath.Walk(p, func(p string, f os.FileInfo, err error) error { - if f.IsDir() { - return nil - } - if filepath.Ext(p) != ".want" { - return nil - } - gotFile := p[:len(p)-len(".want")] - got, err := ioutil.ReadFile(gotFile) - if err != nil { - t.Errorf("failed to read %q", p) - return nil - } - if *genFiles { - if err := ioutil.WriteFile(p, got, 0644); err != nil { - t.Fatal(err) - } - } - want, err := ioutil.ReadFile(p) - if err != nil { - t.Errorf("failed to read %q", p) - } else { - scanGot := bufio.NewScanner(bytes.NewReader(got)) - scanWant := bufio.NewScanner(bytes.NewReader(want)) - line := 0 - clean := func(s string) string { - s = path.Clean(filepath.ToSlash(s)) - if i := strings.LastIndex(s, "Size:"); i != -1 { - s = s[:i] - } - if i := strings.LastIndex(s, "Total table size"); i != -1 { - s = s[:i] - } - return s - } - for scanGot.Scan() && scanWant.Scan() { - got := clean(scanGot.Text()) - want := clean(scanWant.Text()) - if got != want { - t.Errorf("file %q differs from .want file at line %d:\n\t%s\n\t%s", gotFile, line, got, want) - break - } - line++ - } - if scanGot.Scan() || scanWant.Scan() { - t.Errorf("file %q differs from .want file at line %d.", gotFile, line) - } - } - return nil - }) -} - -func writeJSON(t *testing.T, path string, x interface{}) { - data, err := json.MarshalIndent(x, "", " ") - if err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(path, data, 0644); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/golang.org/x/text/message/pipeline/rewrite.go b/vendor/golang.org/x/text/message/pipeline/rewrite.go index cf1511f..fa78324 100644 --- a/vendor/golang.org/x/text/message/pipeline/rewrite.go +++ b/vendor/golang.org/x/text/message/pipeline/rewrite.go @@ -24,11 +24,11 @@ const printerType = "golang.org/x/text/message.Printer" // machinery and rewrites strings to adopt best practices when possible. // If w is not nil the generated files are written to it, each files with a // "--- <filename>" header. Otherwise the files are overwritten. -func Rewrite(w io.Writer, args ...string) error { +func Rewrite(w io.Writer, goPackage string) error { conf := &loader.Config{ AllowErrors: true, // Allow unused instances of message.Printer. } - prog, err := loadPackages(conf, args) + prog, err := loadPackages(conf, []string{goPackage}) if err != nil { return wrap(err, "") } diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go b/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go deleted file mode 100644 index 8195287..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go +++ /dev/null @@ -1,83 +0,0 @@ -// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. - -package main - -import ( - "golang.org/x/text/language" - "golang.org/x/text/message" - "golang.org/x/text/message/catalog" -) - -type dictionary struct { - index []uint32 - data string -} - -func (d *dictionary) Lookup(key string) (data string, ok bool) { - p := messageKeyToIndex[key] - start, end := d.index[p], d.index[p+1] - if start == end { - return "", false - } - return d.data[start:end], true -} - -func init() { - dict := map[string]catalog.Dictionary{ - "de": &dictionary{index: deIndex, data: deData}, - "en_US": &dictionary{index: en_USIndex, data: en_USData}, - "zh": &dictionary{index: zhIndex, data: zhData}, - } - fallback := language.MustParse("en-US") - cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback)) - if err != nil { - panic(err) - } - message.DefaultCatalog = cat -} - -var messageKeyToIndex = map[string]int{ - "%.2[1]f miles traveled (%[1]f)": 7, - "%[1]s is visiting %[3]s!\n": 3, - "%d files remaining!": 4, - "%d more files remaining!": 5, - "%s is out of order!": 6, - "%s is visiting %s!\n": 2, - "Hello %s!\n": 1, - "Hello world!\n": 0, -} - -var deIndex = []uint32{ // 9 elements - 0x00000000, 0x00000011, 0x00000023, 0x0000003d, - 0x00000057, 0x00000075, 0x00000094, 0x00000094, - 0x00000094, -} // Size: 60 bytes - -const deData string = "" + // Size: 148 bytes - "\x04\x00\x01\x0a\x0c\x02Hallo Welt!\x04\x00\x01\x0a\x0d\x02Hallo %[1]s!" + - "\x04\x00\x01\x0a\x15\x02%[1]s besucht %[2]s!\x04\x00\x01\x0a\x15\x02%[1]" + - "s besucht %[3]s!\x02Noch zwei Bestände zu gehen!\x02Noch %[1]d Bestände " + - "zu gehen!" - -var en_USIndex = []uint32{ // 9 elements - 0x00000000, 0x00000012, 0x00000024, 0x00000042, - 0x00000060, 0x00000060, 0x000000a3, 0x000000ba, - 0x000000d9, -} // Size: 60 bytes - -const en_USData string = "" + // Size: 217 bytes - "\x04\x00\x01\x0a\x0d\x02Hello world!\x04\x00\x01\x0a\x0d\x02Hello %[1]s!" + - "\x04\x00\x01\x0a\x19\x02%[1]s is visiting %[2]s!\x04\x00\x01\x0a\x19\x02" + - "%[1]s is visiting %[3]s!\x14\x01\x81\x01\x00\x02\x14\x02One file remaini" + - "ng!\x00&\x02There are %[1]d more files remaining!\x02%[1]s is out of ord" + - "er!\x02%.2[1]f miles traveled (%[1]f)" - -var zhIndex = []uint32{ // 9 elements - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, -} // Size: 60 bytes - -const zhData string = "" - -// Total table size 545 bytes (0KiB); checksum: 343E0210 diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go.want b/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go.want deleted file mode 100644 index 8195287..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/catalog_gen.go.want +++ /dev/null @@ -1,83 +0,0 @@ -// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. - -package main - -import ( - "golang.org/x/text/language" - "golang.org/x/text/message" - "golang.org/x/text/message/catalog" -) - -type dictionary struct { - index []uint32 - data string -} - -func (d *dictionary) Lookup(key string) (data string, ok bool) { - p := messageKeyToIndex[key] - start, end := d.index[p], d.index[p+1] - if start == end { - return "", false - } - return d.data[start:end], true -} - -func init() { - dict := map[string]catalog.Dictionary{ - "de": &dictionary{index: deIndex, data: deData}, - "en_US": &dictionary{index: en_USIndex, data: en_USData}, - "zh": &dictionary{index: zhIndex, data: zhData}, - } - fallback := language.MustParse("en-US") - cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback)) - if err != nil { - panic(err) - } - message.DefaultCatalog = cat -} - -var messageKeyToIndex = map[string]int{ - "%.2[1]f miles traveled (%[1]f)": 7, - "%[1]s is visiting %[3]s!\n": 3, - "%d files remaining!": 4, - "%d more files remaining!": 5, - "%s is out of order!": 6, - "%s is visiting %s!\n": 2, - "Hello %s!\n": 1, - "Hello world!\n": 0, -} - -var deIndex = []uint32{ // 9 elements - 0x00000000, 0x00000011, 0x00000023, 0x0000003d, - 0x00000057, 0x00000075, 0x00000094, 0x00000094, - 0x00000094, -} // Size: 60 bytes - -const deData string = "" + // Size: 148 bytes - "\x04\x00\x01\x0a\x0c\x02Hallo Welt!\x04\x00\x01\x0a\x0d\x02Hallo %[1]s!" + - "\x04\x00\x01\x0a\x15\x02%[1]s besucht %[2]s!\x04\x00\x01\x0a\x15\x02%[1]" + - "s besucht %[3]s!\x02Noch zwei Bestände zu gehen!\x02Noch %[1]d Bestände " + - "zu gehen!" - -var en_USIndex = []uint32{ // 9 elements - 0x00000000, 0x00000012, 0x00000024, 0x00000042, - 0x00000060, 0x00000060, 0x000000a3, 0x000000ba, - 0x000000d9, -} // Size: 60 bytes - -const en_USData string = "" + // Size: 217 bytes - "\x04\x00\x01\x0a\x0d\x02Hello world!\x04\x00\x01\x0a\x0d\x02Hello %[1]s!" + - "\x04\x00\x01\x0a\x19\x02%[1]s is visiting %[2]s!\x04\x00\x01\x0a\x19\x02" + - "%[1]s is visiting %[3]s!\x14\x01\x81\x01\x00\x02\x14\x02One file remaini" + - "ng!\x00&\x02There are %[1]d more files remaining!\x02%[1]s is out of ord" + - "er!\x02%.2[1]f miles traveled (%[1]f)" - -var zhIndex = []uint32{ // 9 elements - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, -} // Size: 60 bytes - -const zhData string = "" - -// Total table size 545 bytes (0KiB); checksum: 343E0210 diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json b/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json deleted file mode 100644 index 4d317af..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json +++ /dev/null @@ -1,188 +0,0 @@ -{ - "language": "en-US", - "messages": [ - { - "id": "Hello world!", - "key": "Hello world!\n", - "message": "Hello world!", - "translation": "", - "position": "testdata/test1/test1.go:19:10" - }, - { - "id": "Hello {City}!", - "key": "Hello %s!\n", - "message": "Hello {City}!", - "translation": "", - "placeholders": [ - { - "id": "City", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "city" - } - ], - "position": "testdata/test1/test1.go:24:10" - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%s is visiting %s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "person", - "comment": "The person of matter." - }, - { - "id": "Place", - "string": "%[2]s", - "type": "string", - "underlyingType": "string", - "argNum": 2, - "expr": "place", - "comment": "Place the person is visiting." - } - ], - "position": "testdata/test1/test1.go:30:10" - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%[1]s is visiting %[3]s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "comment": "Field names are placeholders.", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "pp.Person" - }, - { - "id": "Place", - "string": "%[3]s", - "type": "string", - "underlyingType": "string", - "argNum": 3, - "expr": "pp.Place", - "comment": "Place the person is visiting." - }, - { - "id": "Extra", - "string": "%[2]v", - "type": "int", - "underlyingType": "int", - "argNum": 2, - "expr": "pp.extra" - } - ], - "position": "testdata/test1/test1.go:44:10" - }, - { - "id": "{2} files remaining!", - "key": "%d files remaining!", - "message": "{2} files remaining!", - "translation": "", - "placeholders": [ - { - "id": "2", - "string": "%[1]d", - "type": "int", - "underlyingType": "int", - "argNum": 1, - "expr": "2" - } - ], - "position": "testdata/test1/test1.go:51:10" - }, - { - "id": "{N} more files remaining!", - "key": "%d more files remaining!", - "message": "{N} more files remaining!", - "translation": "", - "placeholders": [ - { - "id": "N", - "string": "%[1]d", - "type": "int", - "underlyingType": "int", - "argNum": 1, - "expr": "n" - } - ], - "position": "testdata/test1/test1.go:56:10" - }, - { - "id": "Use the following code for your discount: {ReferralCode}", - "key": "Use the following code for your discount: %d\n", - "message": "Use the following code for your discount: {ReferralCode}", - "translation": "", - "placeholders": [ - { - "id": "ReferralCode", - "string": "%[1]d", - "type": "./testdata/test1.referralCode", - "underlyingType": "int", - "argNum": 1, - "expr": "c" - } - ], - "position": "testdata/test1/test1.go:64:10" - }, - { - "id": [ - "msgOutOfOrder", - "{Device} is out of order!" - ], - "key": "%s is out of order!", - "message": "{Device} is out of order!", - "translation": "", - "comment": "This comment wins.\n", - "placeholders": [ - { - "id": "Device", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "device" - } - ], - "position": "testdata/test1/test1.go:70:10" - }, - { - "id": "{Miles} miles traveled ({Miles_1})", - "key": "%.2[1]f miles traveled (%[1]f)", - "message": "{Miles} miles traveled ({Miles_1})", - "translation": "", - "placeholders": [ - { - "id": "Miles", - "string": "%.2[1]f", - "type": "float64", - "underlyingType": "float64", - "argNum": 1, - "expr": "miles" - }, - { - "id": "Miles_1", - "string": "%[1]f", - "type": "float64", - "underlyingType": "float64", - "argNum": 1, - "expr": "miles" - } - ], - "position": "testdata/test1/test1.go:74:10" - } - ] -}
\ No newline at end of file diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json.want b/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json.want deleted file mode 100644 index 4d317af..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/extracted.gotext.json.want +++ /dev/null @@ -1,188 +0,0 @@ -{ - "language": "en-US", - "messages": [ - { - "id": "Hello world!", - "key": "Hello world!\n", - "message": "Hello world!", - "translation": "", - "position": "testdata/test1/test1.go:19:10" - }, - { - "id": "Hello {City}!", - "key": "Hello %s!\n", - "message": "Hello {City}!", - "translation": "", - "placeholders": [ - { - "id": "City", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "city" - } - ], - "position": "testdata/test1/test1.go:24:10" - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%s is visiting %s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "person", - "comment": "The person of matter." - }, - { - "id": "Place", - "string": "%[2]s", - "type": "string", - "underlyingType": "string", - "argNum": 2, - "expr": "place", - "comment": "Place the person is visiting." - } - ], - "position": "testdata/test1/test1.go:30:10" - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%[1]s is visiting %[3]s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "comment": "Field names are placeholders.", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "pp.Person" - }, - { - "id": "Place", - "string": "%[3]s", - "type": "string", - "underlyingType": "string", - "argNum": 3, - "expr": "pp.Place", - "comment": "Place the person is visiting." - }, - { - "id": "Extra", - "string": "%[2]v", - "type": "int", - "underlyingType": "int", - "argNum": 2, - "expr": "pp.extra" - } - ], - "position": "testdata/test1/test1.go:44:10" - }, - { - "id": "{2} files remaining!", - "key": "%d files remaining!", - "message": "{2} files remaining!", - "translation": "", - "placeholders": [ - { - "id": "2", - "string": "%[1]d", - "type": "int", - "underlyingType": "int", - "argNum": 1, - "expr": "2" - } - ], - "position": "testdata/test1/test1.go:51:10" - }, - { - "id": "{N} more files remaining!", - "key": "%d more files remaining!", - "message": "{N} more files remaining!", - "translation": "", - "placeholders": [ - { - "id": "N", - "string": "%[1]d", - "type": "int", - "underlyingType": "int", - "argNum": 1, - "expr": "n" - } - ], - "position": "testdata/test1/test1.go:56:10" - }, - { - "id": "Use the following code for your discount: {ReferralCode}", - "key": "Use the following code for your discount: %d\n", - "message": "Use the following code for your discount: {ReferralCode}", - "translation": "", - "placeholders": [ - { - "id": "ReferralCode", - "string": "%[1]d", - "type": "./testdata/test1.referralCode", - "underlyingType": "int", - "argNum": 1, - "expr": "c" - } - ], - "position": "testdata/test1/test1.go:64:10" - }, - { - "id": [ - "msgOutOfOrder", - "{Device} is out of order!" - ], - "key": "%s is out of order!", - "message": "{Device} is out of order!", - "translation": "", - "comment": "This comment wins.\n", - "placeholders": [ - { - "id": "Device", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "device" - } - ], - "position": "testdata/test1/test1.go:70:10" - }, - { - "id": "{Miles} miles traveled ({Miles_1})", - "key": "%.2[1]f miles traveled (%[1]f)", - "message": "{Miles} miles traveled ({Miles_1})", - "translation": "", - "placeholders": [ - { - "id": "Miles", - "string": "%.2[1]f", - "type": "float64", - "underlyingType": "float64", - "argNum": 1, - "expr": "miles" - }, - { - "id": "Miles_1", - "string": "%[1]f", - "type": "float64", - "underlyingType": "float64", - "argNum": 1, - "expr": "miles" - } - ], - "position": "testdata/test1/test1.go:74:10" - } - ] -}
\ No newline at end of file diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/de/messages.gotext.json b/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/de/messages.gotext.json deleted file mode 100755 index f92e4a1..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/de/messages.gotext.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "language": "de", - "messages": [ - { - "id": "Hello world!", - "key": "Hello world!\n", - "message": "Hello world!", - "translation": "Hallo Welt!" - }, - { - "id": "Hello {City}!", - "key": "Hello %s!\n", - "message": "Hello {City}!", - "translation": "Hallo {City}!", - "placeholders": [ - { - "id": "City", - "string": "%[1]s" - } - ] - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%s is visiting %s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "{Person} besucht {Place}!", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s" - }, - { - "id": "Place", - "string": "%[2]s" - } - ] - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%[1]s is visiting %[3]s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "{Person} besucht {Place}!", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s" - }, - { - "id": "Place", - "string": "%[3]s" - }, - { - "id": "Extra", - "string": "%[2]v" - } - ] - }, - { - "id": "{2} files remaining!", - "key": "%d files remaining!", - "message": "{N} files remaining!", - "translation": "Noch zwei Bestände zu gehen!", - "placeholders": [ - { - "id": "2", - "string": "%[1]d" - } - ] - }, - { - "id": "{N} more files remaining!", - "key": "%d more files remaining!", - "message": "{N} more files remaining!", - "translation": "Noch {N} Bestände zu gehen!", - "placeholders": [ - { - "id": "N", - "string": "%[1]d" - } - ] - }, - { - "id": "Use the following code for your discount: {ReferralCode}", - "key": "Use the following code for your discount: %d\n", - "message": "Use the following code for your discount: {ReferralCode}", - "translation": "", - "placeholders": [ - { - "id": "ReferralCode", - "string": "%[1]d" - } - ] - }, - { - "id": [ "msgOutOfOrder", "{Device} is out of order!" ], - "key": "%s is out of order!", - "message": "{Device} is out of order!", - "translation": "", - "placeholders": [ - { - "id": "Device", - "string": "%[1]s" - } - ] - }, - { - "id": "{Miles} miles traveled ({Miles_1})", - "key": "%.2[1]f miles traveled (%[1]f)", - "message": "{Miles} miles traveled ({Miles_1})", - "translation": "", - "placeholders": [ - { - "id": "Miles", - "string": "%.2[1]f" - }, - { - "id": "Miles_1", - "string": "%[1]f" - } - ] - } - ] -} diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/en-US/messages.gotext.json b/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/en-US/messages.gotext.json deleted file mode 100755 index b984242..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/en-US/messages.gotext.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "language": "en-US", - "messages": [ - { - "id": "Hello world!", - "key": "Hello world!\n", - "message": "Hello world!", - "translation": "Hello world!" - }, - { - "id": "Hello {City}!", - "key": "Hello %s!\n", - "message": "Hello {City}!", - "translation": "Hello {City}!" - }, - { - "id": "Hello {Town}!", - "key": "Hello %s!\n", - "message": "Hello {Town}!", - "translation": "Hello {Town}!", - "placeholders": [ - { - "id": "Town", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "town", - "comment": "Town" - } - ] - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%s is visiting %s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "{Person} is visiting {Place}!" - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%[1]s is visiting %[3]s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "{Person} is visiting {Place}!" - }, - { - "id": "{2} files remaining!", - "key": "%d files remaining!", - "message": "{N} files remaining!", - "translation": "", - "placeholders": [ - { - "id": "2", - "string": "%[1]d" - } - ] - }, - { - "id": "{N} more files remaining!", - "key": "%d more files remaining!", - "message": "{N} more files remaining!", - "translation": { - "select": { - "feature": "plural", - "arg": "N", - "cases": { - "one": "One file remaining!", - "other": "There are {N} more files remaining!" - } - } - } - }, - { - "id": "Use the following code for your discount: {ReferralCode}", - "key": "Use the following code for your discount: %d\n", - "message": "Use the following code for your discount: {ReferralCode}", - "translation": "" - }, - { - "id": [ "msgOutOfOrder", "{Device} is out of order!" ], - "key": "%s is out of order!", - "message": "{Device} is out of order!", - "translation": "{Device} is out of order!" - }, - { - "id": "{Miles} miles traveled ({Miles_1})", - "key": "%.2[1]f miles traveled (%[1]f)", - "message": "{Miles} miles traveled ({Miles_1})", - "translation": "{Miles} miles traveled ({Miles_1})" - } - ] -} diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/zh/messages.gotext.json b/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/zh/messages.gotext.json deleted file mode 100755 index c80d1d2..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/locales/zh/messages.gotext.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "language": "zh", - "messages": [ - { - "id": "Hello world!", - "key": "Hello world!\n", - "message": "Hello world!", - "translation": "" - }, - { - "id": "Hello {City}!", - "key": "Hello %s!\n", - "message": "Hello {City}!", - "translation": "", - "placeholders": [ - { - "id": "City", - "string": "%[1]s" - } - ] - }, - { - "id": "Hello {Town}!", - "key": "Hello %s!\n", - "message": "Hello {Town}!", - "translation": "", - "placeholders": [ - { - "id": "Town", - "string": "%[1]s" - } - ] - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%s is visiting %s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s" - }, - { - "id": "Place", - "string": "%[2]s" - } - ] - }, - { - "id": "{Person} is visiting {Place}!", - "key": "%[1]s is visiting %[3]s!\n", - "message": "{Person} is visiting {Place}!", - "translation": "", - "placeholders": [ - { - "id": "Person", - "string": "%[1]s" - }, - { - "id": "Place", - "string": "%[3]s" - }, - { - "id": "Extra", - "string": "%[2]v" - } - ] - }, - { - "id": "{2} files remaining!", - "key": "%d files remaining!", - "message": "{2} files remaining!", - "translation": "", - "placeholders": [ - { - "id": "", - "string": "%[1]d" - } - ] - }, - { - "id": "{N} more files remaining!", - "key": "%d more files remaining!", - "message": "{N} more files remaining!", - "translation": "", - "placeholders": [ - { - "id": "N", - "string": "%[1]d" - } - ] - }, - { - "id": "Use the following code for your discount: {ReferralCode}", - "key": "Use the following code for your discount: %d\n", - "message": "Use the following code for your discount: {ReferralCode}", - "translation": "", - "placeholders": [ - { - "id": "ReferralCode", - "string": "%[1]d" - } - ] - }, - { - "id": [ "{Device} is out of order!", "msgOutOfOrder" ], - "key": "%s is out of order!", - "message": "{Device} is out of order!", - "translation": "", - "placeholders": [ - { - "id": "Device", - "string": "%[1]s" - } - ] - }, - { - "id": "{Miles} miles traveled ({Miles_1})", - "key": "%.2[1]f miles traveled (%[1]f)", - "message": "{Miles} miles traveled ({Miles_1})", - "translation": "", - "placeholders": [ - { - "id": "Miles", - "string": "%.2[1]f" - }, - { - "id": "Miles_1", - "string": "%[1]f" - } - ] - } - ] -}
\ No newline at end of file diff --git a/vendor/golang.org/x/text/message/pipeline/testdata/test1/test1.go b/vendor/golang.org/x/text/message/pipeline/testdata/test1/test1.go deleted file mode 100644 index 88051f9..0000000 --- a/vendor/golang.org/x/text/message/pipeline/testdata/test1/test1.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "golang.org/x/text/message" - -func main() { - p := message.NewPrinter(message.MatchLanguage("en")) - - // NOT EXTRACTED: strings passed to Println are not extracted. - p.Println("Hello world!") - - // NOT EXTRACTED: strings passed to Print are not extracted. - p.Print("Hello world!\n") - - // Extract and trim whitespace (TODO). - p.Printf("Hello world!\n") - - // NOT EXTRACTED: city is not used as a pattern or passed to %m. - city := "Amsterdam" - // This comment is extracted. - p.Printf("Hello %s!\n", city) - - person := "Sheila" - place := "Zürich" - - // Substitutions replaced by variable names. - p.Printf("%s is visiting %s!\n", - person, // The person of matter. - place, // Place the person is visiting. - ) - - pp := struct { - Person string // The person of matter. // TODO: get this comment. - Place string - extra int - }{ - person, place, 4, - } - - // extract will drop this comment in favor of the one below. - p.Printf("%[1]s is visiting %[3]s!\n", // Field names are placeholders. - pp.Person, - pp.extra, - pp.Place, // Place the person is visiting. - ) - - // Numeric literal becomes placeholder. - p.Printf("%d files remaining!", 2) - - const n = 2 - - // Constant identifier becomes placeholder. - p.Printf("%d more files remaining!", n) - - // Infer better names from type names. - type referralCode int - - const c = referralCode(5) - - // Use type name as placeholder. - p.Printf("Use the following code for your discount: %d\n", c) - - // Use constant name as message ID. - const msgOutOfOrder = "%s is out of order!" // This comment wins. - const device = "Soda machine" - // This message has two IDs. - p.Printf(msgOutOfOrder, device) - - // Multiple substitutions for same argument. - miles := 1.2345 - p.Printf("%.2[1]f miles traveled (%[1]f)", miles) -} |