From 0135904f7d3e1c0e763adaefe267c736616e3d26 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 16 Nov 2016 19:28:52 -0500 Subject: Upgrading server dependancies (#4566) --- .../nicksnyder/go-i18n/goi18n/constants_command.go | 230 +++++++++++++++++++++ .../go-i18n/goi18n/constants_command_test.go | 42 ++++ vendor/github.com/nicksnyder/go-i18n/goi18n/doc.go | 38 +++- .../github.com/nicksnyder/go-i18n/goi18n/gendoc.sh | 4 +- .../github.com/nicksnyder/go-i18n/goi18n/goi18n.go | 95 +++------ .../github.com/nicksnyder/go-i18n/goi18n/merge.go | 127 ------------ .../nicksnyder/go-i18n/goi18n/merge_command.go | 206 ++++++++++++++++++ .../go-i18n/goi18n/merge_command_test.go | 74 +++++++ .../nicksnyder/go-i18n/goi18n/merge_test.go | 74 ------- .../go-i18n/goi18n/testdata/expected/R.go | 38 ++++ .../goi18n/testdata/input/en-us.constants.json | 45 ++++ 11 files changed, 708 insertions(+), 265 deletions(-) create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command.go create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command_test.go delete mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/merge.go create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command.go create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command_test.go delete mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/merge_test.go create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/expected/R.go create mode 100644 vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/input/en-us.constants.json (limited to 'vendor/github.com/nicksnyder/go-i18n/goi18n') diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command.go new file mode 100644 index 000000000..85b1ac18e --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command.go @@ -0,0 +1,230 @@ +package main + +import ( + "flag" + "fmt" + "os" + "path/filepath" + "reflect" + "regexp" + "sort" + "strconv" + "strings" + "text/template" + "unicode" + + "github.com/nicksnyder/go-i18n/i18n/bundle" + "github.com/nicksnyder/go-i18n/i18n/language" + "github.com/nicksnyder/go-i18n/i18n/translation" +) + +type constantsCommand struct { + translationFiles []string + packageName string + outdir string +} + +type templateConstants struct { + ID string + Name string + Comments []string +} + +type templateHeader struct { + PackageName string + Constants []templateConstants +} + +var constTemplate = template.Must(template.New("").Parse(`// DON'T CHANGE THIS FILE MANUALLY +// This file was generated using the command: +// $ goi18n constants + +package {{.PackageName}} +{{range .Constants}} +// {{.Name}} is the identifier for the following localizable string template(s):{{range .Comments}} +// {{.}}{{end}} +const {{.Name}} = "{{.ID}}" +{{end}}`)) + +func (cc *constantsCommand) execute() error { + if len(cc.translationFiles) != 1 { + return fmt.Errorf("need one translation file") + } + + bundle := bundle.New() + + if err := bundle.LoadTranslationFile(cc.translationFiles[0]); err != nil { + return fmt.Errorf("failed to load translation file %s because %s\n", cc.translationFiles[0], err) + } + + translations := bundle.Translations() + lang := translations[bundle.LanguageTags()[0]] + + // create an array of id to organize + keys := make([]string, len(lang)) + i := 0 + + for id := range lang { + keys[i] = id + i++ + } + sort.Strings(keys) + + tmpl := &templateHeader{ + PackageName: cc.packageName, + Constants: make([]templateConstants, len(keys)), + } + + for i, id := range keys { + tmpl.Constants[i].ID = id + tmpl.Constants[i].Name = toCamelCase(id) + tmpl.Constants[i].Comments = toComments(lang[id]) + } + + filename := filepath.Join(cc.outdir, cc.packageName+".go") + f, err := os.Create(filename) + if err != nil { + return fmt.Errorf("failed to create file %s because %s", filename, err) + } + + defer f.Close() + + if err = constTemplate.Execute(f, tmpl); err != nil { + return fmt.Errorf("failed to write file %s because %s", filename, err) + } + + return nil +} + +func (cc *constantsCommand) parse(arguments []string) { + flags := flag.NewFlagSet("constants", flag.ExitOnError) + flags.Usage = usageConstants + + packageName := flags.String("package", "R", "") + outdir := flags.String("outdir", ".", "") + + flags.Parse(arguments) + + cc.translationFiles = flags.Args() + cc.packageName = *packageName + cc.outdir = *outdir +} + +func (cc *constantsCommand) SetArgs(args []string) { + cc.translationFiles = args +} + +func usageConstants() { + fmt.Printf(`Generate constant file from translation file. + +Usage: + + goi18n constants [options] [file] + +Translation files: + + A translation file contains the strings and translations for a single language. + + Translation file names must have a suffix of a supported format (e.g. .json) and + contain a valid language tag as defined by RFC 5646 (e.g. en-us, fr, zh-hant, etc.). + +Options: + + -package name + goi18n generates the constant file under the package name. + Default: R + + -outdir directory + goi18n writes the constant file to this directory. + Default: . + +`) + os.Exit(1) +} + +// commonInitialisms is a set of common initialisms. +// Only add entries that are highly unlikely to be non-initialisms. +// For instance, "ID" is fine (Freudian code is rare), but "AND" is not. +// https://github.com/golang/lint/blob/master/lint.go +var commonInitialisms = map[string]bool{ + "API": true, + "ASCII": true, + "CPU": true, + "CSS": true, + "DNS": true, + "EOF": true, + "GUID": true, + "HTML": true, + "HTTP": true, + "HTTPS": true, + "ID": true, + "IP": true, + "JSON": true, + "LHS": true, + "QPS": true, + "RAM": true, + "RHS": true, + "RPC": true, + "SLA": true, + "SMTP": true, + "SQL": true, + "SSH": true, + "TCP": true, + "TLS": true, + "TTL": true, + "UDP": true, + "UI": true, + "UID": true, + "UUID": true, + "URI": true, + "URL": true, + "UTF8": true, + "VM": true, + "XML": true, + "XSRF": true, + "XSS": true, +} + +func toCamelCase(id string) string { + var result string + + r := regexp.MustCompile(`[\-\.\_\s]`) + words := r.Split(id, -1) + + for _, w := range words { + upper := strings.ToUpper(w) + if commonInitialisms[upper] { + result += upper + continue + } + + if len(w) > 0 { + u := []rune(w) + u[0] = unicode.ToUpper(u[0]) + result += string(u) + } + } + return result +} + +func toComments(trans translation.Translation) []string { + var result []string + data := trans.MarshalInterface().(map[string]interface{}) + + t := data["translation"] + + switch v := reflect.ValueOf(t); v.Kind() { + case reflect.Map: + for _, k := range []language.Plural{"zero", "one", "two", "few", "many", "other"} { + vt := v.MapIndex(reflect.ValueOf(k)) + if !vt.IsValid() { + continue + } + result = append(result, string(k)+": "+strconv.Quote(fmt.Sprint(vt.Interface()))) + } + default: + result = append(result, strconv.Quote(fmt.Sprint(t))) + } + + return result +} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command_test.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command_test.go new file mode 100644 index 000000000..43dea3f38 --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/constants_command_test.go @@ -0,0 +1,42 @@ +package main + +import "testing" + +func TestConstantsExecute(t *testing.T) { + resetDir(t, "testdata/output") + + cc := &constantsCommand{ + translationFiles: []string{"testdata/input/en-us.constants.json"}, + packageName: "R", + outdir: "testdata/output", + } + + if err := cc.execute(); err != nil { + t.Fatal(err) + } + + expectEqualFiles(t, "testdata/output/R.go", "testdata/expected/R.go") +} + +func TestToCamelCase(t *testing.T) { + expectEqual := func(test, expected string) { + result := toCamelCase(test) + if result != expected { + t.Fatalf("failed toCamelCase the test %s was expected %s but the result was %s", test, expected, result) + } + } + + expectEqual("", "") + expectEqual("a", "A") + expectEqual("_", "") + expectEqual("__code__", "Code") + expectEqual("test", "Test") + expectEqual("test_one", "TestOne") + expectEqual("test.two", "TestTwo") + expectEqual("test_alpha_beta", "TestAlphaBeta") + expectEqual("word word", "WordWord") + expectEqual("test_id", "TestID") + expectEqual("tcp_name", "TCPName") + expectEqual("こんにちは", "こんにちは") + expectEqual("test_a", "TestA") +} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/doc.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/doc.go index 10d244217..97c7a7fb6 100644 --- a/vendor/github.com/nicksnyder/go-i18n/goi18n/doc.go +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/doc.go @@ -5,11 +5,22 @@ // // Help documentation: // -// goi18n formats and merges translation files. +// goi18n manages translation files. // // Usage: // -// goi18n [options] [files...] +// goi18n merge Merge translation files +// goi18n constants Generate constant file from translation file +// +// For more details execute: +// +// goi18n [command] -help +// +// Merge translation files. +// +// Usage: +// +// goi18n merge [options] [files...] // // Translation files: // @@ -56,4 +67,27 @@ // Supported formats: json, yaml // Default: json // +// Generate constant file from translation file. +// +// Usage: +// +// goi18n constants [options] [file] +// +// Translation files: +// +// A translation file contains the strings and translations for a single language. +// +// Translation file names must have a suffix of a supported format (e.g. .json) and +// contain a valid language tag as defined by RFC 5646 (e.g. en-us, fr, zh-hant, etc.). +// +// Options: +// +// -package name +// goi18n generates the constant file under the package name. +// Default: R +// +// -outdir directory +// goi18n writes the constant file to this directory. +// Default: . +// package main diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/gendoc.sh b/vendor/github.com/nicksnyder/go-i18n/goi18n/gendoc.sh index 094f479a5..f30df34e6 100644 --- a/vendor/github.com/nicksnyder/go-i18n/goi18n/gendoc.sh +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/gendoc.sh @@ -6,5 +6,7 @@ echo "// goi18n -help" >> doc.go echo "//" >> doc.go echo "// Help documentation:" >> doc.go echo "//" >> doc.go -goi18n -help | sed -e 's/^/\/\/ /' >> doc.go +goi18n | sed -e 's/^/\/\/ /' >> doc.go +goi18n merge -help | sed -e 's/^/\/\/ /' >> doc.go +goi18n constants -help | sed -e 's/^/\/\/ /' >> doc.go echo "package main" >> doc.go diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go index f57ea8175..3bd763f47 100644 --- a/vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go @@ -6,77 +6,50 @@ import ( "os" ) -func usage() { - fmt.Printf(`goi18n formats and merges translation files. - -Usage: - - goi18n [options] [files...] - -Translation files: - - A translation file contains the strings and translations for a single language. - - Translation file names must have a suffix of a supported format (e.g. .json) and - contain a valid language tag as defined by RFC 5646 (e.g. en-us, fr, zh-hant, etc.). - - For each language represented by at least one input translation file, goi18n will produce 2 output files: - - xx-yy.all.format - This file contains all strings for the language (translated and untranslated). - Use this file when loading strings at runtime. +type command interface { + execute() error + parse(arguments []string) +} - xx-yy.untranslated.format - This file contains the strings that have not been translated for this language. - The translations for the strings in this file will be extracted from the source language. - After they are translated, merge them back into xx-yy.all.format using goi18n. +func main() { + flag.Usage = usage -Merging: + if len(os.Args) == 1 { + usage() + } - goi18n will merge multiple translation files for the same language. - Duplicate translations will be merged into the existing translation. - Non-empty fields in the duplicate translation will overwrite those fields in the existing translation. - Empty fields in the duplicate translation are ignored. + var cmd command + + switch os.Args[1] { + case "merge": + cmd = &mergeCommand{} + cmd.parse(os.Args[2:]) + case "constants": + cmd = &constantsCommand{} + cmd.parse(os.Args[2:]) + default: + cmd = &mergeCommand{} + cmd.parse(os.Args[1:]) + } -Adding a new language: + if err := cmd.execute(); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } +} - To produce translation files for a new language, create an empty translation file with the - appropriate name and pass it in to goi18n. +func usage() { + fmt.Printf(`goi18n manages translation files. -Options: +Usage: - -sourceLanguage tag - goi18n uses the strings from this language to seed the translations for other languages. - Default: en-us + goi18n merge Merge translation files + goi18n constants Generate constant file from translation file - -outdir directory - goi18n writes the output translation files to this directory. - Default: . +For more details execute: - -format format - goi18n encodes the output translation files in this format. - Supported formats: json, yaml - Default: json + goi18n [command] -help `) os.Exit(1) } - -func main() { - flag.Usage = usage - sourceLanguage := flag.String("sourceLanguage", "en-us", "") - outdir := flag.String("outdir", ".", "") - format := flag.String("format", "json", "") - flag.Parse() - - mc := &mergeCommand{ - translationFiles: flag.Args(), - sourceLanguageTag: *sourceLanguage, - outdir: *outdir, - format: *format, - } - if err := mc.execute(); err != nil { - fmt.Println(err.Error()) - os.Exit(1) - } -} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge.go deleted file mode 100644 index 1317fe958..000000000 --- a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge.go +++ /dev/null @@ -1,127 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "gopkg.in/yaml.v2" - "io/ioutil" - "path/filepath" - "reflect" - "sort" - - "github.com/nicksnyder/go-i18n/i18n/bundle" - "github.com/nicksnyder/go-i18n/i18n/language" - "github.com/nicksnyder/go-i18n/i18n/translation" -) - -type mergeCommand struct { - translationFiles []string - sourceLanguageTag string - outdir string - format string -} - -func (mc *mergeCommand) execute() error { - if len(mc.translationFiles) < 1 { - return fmt.Errorf("need at least one translation file to parse") - } - - if lang := language.Parse(mc.sourceLanguageTag); lang == nil { - return fmt.Errorf("invalid source locale: %s", mc.sourceLanguageTag) - } - - marshal, err := newMarshalFunc(mc.format) - if err != nil { - return err - } - - bundle := bundle.New() - for _, tf := range mc.translationFiles { - if err := bundle.LoadTranslationFile(tf); err != nil { - return fmt.Errorf("failed to load translation file %s because %s\n", tf, err) - } - } - - translations := bundle.Translations() - sourceLanguageTag := language.NormalizeTag(mc.sourceLanguageTag) - sourceTranslations := translations[sourceLanguageTag] - if sourceTranslations == nil { - return fmt.Errorf("no translations found for source locale %s", sourceLanguageTag) - } - for translationID, src := range sourceTranslations { - for _, localeTranslations := range translations { - if dst := localeTranslations[translationID]; dst == nil || reflect.TypeOf(src) != reflect.TypeOf(dst) { - localeTranslations[translationID] = src.UntranslatedCopy() - } - } - } - - for localeID, localeTranslations := range translations { - lang := language.MustParse(localeID)[0] - all := filter(localeTranslations, func(t translation.Translation) translation.Translation { - return t.Normalize(lang) - }) - if err := mc.writeFile("all", all, localeID, marshal); err != nil { - return err - } - - untranslated := filter(localeTranslations, func(t translation.Translation) translation.Translation { - if t.Incomplete(lang) { - return t.Normalize(lang).Backfill(sourceTranslations[t.ID()]) - } - return nil - }) - if err := mc.writeFile("untranslated", untranslated, localeID, marshal); err != nil { - return err - } - } - return nil -} - -type marshalFunc func(interface{}) ([]byte, error) - -func (mc *mergeCommand) writeFile(label string, translations []translation.Translation, localeID string, marshal marshalFunc) error { - sort.Sort(translation.SortableByID(translations)) - buf, err := marshal(marshalInterface(translations)) - if err != nil { - return fmt.Errorf("failed to marshal %s strings to %s because %s", localeID, mc.format, err) - } - filename := filepath.Join(mc.outdir, fmt.Sprintf("%s.%s.%s", localeID, label, mc.format)) - if err := ioutil.WriteFile(filename, buf, 0666); err != nil { - return fmt.Errorf("failed to write %s because %s", filename, err) - } - return nil -} - -func filter(translations map[string]translation.Translation, filter func(translation.Translation) translation.Translation) []translation.Translation { - filtered := make([]translation.Translation, 0, len(translations)) - for _, translation := range translations { - if t := filter(translation); t != nil { - filtered = append(filtered, t) - } - } - return filtered - -} - -func newMarshalFunc(format string) (marshalFunc, error) { - switch format { - case "json": - return func(v interface{}) ([]byte, error) { - return json.MarshalIndent(v, "", " ") - }, nil - case "yaml": - return func(v interface{}) ([]byte, error) { - return yaml.Marshal(v) - }, nil - } - return nil, fmt.Errorf("unsupported format: %s\n", format) -} - -func marshalInterface(translations []translation.Translation) []interface{} { - mi := make([]interface{}, len(translations)) - for i, translation := range translations { - mi[i] = translation.MarshalInterface() - } - return mi -} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command.go new file mode 100644 index 000000000..1d34ac438 --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command.go @@ -0,0 +1,206 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" + "os" + "path/filepath" + "reflect" + "sort" + + "gopkg.in/yaml.v2" + + "github.com/nicksnyder/go-i18n/i18n/bundle" + "github.com/nicksnyder/go-i18n/i18n/language" + "github.com/nicksnyder/go-i18n/i18n/translation" +) + +type mergeCommand struct { + translationFiles []string + sourceLanguage string + outdir string + format string +} + +func (mc *mergeCommand) execute() error { + if len(mc.translationFiles) < 1 { + return fmt.Errorf("need at least one translation file to parse") + } + + if lang := language.Parse(mc.sourceLanguage); lang == nil { + return fmt.Errorf("invalid source locale: %s", mc.sourceLanguage) + } + + marshal, err := newMarshalFunc(mc.format) + if err != nil { + return err + } + + bundle := bundle.New() + for _, tf := range mc.translationFiles { + if err := bundle.LoadTranslationFile(tf); err != nil { + return fmt.Errorf("failed to load translation file %s because %s\n", tf, err) + } + } + + translations := bundle.Translations() + sourceLanguageTag := language.NormalizeTag(mc.sourceLanguage) + sourceTranslations := translations[sourceLanguageTag] + if sourceTranslations == nil { + return fmt.Errorf("no translations found for source locale %s", sourceLanguageTag) + } + for translationID, src := range sourceTranslations { + for _, localeTranslations := range translations { + if dst := localeTranslations[translationID]; dst == nil || reflect.TypeOf(src) != reflect.TypeOf(dst) { + localeTranslations[translationID] = src.UntranslatedCopy() + } + } + } + + for localeID, localeTranslations := range translations { + lang := language.MustParse(localeID)[0] + all := filter(localeTranslations, func(t translation.Translation) translation.Translation { + return t.Normalize(lang) + }) + if err := mc.writeFile("all", all, localeID, marshal); err != nil { + return err + } + + untranslated := filter(localeTranslations, func(t translation.Translation) translation.Translation { + if t.Incomplete(lang) { + return t.Normalize(lang).Backfill(sourceTranslations[t.ID()]) + } + return nil + }) + if err := mc.writeFile("untranslated", untranslated, localeID, marshal); err != nil { + return err + } + } + return nil +} + +func (mc *mergeCommand) parse(arguments []string) { + flags := flag.NewFlagSet("merge", flag.ExitOnError) + flags.Usage = usageMerge + + sourceLanguage := flags.String("sourceLanguage", "en-us", "") + outdir := flags.String("outdir", ".", "") + format := flags.String("format", "json", "") + + flags.Parse(arguments) + + mc.translationFiles = flags.Args() + mc.sourceLanguage = *sourceLanguage + mc.outdir = *outdir + mc.format = *format +} + +func (mc *mergeCommand) SetArgs(args []string) { + mc.translationFiles = args +} + +type marshalFunc func(interface{}) ([]byte, error) + +func (mc *mergeCommand) writeFile(label string, translations []translation.Translation, localeID string, marshal marshalFunc) error { + sort.Sort(translation.SortableByID(translations)) + buf, err := marshal(marshalInterface(translations)) + if err != nil { + return fmt.Errorf("failed to marshal %s strings to %s because %s", localeID, mc.format, err) + } + filename := filepath.Join(mc.outdir, fmt.Sprintf("%s.%s.%s", localeID, label, mc.format)) + if err := ioutil.WriteFile(filename, buf, 0666); err != nil { + return fmt.Errorf("failed to write %s because %s", filename, err) + } + return nil +} + +func filter(translations map[string]translation.Translation, filter func(translation.Translation) translation.Translation) []translation.Translation { + filtered := make([]translation.Translation, 0, len(translations)) + for _, translation := range translations { + if t := filter(translation); t != nil { + filtered = append(filtered, t) + } + } + return filtered + +} + +func newMarshalFunc(format string) (marshalFunc, error) { + switch format { + case "json": + return func(v interface{}) ([]byte, error) { + return json.MarshalIndent(v, "", " ") + }, nil + case "yaml": + return func(v interface{}) ([]byte, error) { + return yaml.Marshal(v) + }, nil + } + return nil, fmt.Errorf("unsupported format: %s\n", format) +} + +func marshalInterface(translations []translation.Translation) []interface{} { + mi := make([]interface{}, len(translations)) + for i, translation := range translations { + mi[i] = translation.MarshalInterface() + } + return mi +} + +func usageMerge() { + fmt.Printf(`Merge translation files. + +Usage: + + goi18n merge [options] [files...] + +Translation files: + + A translation file contains the strings and translations for a single language. + + Translation file names must have a suffix of a supported format (e.g. .json) and + contain a valid language tag as defined by RFC 5646 (e.g. en-us, fr, zh-hant, etc.). + + For each language represented by at least one input translation file, goi18n will produce 2 output files: + + xx-yy.all.format + This file contains all strings for the language (translated and untranslated). + Use this file when loading strings at runtime. + + xx-yy.untranslated.format + This file contains the strings that have not been translated for this language. + The translations for the strings in this file will be extracted from the source language. + After they are translated, merge them back into xx-yy.all.format using goi18n. + +Merging: + + goi18n will merge multiple translation files for the same language. + Duplicate translations will be merged into the existing translation. + Non-empty fields in the duplicate translation will overwrite those fields in the existing translation. + Empty fields in the duplicate translation are ignored. + +Adding a new language: + + To produce translation files for a new language, create an empty translation file with the + appropriate name and pass it in to goi18n. + +Options: + + -sourceLanguage tag + goi18n uses the strings from this language to seed the translations for other languages. + Default: en-us + + -outdir directory + goi18n writes the output translation files to this directory. + Default: . + + -format format + goi18n encodes the output translation files in this format. + Supported formats: json, yaml + Default: json + +`) + os.Exit(1) +} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command_test.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command_test.go new file mode 100644 index 000000000..37e46518b --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_command_test.go @@ -0,0 +1,74 @@ +package main + +import ( + "bytes" + "io/ioutil" + "os" + "testing" +) + +func TestMergeExecuteJSON(t *testing.T) { + files := []string{ + "testdata/input/en-us.one.json", + "testdata/input/en-us.two.json", + "testdata/input/fr-fr.json", + "testdata/input/ar-ar.one.json", + "testdata/input/ar-ar.two.json", + } + testMergeExecute(t, files) +} + +func TestMergeExecuteYAML(t *testing.T) { + files := []string{ + "testdata/input/yaml/en-us.one.yaml", + "testdata/input/yaml/en-us.two.json", + "testdata/input/yaml/fr-fr.json", + "testdata/input/yaml/ar-ar.one.json", + "testdata/input/yaml/ar-ar.two.json", + } + testMergeExecute(t, files) +} + +func testMergeExecute(t *testing.T, files []string) { + resetDir(t, "testdata/output") + + mc := &mergeCommand{ + translationFiles: files, + sourceLanguage: "en-us", + outdir: "testdata/output", + format: "json", + } + if err := mc.execute(); err != nil { + t.Fatal(err) + } + + expectEqualFiles(t, "testdata/output/en-us.all.json", "testdata/expected/en-us.all.json") + expectEqualFiles(t, "testdata/output/ar-ar.all.json", "testdata/expected/ar-ar.all.json") + expectEqualFiles(t, "testdata/output/fr-fr.all.json", "testdata/expected/fr-fr.all.json") + expectEqualFiles(t, "testdata/output/en-us.untranslated.json", "testdata/expected/en-us.untranslated.json") + expectEqualFiles(t, "testdata/output/ar-ar.untranslated.json", "testdata/expected/ar-ar.untranslated.json") + expectEqualFiles(t, "testdata/output/fr-fr.untranslated.json", "testdata/expected/fr-fr.untranslated.json") +} + +func resetDir(t *testing.T, dir string) { + if err := os.RemoveAll(dir); err != nil { + t.Fatal(err) + } + if err := os.Mkdir(dir, 0777); err != nil { + t.Fatal(err) + } +} + +func expectEqualFiles(t *testing.T, expectedName, actualName string) { + actual, err := ioutil.ReadFile(actualName) + if err != nil { + t.Fatal(err) + } + expected, err := ioutil.ReadFile(expectedName) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(actual, expected) { + t.Fatalf("contents of files did not match: %s, %s", expectedName, actualName) + } +} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_test.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_test.go deleted file mode 100644 index f0d0d47a1..000000000 --- a/vendor/github.com/nicksnyder/go-i18n/goi18n/merge_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package main - -import ( - "bytes" - "io/ioutil" - "os" - "testing" -) - -func TestMergeExecuteJSON(t *testing.T) { - files := []string{ - "testdata/input/en-us.one.json", - "testdata/input/en-us.two.json", - "testdata/input/fr-fr.json", - "testdata/input/ar-ar.one.json", - "testdata/input/ar-ar.two.json", - } - testMergeExecute(t, files) -} - -func TestMergeExecuteYAML(t *testing.T) { - files := []string{ - "testdata/input/yaml/en-us.one.yaml", - "testdata/input/yaml/en-us.two.json", - "testdata/input/yaml/fr-fr.json", - "testdata/input/yaml/ar-ar.one.json", - "testdata/input/yaml/ar-ar.two.json", - } - testMergeExecute(t, files) -} - -func testMergeExecute(t *testing.T, files []string) { - resetDir(t, "testdata/output") - - mc := &mergeCommand{ - translationFiles: files, - sourceLanguageTag: "en-us", - outdir: "testdata/output", - format: "json", - } - if err := mc.execute(); err != nil { - t.Fatal(err) - } - - expectEqualFiles(t, "testdata/output/en-us.all.json", "testdata/expected/en-us.all.json") - expectEqualFiles(t, "testdata/output/ar-ar.all.json", "testdata/expected/ar-ar.all.json") - expectEqualFiles(t, "testdata/output/fr-fr.all.json", "testdata/expected/fr-fr.all.json") - expectEqualFiles(t, "testdata/output/en-us.untranslated.json", "testdata/expected/en-us.untranslated.json") - expectEqualFiles(t, "testdata/output/ar-ar.untranslated.json", "testdata/expected/ar-ar.untranslated.json") - expectEqualFiles(t, "testdata/output/fr-fr.untranslated.json", "testdata/expected/fr-fr.untranslated.json") -} - -func resetDir(t *testing.T, dir string) { - if err := os.RemoveAll(dir); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(dir, 0777); err != nil { - t.Fatal(err) - } -} - -func expectEqualFiles(t *testing.T, expectedName, actualName string) { - actual, err := ioutil.ReadFile(actualName) - if err != nil { - t.Fatal(err) - } - expected, err := ioutil.ReadFile(expectedName) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(actual, expected) { - t.Fatalf("contents of files did not match: %s, %s", expectedName, actualName) - } -} diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/expected/R.go b/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/expected/R.go new file mode 100644 index 000000000..9b5334a7e --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/expected/R.go @@ -0,0 +1,38 @@ +// DON'T CHANGE THIS FILE MANUALLY +// This file was generated using the command: +// $ goi18n constants + +package R + +// DDays is the identifier for the following localizable string template(s): +// one: "{{.Count}} day" +// other: "{{.Count}} days" +const DDays = "d_days" + +// MyHeightInMeters is the identifier for the following localizable string template(s): +// one: "I am {{.Count}} meter tall." +// other: "I am {{.Count}} meters tall." +const MyHeightInMeters = "my_height_in_meters" + +// PersonGreeting is the identifier for the following localizable string template(s): +// "Hello {{.Person}}" +const PersonGreeting = "person_greeting" + +// PersonUnreadEmailCount is the identifier for the following localizable string template(s): +// one: "{{.Person}} has {{.Count}} unread email." +// other: "{{.Person}} has {{.Count}} unread emails." +const PersonUnreadEmailCount = "person_unread_email_count" + +// PersonUnreadEmailCountTimeframe is the identifier for the following localizable string template(s): +// one: "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}." +// other: "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}." +const PersonUnreadEmailCountTimeframe = "person_unread_email_count_timeframe" + +// ProgramGreeting is the identifier for the following localizable string template(s): +// "Hello world" +const ProgramGreeting = "program_greeting" + +// YourUnreadEmailCount is the identifier for the following localizable string template(s): +// one: "You have {{.Count}} unread email." +// other: "You have {{.Count}} unread emails." +const YourUnreadEmailCount = "your_unread_email_count" diff --git a/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/input/en-us.constants.json b/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/input/en-us.constants.json new file mode 100644 index 000000000..5aedc235a --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/input/en-us.constants.json @@ -0,0 +1,45 @@ +[ + { + "id": "d_days", + "translation": { + "one": "{{.Count}} day", + "other": "{{.Count}} days" + } + }, + { + "id": "my_height_in_meters", + "translation": { + "one": "I am {{.Count}} meter tall.", + "other": "I am {{.Count}} meters tall." + } + }, + { + "id": "person_greeting", + "translation": "Hello {{.Person}}" + }, + { + "id": "person_unread_email_count", + "translation": { + "one": "{{.Person}} has {{.Count}} unread email.", + "other": "{{.Person}} has {{.Count}} unread emails." + } + }, + { + "id": "person_unread_email_count_timeframe", + "translation": { + "one": "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.", + "other": "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}." + } + }, + { + "id": "program_greeting", + "translation": "Hello world" + }, + { + "id": "your_unread_email_count", + "translation": { + "one": "You have {{.Count}} unread email.", + "other": "You have {{.Count}} unread emails." + } + } +] \ No newline at end of file -- cgit v1.2.3-1-g7c22