extract.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. package main
  5. import (
  6. "golang.org/x/text/message/pipeline"
  7. )
  8. // TODO:
  9. // - merge information into existing files
  10. // - handle different file formats (PO, XLIFF)
  11. // - handle features (gender, plural)
  12. // - message rewriting
  13. func init() {
  14. lang = cmdExtract.Flag.String("lang", "en-US", "comma-separated list of languages to process")
  15. }
  16. var cmdExtract = &Command{
  17. Run: runExtract,
  18. UsageLine: "extract <package>*",
  19. Short: "extracts strings to be translated from code",
  20. }
  21. func runExtract(cmd *Command, config *pipeline.Config, args []string) error {
  22. config.Packages = args
  23. state, err := pipeline.Extract(config)
  24. if err != nil {
  25. return wrap(err, "extract failed")
  26. }
  27. if err := state.Import(); err != nil {
  28. return wrap(err, "import failed")
  29. }
  30. if err := state.Merge(); err != nil {
  31. return wrap(err, "merge failed")
  32. }
  33. return wrap(state.Export(), "export failed")
  34. }