Skip to content
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.sw?
.idea
.vagrant
28 changes: 22 additions & 6 deletions go-xgettext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"sort"
"strings"
"time"
"path/filepath"
)

var (
Expand Down Expand Up @@ -76,7 +77,7 @@ type keywordDef struct {

type keywords map[string]*keywordDef

type allKeywordsConfig []*keywordDef
// type allKeywordsConfig []*keywordDef

type msgID struct {
msgidPlural string
Expand Down Expand Up @@ -153,7 +154,7 @@ func constructValue(val interface{}) (string, error) {
return "", err
}
// strip left " (or `)
right = right[1:len(right)]
right = right[1:]
return left + right, nil
default:
return "", fmt.Errorf("unknown type: %v", val)
Expand Down Expand Up @@ -267,8 +268,18 @@ func processFiles(args []string) error {

fset := token.NewFileSet()
for _, fname := range args {
if err := processSingleGoSource(fset, fname); err != nil {
return err
if _, err := os.Stat(fname); err==nil {
if err := processSingleGoSource(fset, fname); err != nil {
return err
}
} else {
if fnames , err := filepath.Glob(fname); err == nil {
for _, fname := range fnames {
if err := processSingleGoSource(fset, fname); err != nil {
return err
}
}
}
}
}

Expand Down Expand Up @@ -305,6 +316,11 @@ func parseKeywords() (keywords, error) {
Name: *keywordContextual,
SkipArgs: *skipArgs,
}
k[*keywordPluralContextual] = &keywordDef{
Type: kTypePluralContextual,
Name: *keywordPluralContextual,
SkipArgs: *skipArgs,
}
}
return k, nil
}
Expand Down Expand Up @@ -361,7 +377,7 @@ msgstr "Project-Id-Version: %s\n"
fmt.Fprintf(out, "%s", header)

// yes, this is the way to do it in go
sortedKeys := []string{}
var sortedKeys []string
for k := range msgIDs {
sortedKeys = append(sortedKeys, k)
}
Expand Down Expand Up @@ -415,7 +431,7 @@ func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
fmt.Println("Usage: go-xgettext [options] file1 ...")
fmt.Println("Usage: go-xgettext [options] file1 file2 fileGlobPattern...")
fmt.Println("Options:")
flag.PrintDefaults()
os.Exit(0)
Expand Down
28 changes: 14 additions & 14 deletions go-xgettext/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func main() {
c.Assert(err, IsNil)

c.Assert(msgIDs, DeepEquals, map[string][]msgID{
"foo": []msgID{
"foo": {
{
comment: "#. TRANSLATORS: foo comment\n",
fname: fname,
Expand All @@ -124,7 +124,7 @@ func main() {
c.Assert(err, IsNil)

c.Assert(msgIDs, DeepEquals, map[string][]msgID{
"foo": []msgID{
"foo": {
{
comment: "#. TRANSLATORS: foo comment\n",
fname: fname,
Expand Down Expand Up @@ -160,7 +160,7 @@ msgstr "Project-Id-Version: snappy\n"

func (s *xgettextTestSuite) TestWriteOutputSimple(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
fname: "fname",
line: 2,
Expand All @@ -183,7 +183,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputMultiple(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
fname: "fname",
line: 2,
Expand Down Expand Up @@ -212,7 +212,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputNoComment(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
fname: "fname",
line: 2,
Expand All @@ -233,7 +233,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputNoLocation(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
fname: "fname",
line: 2,
Expand All @@ -255,7 +255,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputFormatHint(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
fname: "fname",
line: 2,
Expand All @@ -279,7 +279,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputPlural(c *C) {
msgIDs = map[string][]msgID{
"foo": []msgID{
"foo": {
{
msgidPlural: "plural",
fname: "fname",
Expand All @@ -304,13 +304,13 @@ msgstr[1] ""

func (s *xgettextTestSuite) TestWriteOutputSorted(c *C) {
msgIDs = map[string][]msgID{
"aaa": []msgID{
"aaa": {
{
fname: "fname",
line: 2,
},
},
"zzz": []msgID{
"zzz": {
{
fname: "fname",
line: 2,
Expand Down Expand Up @@ -411,7 +411,7 @@ func main() {
c.Assert(err, IsNil)

c.Assert(msgIDs, DeepEquals, map[string][]msgID{
"foo\\nbar\\nbaz": []msgID{
"foo\\nbar\\nbaz": {
{
comment: "#. TRANSLATORS: foo comment\n",
fname: fname,
Expand Down Expand Up @@ -446,7 +446,7 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputMultilines(c *C) {
msgIDs = map[string][]msgID{
"foo\\nbar\\nbaz": []msgID{
"foo\\nbar\\nbaz": {
{
fname: "fname",
line: 2,
Expand All @@ -470,13 +470,13 @@ msgstr ""

func (s *xgettextTestSuite) TestWriteOutputTidy(c *C) {
msgIDs = map[string][]msgID{
"foo\\nbar\\nbaz": []msgID{
"foo\\nbar\\nbaz": {
{
fname: "fname",
line: 2,
},
},
"zzz\\n": []msgID{
"zzz\\n": {
{
fname: "fname",
line: 4,
Expand Down