golang.org/x/text@v0.14.0/cmd/gotext/extract.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 cmdExtract = &Command{ 18 Init: initExtract, 19 Run: runExtract, 20 UsageLine: "extract <package>*", 21 Short: "extracts strings to be translated from code", 22 } 23 24 func initExtract(cmd *Command) { 25 lang = cmd.Flag.String("lang", "en-US", "comma-separated list of languages to process") 26 } 27 28 func runExtract(cmd *Command, config *pipeline.Config, args []string) error { 29 config.Packages = args 30 state, err := pipeline.Extract(config) 31 if err != nil { 32 return wrap(err, "extract failed") 33 } 34 if err := state.Import(); err != nil { 35 return wrap(err, "import failed") 36 } 37 if err := state.Merge(); err != nil { 38 return wrap(err, "merge failed") 39 } 40 return wrap(state.Export(), "export failed") 41 }