Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Command Line Options for gotext #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/gotext/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// - message rewriting

func init() {
lang = cmdExtract.Flag.String("lang", "en-US", "comma-separated list of languages to process")
cmdExtract.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process")
}

var cmdExtract = &Command{
Expand Down
4 changes: 0 additions & 4 deletions cmd/gotext/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"golang.org/x/text/message/pipeline"
)

func init() {
out = cmdGenerate.Flag.String("out", "", "output file to write to")
}

var cmdGenerate = &Command{
Run: runGenerate,
UsageLine: "generate <package>",
Expand Down
7 changes: 5 additions & 2 deletions cmd/gotext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func init() {
var (
srcLang = flag.String("srclang", "en-US", "the source-code language")
dir = flag.String("dir", "locales", "default subdirectory to store translation files")
lang = "en-US"
out string
)

func config() (*pipeline.Config, error) {
Expand All @@ -46,10 +48,11 @@ func config() (*pipeline.Config, error) {
return nil, wrap(err, "invalid srclang")
}
return &pipeline.Config{
Dir: *dir,
SourceLanguage: tag,
Supported: getLangs(),
TranslationsPattern: `messages\.(.*)\.json`,
GenFile: *out,
GenFile: out,
}, nil
}

Expand Down Expand Up @@ -332,7 +335,7 @@ func help(args []string) {
}

func getLangs() (tags []language.Tag) {
for _, t := range strings.Split(*lang, ",") {
for _, t := range strings.Split(lang, ",") {
if t == "" {
continue
}
Expand Down
11 changes: 3 additions & 8 deletions cmd/gotext/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ import (
// - handle features (gender, plural)
// - message rewriting

var (
lang *string
out *string
)

func init() {
lang = cmdUpdate.Flag.String("lang", "en-US", "comma-separated list of languages to process")
out = cmdUpdate.Flag.String("out", "", "output file to write to")
cmdUpdate.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process")
cmdUpdate.Flag.StringVar(&out, "out", out, "output file to write to")
}

var cmdUpdate = &Command{
Expand All @@ -45,7 +40,7 @@ func runUpdate(cmd *Command, config *pipeline.Config, args []string) error {
if err := state.Export(); err != nil {
return wrap(err, "export failed")
}
if *out != "" {
if out != "" {
return wrap(state.Generate(), "generation failed")
}
return nil
Expand Down