Add a printer.Print to internal/locale/printer.go

No need to use variadic functions with string format interpolation
to generate static strings.
This commit is contained in:
jvoisin 2024-02-27 16:54:34 +01:00 committed by Frédéric Guillot
parent 57476f4d59
commit b4ed17fbac
1 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,15 @@ type Printer struct {
language string
}
func (p *Printer) Print(key string) string {
if str, ok := defaultCatalog[p.language][key]; ok {
if translation, ok := str.(string); ok {
return translation
}
}
return key
}
// Printf is like fmt.Printf, but using language-specific formatting.
func (p *Printer) Printf(key string, args ...interface{}) string {
var translation string