golang.org/x/text@v0.14.0/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 "golang.org/x/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 cmdUpdate = &Command{ 18 Init: initUpdate, 19 Run: runUpdate, 20 UsageLine: "update <package>* [-out <gofile>]", 21 Short: "merge translations and generate catalog", 22 } 23 24 func initUpdate(cmd *Command) { 25 lang = cmd.Flag.String("lang", "en-US", "comma-separated list of languages to process") 26 out = cmd.Flag.String("out", "", "output file to write to") 27 } 28 29 func runUpdate(cmd *Command, config *pipeline.Config, args []string) error { 30 config.Packages = args 31 state, err := pipeline.Extract(config) 32 if err != nil { 33 return wrap(err, "extract failed") 34 } 35 if err := state.Import(); err != nil { 36 return wrap(err, "import failed") 37 } 38 if err := state.Merge(); err != nil { 39 return wrap(err, "merge failed") 40 } 41 if err := state.Export(); err != nil { 42 return wrap(err, "export failed") 43 } 44 if *out != "" { 45 return wrap(state.Generate(), "generation failed") 46 } 47 return nil 48 }