update module to own version
This commit is contained in:
38
locale.go
38
locale.go
@@ -21,10 +21,10 @@ multiple languages at the same time by working with this object.
|
||||
Example:
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||
"encoding/gob"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -42,7 +42,7 @@ Example:
|
||||
|
||||
// Translate text from domain
|
||||
fmt.Println(l.GetD("extras", "Translate this"))
|
||||
}
|
||||
}
|
||||
*/
|
||||
type Locale struct {
|
||||
// Path to locale files.
|
||||
@@ -71,29 +71,49 @@ func NewLocale(p, l string) *Locale {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Locale) SetLang(lang string) {
|
||||
l.lang = lang
|
||||
}
|
||||
|
||||
func (l *Locale) SetPath(path string) {
|
||||
l.path = path
|
||||
}
|
||||
|
||||
func (l *Locale) findExt(dom, ext string) string {
|
||||
filename := filepath.Join(l.path, l.lang, "LC_MESSAGES", dom+"."+ext)
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
_, err := os.Stat(filename)
|
||||
if err == nil {
|
||||
return filename
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
|
||||
if len(l.lang) > 2 {
|
||||
filename = filepath.Join(l.path, l.lang[:2], "LC_MESSAGES", dom+"."+ext)
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
_, err = os.Stat(filename)
|
||||
if err == nil {
|
||||
return filename
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
}
|
||||
|
||||
filename = filepath.Join(l.path, l.lang, dom+"."+ext)
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
_, err = os.Stat(filename)
|
||||
if err == nil {
|
||||
return filename
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
|
||||
if len(l.lang) > 2 {
|
||||
filename = filepath.Join(l.path, l.lang[:2], dom+"."+ext)
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
_, err = os.Stat(filename)
|
||||
if err == nil {
|
||||
return filename
|
||||
}
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user