diff options
Diffstat (limited to 'vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go')
-rw-r--r-- | vendor/github.com/nicksnyder/go-i18n/goi18n/goi18n.go | 95 |
1 files changed, 34 insertions, 61 deletions
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) - } -} |