github.com/liquid-dev/text@v0.3.3-liquid/cmd/gotext/update.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "github.com/liquid-dev/text/message/pipeline" 9 ) 10 11 // TODO: 12 // - merge information into existing files 13 // - handle different file formats (PO, XLIFF) 14 // - handle features (gender, plural) 15 // - message rewriting 16 17 var ( 18 lang *string 19 out *string 20 ) 21 22 func init() { 23 lang = cmdUpdate.Flag.String("lang", "en-US", "comma-separated list of languages to process") 24 out = cmdUpdate.Flag.String("out", "", "output file to write to") 25 } 26 27 var cmdUpdate = &Command{ 28 Run: runUpdate, 29 UsageLine: "update <package>* [-out <gofile>]", 30 Short: "merge translations and generate catalog", 31 } 32 33 func runUpdate(cmd *Command, config *pipeline.Config, args []string) error { 34 config.Packages = args 35 state, err := pipeline.Extract(config) 36 if err != nil { 37 return wrap(err, "extract failed") 38 } 39 if err := state.Import(); err != nil { 40 return wrap(err, "import failed") 41 } 42 if err := state.Merge(); err != nil { 43 return wrap(err, "merge failed") 44 } 45 if err := state.Export(); err != nil { 46 return wrap(err, "export failed") 47 } 48 if *out != "" { 49 return wrap(state.Generate(), "generation failed") 50 } 51 return nil 52 }