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:
Ben Sarah Golightly
2020-07-23 00:28:56 +01:00
parent 3bb41424ff
commit 75a1fb9b04
6 changed files with 326 additions and 4 deletions

View File

@@ -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
}