update.go 1.2 KB

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