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:
parent
78c7f66df7
commit
33c648825f
1 changed files with 5 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue