From c2fcbba59be09e424704abd43c86e61f0b4cfbd8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 06:51:01 +0000 Subject: [PATCH] chore(deps): bump github.com/leonelquinteros/gotext from 1.6.1 to 1.7.0 Bumps [github.com/leonelquinteros/gotext](https://github.com/leonelquinteros/gotext) from 1.6.1 to 1.7.0. - [Release notes](https://github.com/leonelquinteros/gotext/releases) - [Commits](https://github.com/leonelquinteros/gotext/compare/v1.6.1...v1.7.0) --- updated-dependencies: - dependency-name: github.com/leonelquinteros/gotext dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../leonelquinteros/gotext/domain.go | 95 ++++++++++++++++++- .../leonelquinteros/gotext/gotext.go | 31 +++--- .../leonelquinteros/gotext/helper.go | 12 ++- .../leonelquinteros/gotext/locale.go | 47 +++++---- .../github.com/leonelquinteros/gotext/mo.go | 19 +++- .../github.com/leonelquinteros/gotext/po.go | 21 +++- .../leonelquinteros/gotext/translator.go | 9 +- vendor/modules.txt | 4 +- 10 files changed, 190 insertions(+), 54 deletions(-) diff --git a/go.mod b/go.mod index a8deff364..a15877049 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( github.com/jinzhu/now v1.1.5 github.com/justinas/alice v1.2.0 github.com/kovidgoyal/imaging v1.6.3 - github.com/leonelquinteros/gotext v1.6.1 + github.com/leonelquinteros/gotext v1.7.0 github.com/libregraph/idm v0.5.0 github.com/libregraph/lico v0.64.0 github.com/mitchellh/mapstructure v1.5.0 diff --git a/go.sum b/go.sum index a3b36e5f6..20dc624dd 100644 --- a/go.sum +++ b/go.sum @@ -778,8 +778,8 @@ github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvf github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= -github.com/leonelquinteros/gotext v1.6.1 h1:PuTN8YUqHvfPZxW+fPXp7o0Fc2zN9L2wXBZrqT5MO5A= -github.com/leonelquinteros/gotext v1.6.1/go.mod h1:qQRISjoonXYFdRGrTG1LARQ38Gpibad0IPeB4hpvyyM= +github.com/leonelquinteros/gotext v1.7.0 h1:jcJmF4AXqyamP7vuw2MMIKs+O3jAEmvrc5JQiI8Ht/8= +github.com/leonelquinteros/gotext v1.7.0/go.mod h1:qJdoQuERPpccw7L70uoU+K/BvTfRBHYsisCQyFLXyvw= github.com/libregraph/idm v0.5.0 h1:tDMwKbAOZzdeDYMxVlY5PbSqRKO7dbAW9KT42A51WSk= github.com/libregraph/idm v0.5.0/go.mod h1:BGMwIQ/6orJSPVzJ1x6kgG2JyG9GY05YFmbsnaD80k0= github.com/libregraph/lico v0.64.0 h1:fbMV2ALjrOysGL0m58bhRrF+9e/HCL5RkoSwMN+xoWQ= diff --git a/vendor/github.com/leonelquinteros/gotext/domain.go b/vendor/github.com/leonelquinteros/gotext/domain.go index 110c1b3f1..9427e36f4 100644 --- a/vendor/github.com/leonelquinteros/gotext/domain.go +++ b/vendor/github.com/leonelquinteros/gotext/domain.go @@ -45,6 +45,8 @@ type Domain struct { trBuffer *Translation ctxBuffer string refBuffer string + + customPluralResolver func(int) int } // Preserve MIMEHeader behaviour, without the canonicalisation @@ -88,6 +90,10 @@ func NewDomain() *Domain { return domain } +func (do *Domain) SetPluralResolver(f func(int) int) { + do.customPluralResolver = f +} + func (do *Domain) pluralForm(n int) int { // do we really need locking here? not sure how this plurals.Expression works, so sticking with it for now do.pluralMutex.RLock() @@ -95,6 +101,10 @@ func (do *Domain) pluralForm(n int) int { // Failure fallback if do.pluralforms == nil { + if do.customPluralResolver != nil { + return do.customPluralResolver(n) + } + /* Use the Germanic plural rule. */ if n == 1 { return 0 @@ -261,6 +271,21 @@ func (do *Domain) Get(str string, vars ...interface{}) string { return Printf(str, vars...) } +func (do *Domain) Append(b []byte, str string, vars ...interface{}) []byte { + // Sync read + do.trMutex.RLock() + defer do.trMutex.RUnlock() + + if do.translations != nil { + if _, ok := do.translations[str]; ok { + return Appendf(b, do.translations[str].Get(), vars...) + } + } + + // Return the same we received by default + return Appendf(b, str, vars...) +} + // Set the (N)th plural form for the given string func (do *Domain) SetN(id, plural string, n int, str string) { // Get plural form _before_ lock down @@ -302,6 +327,26 @@ func (do *Domain) GetN(str, plural string, n int, vars ...interface{}) string { return Printf(plural, vars...) } +// GetN retrieves the (N)th plural form of Translation for the given string. +// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. +func (do *Domain) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte { + // Sync read + do.trMutex.RLock() + defer do.trMutex.RUnlock() + + if do.translations != nil { + if _, ok := do.translations[str]; ok { + return Appendf(b, do.translations[str].GetN(do.pluralForm(n)), vars...) + } + } + + // Parse plural forms to distinguish between plural and singular + if do.pluralForm(n) == 0 { + return Appendf(b, str, vars...) + } + return Appendf(b, plural, vars...) +} + // Set the translation for the given string in the given context func (do *Domain) SetC(id, ctx, str string) { do.trMutex.Lock() @@ -348,6 +393,26 @@ func (do *Domain) GetC(str, ctx string, vars ...interface{}) string { return Printf(str, vars...) } +// AppendC retrieves the corresponding Translation for a given string in the given context. +// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. +func (do *Domain) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte { + do.trMutex.RLock() + defer do.trMutex.RUnlock() + + if do.contextTranslations != nil { + if _, ok := do.contextTranslations[ctx]; ok { + if do.contextTranslations[ctx] != nil { + if _, ok := do.contextTranslations[ctx][str]; ok { + return Appendf(b, do.contextTranslations[ctx][str].Get(), vars...) + } + } + } + } + + // Return the string we received by default + return Appendf(b, str, vars...) +} + // Set the (N)th plural form for the given string in the given context func (do *Domain) SetNC(id, plural, ctx string, n int, str string) { // Get plural form _before_ lock down @@ -399,9 +464,31 @@ func (do *Domain) GetNC(str, plural string, n int, ctx string, vars ...interface return Printf(plural, vars...) } +// AppendNC retrieves the (N)th plural form of Translation for the given string in the given context. +// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. +func (do *Domain) AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte { + do.trMutex.RLock() + defer do.trMutex.RUnlock() + + if do.contextTranslations != nil { + if _, ok := do.contextTranslations[ctx]; ok { + if do.contextTranslations[ctx] != nil { + if _, ok := do.contextTranslations[ctx][str]; ok { + return Appendf(b, do.contextTranslations[ctx][str].GetN(do.pluralForm(n)), vars...) + } + } + } + } + + if n == 1 { + return Appendf(b, str, vars...) + } + return Appendf(b, plural, vars...) +} + // IsTranslated reports whether a string is translated func (do *Domain) IsTranslated(str string) bool { - return do.IsTranslatedN(str, 0) + return do.IsTranslatedN(str, 1) } // IsTranslatedN reports whether a plural string is translated @@ -416,12 +503,12 @@ func (do *Domain) IsTranslatedN(str string, n int) bool { if !ok { return false } - return tr.IsTranslatedN(n) + return tr.IsTranslatedN(do.pluralForm(n)) } // IsTranslatedC reports whether a context string is translated func (do *Domain) IsTranslatedC(str, ctx string) bool { - return do.IsTranslatedNC(str, 0, ctx) + return do.IsTranslatedNC(str, 1, ctx) } // IsTranslatedNC reports whether a plural context string is translated @@ -440,7 +527,7 @@ func (do *Domain) IsTranslatedNC(str string, n int, ctx string) bool { if !ok { return false } - return tr.IsTranslatedN(n) + return tr.IsTranslatedN(do.pluralForm(n)) } // GetTranslations returns a copy of every translation in the domain. It does not support contexts. diff --git a/vendor/github.com/leonelquinteros/gotext/gotext.go b/vendor/github.com/leonelquinteros/gotext/gotext.go index e56be5128..d8535204c 100644 --- a/vendor/github.com/leonelquinteros/gotext/gotext.go +++ b/vendor/github.com/leonelquinteros/gotext/gotext.go @@ -3,22 +3,21 @@ Package gotext implements GNU gettext utilities. For quick/simple translations you can use the package level functions directly. - import ( - "fmt" - "github.com/leonelquinteros/gotext" - ) + import ( + "fmt" + "github.com/leonelquinteros/gotext" + ) - func main() { - // Configure package - gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name") + func main() { + // Configure package + gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name") - // Translate text from default domain - fmt.Println(gotext.Get("My text on 'domain-name' domain")) - - // Translate text from a different domain without reconfigure - fmt.Println(gotext.GetD("domain2", "Another text on a different domain")) - } + // Translate text from default domain + fmt.Println(gotext.Get("My text on 'domain-name' domain")) + // Translate text from a different domain without reconfigure + fmt.Println(gotext.GetD("domain2", "Another text on a different domain")) + } */ package gotext @@ -342,7 +341,7 @@ func GetNDC(dom, str, plural string, n int, ctx string, vars ...interface{}) str // IsTranslated reports whether a string is translated in given languages. // When the langs argument is omitted, the output of GetLanguages is used. func IsTranslated(str string, langs ...string) bool { - return IsTranslatedND(GetDomain(), str, 0, langs...) + return IsTranslatedND(GetDomain(), str, 1, langs...) } // IsTranslatedN reports whether a plural string is translated in given languages. @@ -354,7 +353,7 @@ func IsTranslatedN(str string, n int, langs ...string) bool { // IsTranslatedD reports whether a domain string is translated in given languages. // When the langs argument is omitted, the output of GetLanguages is used. func IsTranslatedD(dom, str string, langs ...string) bool { - return IsTranslatedND(dom, str, 0, langs...) + return IsTranslatedND(dom, str, 1, langs...) } // IsTranslatedND reports whether a plural domain string is translated in any of given languages. @@ -385,7 +384,7 @@ func IsTranslatedND(dom, str string, n int, langs ...string) bool { // IsTranslatedC reports whether a context string is translated in given languages. // When the langs argument is omitted, the output of GetLanguages is used. func IsTranslatedC(str, ctx string, langs ...string) bool { - return IsTranslatedNDC(GetDomain(), str, 0, ctx, langs...) + return IsTranslatedNDC(GetDomain(), str, 1, ctx, langs...) } // IsTranslatedNC reports whether a plural context string is translated in given languages. diff --git a/vendor/github.com/leonelquinteros/gotext/helper.go b/vendor/github.com/leonelquinteros/gotext/helper.go index ba1b62c33..ce68e7539 100644 --- a/vendor/github.com/leonelquinteros/gotext/helper.go +++ b/vendor/github.com/leonelquinteros/gotext/helper.go @@ -37,6 +37,15 @@ func Printf(str string, vars ...interface{}) string { return str } +// Appendf applies text formatting only when needed to parse variables. +func Appendf(b []byte, str string, vars ...interface{}) []byte { + if len(vars) > 0 { + return fmt.Appendf(b, str, vars...) + } + + return append(b, str...) +} + // NPrintf support named format // NPrintf("%(name)s is Type %(type)s", map[string]interface{}{"name": "Gotext", "type": "struct"}) func NPrintf(format string, params map[string]interface{}) { @@ -45,7 +54,8 @@ func NPrintf(format string, params map[string]interface{}) { } // Sprintf support named format -// Sprintf("%(name)s is Type %(type)s", map[string]interface{}{"name": "Gotext", "type": "struct"}) +// +// Sprintf("%(name)s is Type %(type)s", map[string]interface{}{"name": "Gotext", "type": "struct"}) func Sprintf(format string, params map[string]interface{}) string { f, p := parseSprintf(format, params) return fmt.Sprintf(f, p...) diff --git a/vendor/github.com/leonelquinteros/gotext/locale.go b/vendor/github.com/leonelquinteros/gotext/locale.go index ac204dddc..01c2a1fa1 100644 --- a/vendor/github.com/leonelquinteros/gotext/locale.go +++ b/vendor/github.com/leonelquinteros/gotext/locale.go @@ -21,30 +21,29 @@ multiple languages at the same time by working with this object. Example: - import ( - "encoding/gob" - "bytes" - "fmt" - "github.com/leonelquinteros/gotext" - ) + import ( + "encoding/gob" + "bytes" + "fmt" + "github.com/leonelquinteros/gotext" + ) - func main() { - // Create Locale with library path and language code - l := gotext.NewLocale("/path/to/i18n/dir", "en_US") + func main() { + // Create Locale with library path and language code + l := gotext.NewLocale("/path/to/i18n/dir", "en_US") - // Load domain '/path/to/i18n/dir/en_US/LC_MESSAGES/default.{po,mo}' - l.AddDomain("default") + // Load domain '/path/to/i18n/dir/en_US/LC_MESSAGES/default.{po,mo}' + l.AddDomain("default") - // Translate text from default domain - fmt.Println(l.Get("Translate this")) + // Translate text from default domain + fmt.Println(l.Get("Translate this")) - // Load different domain ('/path/to/i18n/dir/en_US/LC_MESSAGES/extras.{po,mo}') - l.AddDomain("extras") - - // Translate text from domain - fmt.Println(l.GetD("extras", "Translate this")) - } + // Load different domain ('/path/to/i18n/dir/en_US/LC_MESSAGES/extras.{po,mo}') + l.AddDomain("extras") + // Translate text from domain + fmt.Println(l.GetD("extras", "Translate this")) + } */ type Locale struct { // Path to locale files. @@ -83,6 +82,14 @@ func NewLocaleFS(l string, filesystem fs.FS) *Locale { return loc } +// NewLocaleFSWithPath returns a Locale working with a fs.FS on a p path folder. +func NewLocaleFSWithPath(l string, filesystem fs.FS, p string) *Locale { + loc := NewLocale("", l) + loc.fs = filesystem + loc.path = p + return loc +} + func (l *Locale) findExt(dom, ext string) string { filename := path.Join(l.path, l.lang, "LC_MESSAGES", dom+"."+ext) if l.fileExists(filename) { @@ -333,7 +340,7 @@ func (l *Locale) GetNDC(dom, str, plural string, n int, ctx string, vars ...inte return Printf(plural, vars...) } -//GetTranslations returns a copy of all translations in all domains of this locale. It does not support contexts. +// GetTranslations returns a copy of all translations in all domains of this locale. It does not support contexts. func (l *Locale) GetTranslations() map[string]*Translation { all := make(map[string]*Translation) diff --git a/vendor/github.com/leonelquinteros/gotext/mo.go b/vendor/github.com/leonelquinteros/gotext/mo.go index e80998d71..dfad57627 100644 --- a/vendor/github.com/leonelquinteros/gotext/mo.go +++ b/vendor/github.com/leonelquinteros/gotext/mo.go @@ -45,10 +45,9 @@ Example: // Get Translation fmt.Println(mo.Get("Translate this")) } - */ type Mo struct { - //these three public members are for backwards compatibility. they are just set to the value in the domain + // these three public members are for backwards compatibility. they are just set to the value in the domain Headers HeaderMap Language string PluralForms string @@ -56,7 +55,7 @@ type Mo struct { fs fs.FS } -//NewMo should always be used to instantiate a new Mo object +// NewMo should always be used to instantiate a new Mo object func NewMo() *Mo { mo := new(Mo) mo.domain = NewDomain() @@ -75,22 +74,34 @@ func (mo *Mo) GetDomain() *Domain { return mo.domain } -//all of the Get functions are for convenience and aid in backwards compatibility +// all of the Get functions are for convenience and aid in backwards compatibility func (mo *Mo) Get(str string, vars ...interface{}) string { return mo.domain.Get(str, vars...) } +func (mo *Mo) Append(b []byte, str string, vars ...interface{}) []byte { + return mo.domain.Append(b, str, vars...) +} func (mo *Mo) GetN(str, plural string, n int, vars ...interface{}) string { return mo.domain.GetN(str, plural, n, vars...) } +func (mo *Mo) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte { + return mo.domain.AppendN(b, str, plural, n, vars...) +} func (mo *Mo) GetC(str, ctx string, vars ...interface{}) string { return mo.domain.GetC(str, ctx, vars...) } +func (mo *Mo) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte { + return mo.domain.AppendC(b, str, ctx, vars...) +} func (mo *Mo) GetNC(str, plural string, n int, ctx string, vars ...interface{}) string { return mo.domain.GetNC(str, plural, n, ctx, vars...) } +func (mo *Mo) AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte { + return mo.domain.AppendNC(b, str, plural, n, ctx, vars...) +} func (mo *Mo) IsTranslated(str string) bool { return mo.domain.IsTranslated(str) diff --git a/vendor/github.com/leonelquinteros/gotext/po.go b/vendor/github.com/leonelquinteros/gotext/po.go index a7d656d3e..ca5937dca 100644 --- a/vendor/github.com/leonelquinteros/gotext/po.go +++ b/vendor/github.com/leonelquinteros/gotext/po.go @@ -33,10 +33,9 @@ Example: // Get Translation fmt.Println(po.Get("Translate this")) } - */ type Po struct { - //these three public members are for backwards compatibility. they are just set to the value in the domain + // these three public members are for backwards compatibility. they are just set to the value in the domain Headers HeaderMap Language string PluralForms string @@ -55,7 +54,7 @@ const ( msgStr ) -//NewPo should always be used to instantiate a new Po object +// NewPo should always be used to instantiate a new Po object func NewPo() *Po { po := new(Po) po.domain = NewDomain() @@ -86,12 +85,19 @@ func (po *Po) GetRefs(str string) []string { return po.domain.GetRefs(str) } +func (po *Po) SetPluralResolver(f func(int) int) { + po.domain.customPluralResolver = f +} + func (po *Po) Set(id, str string) { po.domain.Set(id, str) } func (po *Po) Get(str string, vars ...interface{}) string { return po.domain.Get(str, vars...) } +func (po *Po) Append(b []byte, str string, vars ...interface{}) []byte { + return po.domain.Append(b, str, vars...) +} func (po *Po) SetN(id, plural string, n int, str string) { po.domain.SetN(id, plural, n, str) @@ -99,6 +105,9 @@ func (po *Po) SetN(id, plural string, n int, str string) { func (po *Po) GetN(str, plural string, n int, vars ...interface{}) string { return po.domain.GetN(str, plural, n, vars...) } +func (po *Po) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte { + return po.domain.AppendN(b, str, plural, n, vars...) +} func (po *Po) SetC(id, ctx, str string) { po.domain.SetC(id, ctx, str) @@ -106,6 +115,9 @@ func (po *Po) SetC(id, ctx, str string) { func (po *Po) GetC(str, ctx string, vars ...interface{}) string { return po.domain.GetC(str, ctx, vars...) } +func (po *Po) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte { + return po.domain.AppendC(b, str, ctx, vars...) +} func (po *Po) SetNC(id, plural, ctx string, n int, str string) { po.domain.SetNC(id, plural, ctx, n, str) @@ -113,6 +125,9 @@ func (po *Po) SetNC(id, plural, ctx string, n int, str string) { func (po *Po) GetNC(str, plural string, n int, ctx string, vars ...interface{}) string { return po.domain.GetNC(str, plural, n, ctx, vars...) } +func (po *Po) AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte { + return po.domain.AppendNC(b, str, plural, n, ctx, vars...) +} func (po *Po) IsTranslated(str string) bool { return po.domain.IsTranslated(str) diff --git a/vendor/github.com/leonelquinteros/gotext/translator.go b/vendor/github.com/leonelquinteros/gotext/translator.go index a53776d52..7a0dbd5bb 100644 --- a/vendor/github.com/leonelquinteros/gotext/translator.go +++ b/vendor/github.com/leonelquinteros/gotext/translator.go @@ -27,6 +27,13 @@ type Translator interface { UnmarshalBinary([]byte) error GetDomain() *Domain } +type AppendTranslator interface { + Translator + Append(b []byte, str string, vars ...interface{}) []byte + AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte + AppendC(b []byte, str, ctx string, vars ...interface{}) []byte + AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte +} // TranslatorEncoding is used as intermediary storage to encode Translator objects to Gob. type TranslatorEncoding struct { @@ -66,7 +73,7 @@ func (te *TranslatorEncoding) GetTranslator() Translator { return po } -//getFileData reads a file and returns the byte slice after doing some basic sanity checking +// getFileData reads a file and returns the byte slice after doing some basic sanity checking func getFileData(f string, filesystem fs.FS) ([]byte, error) { if filesystem != nil { return fs.ReadFile(filesystem, f) diff --git a/vendor/modules.txt b/vendor/modules.txt index bbaa7b2a8..babba688a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1284,8 +1284,8 @@ github.com/kovidgoyal/imaging ## explicit; go 1.18 github.com/leodido/go-urn github.com/leodido/go-urn/scim/schema -# github.com/leonelquinteros/gotext v1.6.1 -## explicit; go 1.13 +# github.com/leonelquinteros/gotext v1.7.0 +## explicit; go 1.16 github.com/leonelquinteros/gotext github.com/leonelquinteros/gotext/plurals # github.com/libregraph/idm v0.5.0