diff options
Diffstat (limited to 'src/gotext.go')
-rw-r--r-- | src/gotext.go | 105 |
1 files changed, 23 insertions, 82 deletions
diff --git a/src/gotext.go b/src/gotext.go index bfba745..0e61a91 100644 --- a/src/gotext.go +++ b/src/gotext.go @@ -16,7 +16,6 @@ import ( "unsafe" g "gobang" - // "github.com/jessevdk/go-flags" ) @@ -250,30 +249,27 @@ func writePotFile(out io.Writer) { `) fmt.Fprintf(out, "%s", header) + // FIXME: sort by location, not by key // yes, this is the way to do it in go sortedKeys := []string{} for k := range msgIDs { sortedKeys = append(sortedKeys, k) } - if opts.SortOutput { - sort.Strings(sortedKeys) - } + sort.Strings(sortedKeys) // FIXME: use template here? for _, k := range sortedKeys { msgidList := msgIDs[k] for _, msgid := range msgidList { - if opts.AddComments || opts.AddCommentsTag != "" { - fmt.Fprintf(out, "%s", msgid.comment) - } + fmt.Fprintf(out, "%s", msgid.comment) } - if !opts.NoLocation { - fmt.Fprintf(out, "#:") - for _, msgid := range msgidList { - fmt.Fprintf(out, " %s:%d", msgid.fname, msgid.line) - } - fmt.Fprintf(out, "\n") + + fmt.Fprintf(out, "#:") + for _, msgid := range msgidList { + fmt.Fprintf(out, " %s:%d", msgid.fname, msgid.line) } + fmt.Fprintf(out, "\n") + msgid := msgidList[0] if msgid.formatHint != "" { fmt.Fprintf(out, "#, %s\n", msgid.formatHint) @@ -306,38 +302,24 @@ func writePotFile(out io.Writer) { // FIXME: this must be setable via go-flags type optsT struct { - Output string `short:"o" long:"output" description:"output to specified file"` - - AddComments bool `short:"c" long:"add-comments" description:"place all comment blocks preceding keyword lines in output file"` - AddCommentsTag string `long:"add-comments-tag" description:"place comment blocks starting with TAG and prceding keyword lines in output file"` - - SortOutput bool `short:"s" long:"sort-output" description:"generate sorted output"` - - NoLocation bool `long:"no-location" description:"do not write '#: filename:line' lines"` - - MsgIDBugsAddress string `long:"msgid-bugs-address" default:"EMAIL" description:"set report address for msgid bugs"` - - PackageName string `long:"package-name" description:"set package name in output"` - Keyword string `short:"k" long:"keyword" default:"gt.Gettext" description:"look for WORD as the keyword for singular strings"` KeywordPlural string `long:"keyword-plural" default:"gt.NGettext" description:"look for WORD as the keyword for plural strings"` } // FIXME: Remove me var opts = optsT{ - NoLocation: false, AddCommentsTag: "TRANSLATORS:", Keyword: "i18n.G", KeywordPlural: "i18n.NG", - SortOutput: true, - PackageName: "snappy", - MsgIDBugsAddress: "snappy-devel@lists.ubuntu.com", } type argsT struct{ - allArgs []string - subArgs []string + allArgs []string + subArgs []string + commentTag string + keyword string + keywordPlural string } func usage(argv0 string, w io.Writer) { @@ -355,41 +337,11 @@ func getopt(allArgs []string, w io.Writer) (argsT, int) { fs.Usage = func() {} fs.SetOutput(w) - output := fs.String( - "o", - "", - "output to specified file", - ) - addComments := fs.Bool( - "c", - false, - "place all comment blocks preceding keyword lines in output file", - ) - addCommentsTag := fs.String( + commentTag := fs.String( "A", - "", + "TRANSLATORS", "place comment blocks starting with TAG and prceding keyword lines in output file", ) - sortOutput := fs.Bool( - "s", - false, - "generate sorted output", - ) - noLocation := fs.Bool( - "L", - false, - "do not write '#: filename:line' lines", - ) - msgIDBugsAddress := fs.String( - "M", - "EMAIL", - "set report address for msgid bugs", - ) - packageName := fs.String( - "N", - "", - "set package name in output", - ) keyword := fs.String( "k", "gt.Gettext", @@ -407,13 +359,7 @@ func getopt(allArgs []string, w io.Writer) (argsT, int) { } opts = optsT{ - Output: *output, - AddComments: *addComments, - AddCommentsTag: *addCommentsTag, - SortOutput: *sortOutput, - NoLocation: *noLocation, - MsgIDBugsAddress: *msgIDBugsAddress, - PackageName: *packageName, + AddCommentsTag: *commentTag, Keyword: *keyword, KeywordPlural: *keywordPlural, } @@ -421,8 +367,11 @@ func getopt(allArgs []string, w io.Writer) (argsT, int) { subArgs := fs.Args() return argsT{ - allArgs: allArgs, - subArgs: subArgs, + allArgs: allArgs, + subArgs: subArgs, + commentTag: *commentTag, + keyword: *keyword, + keywordPlural: *keywordPlural, }, 0 } @@ -444,15 +393,7 @@ func Main() { log.Fatalf("processFiles failed with: %s", err) } - out := os.Stdout - if opts.Output != "" { - var err error - out, err = os.Create(opts.Output) - if err != nil { - log.Fatalf("failed to create %s: %s", opts.Output, err) - } - } - writePotFile(out) + writePotFile(os.Stdout) } // FIXME: are these comments useful |