From 67d7b9ca6022481596ae1e1a3ac14d6c969591ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Wed, 29 Jul 2020 18:09:14 +0200 Subject: [PATCH] update module to own version --- locale.go | 38 +++++++++++++++++++++++++++++--------- po.go | 4 ++-- translation.go | 4 ++-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/locale.go b/locale.go index fd265f7..6090ccd 100644 --- a/locale.go +++ b/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 "" diff --git a/po.go b/po.go index aaa4f73..5153440 100644 --- a/po.go +++ b/po.go @@ -456,7 +456,7 @@ func (po *Po) GetNC(str, plural string, n int, ctx string, vars ...interface{}) return Printf(plural, vars...) } -// Get Eretrieves the corresponding Translation for the given string. +// GetE retrieves the corresponding Translation for the given string. // Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. // The second return value is true iff the string was found. func (po *Po) GetE(str string, vars ...interface{}) (string, bool) { @@ -475,7 +475,7 @@ func (po *Po) GetE(str string, vars ...interface{}) (string, bool) { return "", false } -// GetN Eretrieves the (N)th plural form of Translation for the given string. +// GetNE 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. // The second return value is true iff the string was found. func (po *Po) GetNE(str, plural string, n int, vars ...interface{}) (string, bool) { diff --git a/translation.go b/translation.go index 539dcc1..51de836 100644 --- a/translation.go +++ b/translation.go @@ -51,7 +51,7 @@ func (t *Translation) GetN(n int) string { return t.PluralID } -// Get returns the string of the translation. The second return value is true +// GetE returns the string of the translation. The second return value is true // iff the string was found. func (t *Translation) GetE() (string, bool) { // Look for Translation index 0 @@ -64,7 +64,7 @@ func (t *Translation) GetE() (string, bool) { return "", false } -// GetN returns the string of the plural translation. The second return value +// GetNE returns the string of the plural translation. The second return value // is true iff the string was found. func (t *Translation) GetNE(n int) (string, bool) { // Look for Translation index