catch unsupported function calls
This commit is contained in:
@@ -35,6 +35,10 @@ func main() {
|
||||
// same as before
|
||||
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
|
||||
|
||||
// unsupported function call
|
||||
trStr := "some string to translate"
|
||||
fmt.Println(gotext.Get(trStr))
|
||||
|
||||
// same with alias package name
|
||||
fmt.Println(alias.Get("alias call"))
|
||||
|
||||
|
||||
@@ -240,14 +240,30 @@ func (g *GoFile) parseGetter(def GetterDef, args []*ast.BasicLit, pos string) {
|
||||
domain, _ = strconv.Unquote(args[def.Domain].Value)
|
||||
}
|
||||
|
||||
// only handle function calls with strings as ID
|
||||
if args[def.Id] == nil || args[def.Id].Kind != token.STRING {
|
||||
log.Printf("ERR: Unsupported call at %s (ID not a string)", pos)
|
||||
return
|
||||
}
|
||||
|
||||
trans := Translation{
|
||||
MsgId: args[def.Id].Value,
|
||||
SourceLocations: []string{pos},
|
||||
}
|
||||
if def.Plural > 0 {
|
||||
// plural ID must be a string
|
||||
if args[def.Plural] == nil || args[def.Plural].Kind != token.STRING {
|
||||
log.Printf("ERR: Unsupported call at %s (Plural not a string)", pos)
|
||||
return
|
||||
}
|
||||
trans.MsgIdPlural = args[def.Plural].Value
|
||||
}
|
||||
if def.Context > 0 {
|
||||
// Context must be a string
|
||||
if args[def.Context] == nil || args[def.Context].Kind != token.STRING {
|
||||
log.Printf("ERR: Unsupported call at %s (Context not a string)", pos)
|
||||
return
|
||||
}
|
||||
trans.Context = args[def.Context].Value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user