Skip to content

Commit 275c8ec

Browse files
ksegunnicksnyder
authored andcommitted
fix(goi18n): could not extract constant message id (#202)
1 parent 3f2fe62 commit 275c8ec

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

v2/goi18n/extract_command.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ func extractStringLiteral(expr ast.Expr) (string, bool) {
258258
return "", false
259259
}
260260
return x + y, true
261+
case *ast.Ident:
262+
switch z := v.Obj.Decl.(type) {
263+
case *ast.ValueSpec:
264+
s, ok := extractStringLiteral(z.Values[0])
265+
if !ok {
266+
return "", false
267+
}
268+
return s, true
269+
}
270+
return "", false
261271
default:
262272
return "", false
263273
}

v2/goi18n/extract_command_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@ zero = "Zero translation"
185185
}
186186
`,
187187
},
188+
{
189+
name: "global declaration",
190+
fileName: "file.go",
191+
file: `package main
192+
193+
import "github.com/nicksnyder/go-i18n/v2/i18n"
194+
195+
const constID = "ConstantID"
196+
197+
var m = &i18n.Message{
198+
ID: constID,
199+
Other: "ID is a constant",
200+
}
201+
`,
202+
activeFile: []byte(`ConstantID = "ID is a constant"
203+
`),
204+
},
188205
}
189206

190207
for _, test := range tests {

0 commit comments

Comments
 (0)