From 6b5b4ec6be01824a4d345105d7fb2b296989b040 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Thu, 28 Nov 2024 14:41:12 +0100 Subject: [PATCH] linting --- Context.go | 2 +- Translator.go | 8 +++++--- examples/translation/translation.go | 13 +++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Context.go b/Context.go index 96b7f990..ab9288d3 100644 --- a/Context.go +++ b/Context.go @@ -120,7 +120,7 @@ func (c *GIUContext) SetDirty() { // It does the following: // - adds a string to the FontAtlas // - translates the string with the Translator set in the context -// Not all widgets will use this. Text with user-defined input (e.g. InputText will still use FontAtlas.RegisterString) +// Not all widgets will use this. Text with user-defined input (e.g. InputText will still use FontAtlas.RegisterString). func (c *GIUContext) PrepareString(str string) string { str = c.Translator.Translate(str) return c.FontAtlas.RegisterString(str) diff --git a/Translator.go b/Translator.go index d389f25a..9f1a379a 100644 --- a/Translator.go +++ b/Translator.go @@ -16,7 +16,7 @@ type Translator interface { // This will raise a panic if t is nil. // Note that using translator will change labels of widgets, // so this might affect internal imgui's state. -// See also Context.RegisterString +// See also Context.RegisterString. func (c *GIUContext) SetTranslator(t Translator) { Assert(t != nil, "Context", "SetTranslator", "Translator must not be nil.") c.Translator = t @@ -25,13 +25,15 @@ func (c *GIUContext) SetTranslator(t Translator) { var _ Translator = &EmptyTranslator{} // EmptyTranslator is the default one (to save resources). -// It does nothing +// It does nothing. type EmptyTranslator struct{} +// Translate implements Translator interface. func (t *EmptyTranslator) Translate(s string) string { return s } +// SetLanguage implements Translator interface. func (t *EmptyTranslator) SetLanguage(_ string) error { return nil } @@ -70,7 +72,7 @@ func (t *BasicTranslator) Translate(s string) string { return "" } - Assert(t.currentLanguage != "", "BasicTranslator", "Translate", "Current language is not set, so ther is no sense in using BasicTranslator.") + Assert(t.currentLanguage != "", "BasicTranslator", "Translate", "Current language is not set, so there is no sense in using BasicTranslator.") locale, ok := t.source[t.currentLanguage] Assert(ok, "BasicTranslator", "Translate", "There is no language tag %s known by the translator. Did you add it?", t.currentLanguage) diff --git a/examples/translation/translation.go b/examples/translation/translation.go index 2fdd0cd3..6770c52a 100644 --- a/examples/translation/translation.go +++ b/examples/translation/translation.go @@ -1,3 +1,4 @@ +// Package main shows using of translations in giu. package main import "github.com/AllenDang/giu" @@ -15,14 +16,16 @@ var ( }, } - languageCodes = []string{"en", "pl", "de"} - currentLang int32 = 0 + languageCodes = []string{"en", "pl", "de"} + currentLang int32 ) func loop() { giu.SingleWindow().Layout( giu.Combo("Select language", languageCodes[currentLang], languageCodes, ¤tLang).OnChange(func() { - giu.Context.Translator.SetLanguage(languageCodes[currentLang]) + if err := giu.Context.Translator.SetLanguage(languageCodes[currentLang]); err != nil { + panic(err) + } }), giu.Label("Hello world!"), ) @@ -36,7 +39,9 @@ func main() { translator.AddLanguage(k, v) } - translator.SetLanguage(languageCodes[currentLang]) + if err := translator.SetLanguage(languageCodes[currentLang]); err != nil { + panic(err) + } giu.Context.SetTranslator(translator)