diff options
author | 2024-02-27 16:54:34 +0100 | |
---|---|---|
committer | 2024-02-28 19:24:41 -0800 | |
commit | b4ed17fbac15d71fa379ca463d63c7e36d833fd2 (patch) | |
tree | d94747b877fc8d11dda2d3d1495a751fa831d330 | |
parent | 57476f4d59acb0aea60014c55c573c62ad34780e (diff) | |
download | v2-b4ed17fbac15d71fa379ca463d63c7e36d833fd2.tar.gz v2-b4ed17fbac15d71fa379ca463d63c7e36d833fd2.tar.zst v2-b4ed17fbac15d71fa379ca463d63c7e36d833fd2.zip |
Add a printer.Print to internal/locale/printer.go
No need to use variadic functions with string format interpolation
to generate static strings.
-rw-r--r-- | internal/locale/printer.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/locale/printer.go b/internal/locale/printer.go index b0f5de6c..f85960fa 100644 --- a/internal/locale/printer.go +++ b/internal/locale/printer.go @@ -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 |