Skip to content

Commit

Permalink
fix(goi18n): could not extract constant message id (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksegun authored and nicksnyder committed Oct 13, 2019
1 parent 3f2fe62 commit 275c8ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions v2/goi18n/extract_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ func extractStringLiteral(expr ast.Expr) (string, bool) {
return "", false
}
return x + y, true
case *ast.Ident:
switch z := v.Obj.Decl.(type) {
case *ast.ValueSpec:
s, ok := extractStringLiteral(z.Values[0])
if !ok {
return "", false
}
return s, true
}
return "", false
default:
return "", false
}
Expand Down
17 changes: 17 additions & 0 deletions v2/goi18n/extract_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ zero = "Zero translation"
}
`,
},
{
name: "global declaration",
fileName: "file.go",
file: `package main
import "github.com/nicksnyder/go-i18n/v2/i18n"
const constID = "ConstantID"
var m = &i18n.Message{
ID: constID,
Other: "ID is a constant",
}
`,
activeFile: []byte(`ConstantID = "ID is a constant"
`),
},
}

for _, test := range tests {
Expand Down

0 comments on commit 275c8ec

Please sign in to comment.