1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

refactor(locale): make Printf's code structure similar to Print's

And also change the order of the cases in the Plural function, to make it
explicit that []string shouldn't match []any.
This commit is contained in:
jvoisin 2025-07-06 00:30:09 +02:00 committed by Frédéric Guillot
parent 78c7f66df7
commit 33c648825f

View file

@ -25,12 +25,9 @@ func (p *Printer) Print(key string) string {
func (p *Printer) Printf(key string, args ...any) string {
translation := key
str, found := dict[key]
if found {
var valid bool
translation, valid = str.(string)
if !valid {
if dict, err := getTranslationDict(p.language); err == nil {
if str, ok := dict[key]; ok {
if translation, ok = str.(string); !ok {
translation = key
}
}
@ -50,12 +47,12 @@ func (p *Printer) Plural(key string, n int, args ...interface{}) string {
var plurals []string
switch v := choices.(type) {
case []interface{}:
case []string:
plurals = v
case []any:
for _, v := range v {
plurals = append(plurals, fmt.Sprint(v))
}
case []string:
plurals = v
default:
return key
}