mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
First commit
This commit is contained in:
commit
8ffb773f43
2121 changed files with 1118910 additions and 0 deletions
47
locale/language.go
Normal file
47
locale/language.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package locale
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Language struct {
|
||||
language string
|
||||
translations Translation
|
||||
}
|
||||
|
||||
func (l *Language) Get(key string, args ...interface{}) string {
|
||||
var translation string
|
||||
|
||||
str, found := l.translations[key]
|
||||
if !found {
|
||||
translation = key
|
||||
} else {
|
||||
translation = str.(string)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(translation, args...)
|
||||
}
|
||||
|
||||
func (l *Language) Plural(key string, n int, args ...interface{}) string {
|
||||
translation := key
|
||||
slices, found := l.translations[key]
|
||||
if found {
|
||||
|
||||
pluralForm, found := pluralForms[l.language]
|
||||
if !found {
|
||||
pluralForm = pluralForms["default"]
|
||||
}
|
||||
|
||||
index := pluralForm(n)
|
||||
translations := slices.([]interface{})
|
||||
translation = key
|
||||
|
||||
if len(translations) > index {
|
||||
translation = translations[index].(string)
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf(translation, args...)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue