aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gotext.go105
-rw-r--r--tests/gotext.go52
2 files changed, 24 insertions, 133 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
diff --git a/tests/gotext.go b/tests/gotext.go
index e679bda..3c097c8 100644
--- a/tests/gotext.go
+++ b/tests/gotext.go
@@ -98,7 +98,6 @@ func test_processFiles() {
g.Testing("process files with concat", func() {
msgIDs = nil
- opts.NoLocation = true
fname := src(g.Heredoc(`
package main
@@ -108,7 +107,6 @@ func test_processFiles() {
}
`))
g.TErrorIf(processFiles([]string{fname}))
- opts.NoLocation = false
g.TAssertEqual(msgIDs, map[string][]msgID{
"foo\\nbar\\nbaz": []msgID{
@@ -263,10 +261,8 @@ func test_writePotFile() {
},
}
- opts.NoLocation = true
out := bytes.NewBuffer([]byte(""))
writePotFile(out)
- opts.NoLocation = false
expected := g.Heredoc(`
#, fuzzy
@@ -277,6 +273,7 @@ func test_writePotFile() {
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
+ #: fname:2
msgid "foo"
msgstr ""
@@ -349,53 +346,6 @@ func test_writePotFile() {
g.TAssertEqual(out.String(), expected)
})
- g.Testing("sorted output", func() {
- msgIDs = map[string][]msgID{
- "aaa": []msgID{
- {
- fname: "fname",
- line: 2,
- },
- },
- "zzz": []msgID{
- {
- fname: "fname",
- line: 2,
- },
- },
- }
-
- opts.SortOutput = true
- // we need to run this a bunch of times as the ordering might
- // be right by pure chance
- // FIXME
- for i := 0; i < 10; i++ {
- out := bytes.NewBuffer([]byte(""))
- writePotFile(out)
-
- expected := g.Heredoc(`
- #, fuzzy
- msgid ""
- msgstr ""
- "Language: \n"
- "MIME-Version: 1.0\n"
- "Content-Type: text/plain; charset=UTF-8\n"
- "Content-Transfer-Encoding: 8bit\n"
-
- #: fname:2
- msgid "aaa"
- msgstr ""
-
- #: fname:2
- msgid "zzz"
- msgstr ""
-
- `)
- g.TAssertEqual(out.String(), expected)
- }
- opts.SortOutput = false
- })
-
g.Testing("multiline output", func() {
msgIDs = map[string][]msgID{
"foo\\nbar\\nbaz": []msgID{