diff options
author | ksegun <ksegun@users.noreply.github.com> | 2019-10-13 19:21:32 +0300 |
---|---|---|
committer | Nick Snyder <nickdsnyder@gmail.com> | 2019-10-13 19:21:32 +0300 |
commit | 275c8ecd2b9eb2da0b5efae46e8f3b01c5e5261c (patch) | |
tree | 584c5ac96b89e0bc11a2b58e63269315065057ea | |
parent | 3f2fe621ac72b7d6700da69f1177dcc6d7689108 (diff) |
fix(goi18n): could not extract constant message id (#202)
-rw-r--r-- | v2/goi18n/extract_command.go | 10 | ||||
-rw-r--r-- | v2/goi18n/extract_command_test.go | 17 |
2 files changed, 27 insertions, 0 deletions
diff --git a/v2/goi18n/extract_command.go b/v2/goi18n/extract_command.go index 178a06d..9f46160 100644 --- a/v2/goi18n/extract_command.go +++ b/v2/goi18n/extract_command.go @@ -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 } diff --git a/v2/goi18n/extract_command_test.go b/v2/goi18n/extract_command_test.go index 4aacafa..d5a7efd 100644 --- a/v2/goi18n/extract_command_test.go +++ b/v2/goi18n/extract_command_test.go @@ -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 { |