Add variants of Get functions with existence checks
Currently, a translation that doesn't exist just defaults to the passed message ID. It can be helpful to be able to catch these missing cases e.g. to save to a log. This PR implements variants ending in 'E' like GetE, GetNE. This wasn't implemented at the package-level scope, because for quick translations like that the extra flexibility probably isn't needed.
This commit is contained in:
@@ -13,11 +13,17 @@ import "net/textproto"
|
||||
type Translator interface {
|
||||
ParseFile(f string)
|
||||
Parse(buf []byte)
|
||||
|
||||
Get(str string, vars ...interface{}) string
|
||||
GetN(str, plural string, n int, vars ...interface{}) string
|
||||
GetC(str, ctx string, vars ...interface{}) string
|
||||
GetNC(str, plural string, n int, ctx string, vars ...interface{}) string
|
||||
|
||||
GetE(str string, vars ...interface{}) (string, bool)
|
||||
GetNE(str, plural string, n int, vars ...interface{}) (string, bool)
|
||||
GetCE(str, ctx string, vars ...interface{}) (string, bool)
|
||||
GetNCE(str, plural string, n int, ctx string, vars ...interface{}) (string, bool)
|
||||
|
||||
MarshalBinary() ([]byte, error)
|
||||
UnmarshalBinary([]byte) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user