initial rework of xgotext

This commit is contained in:
Benjamin Böhmke
2020-02-22 22:35:39 +01:00
parent 2b59b30398
commit 75a3d22c53
8 changed files with 525 additions and 336 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"github.com/leonelquinteros/gotext"
alias "github.com/leonelquinteros/gotext"
"github.com/leonelquinteros/gotext/cli/xgotext/fixtures/pkg"
)
// Fake object with methods similar to gotext
@@ -15,12 +17,26 @@ func (f Fake) Get(id int) int {
return 42
}
// Fake object with same methods as gotext
type Fake2 struct {
}
// Get by str
func (f Fake2) Get(s string) string {
return s
}
func main() {
// Configure package
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
// Translate text from default domain
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
// same as before
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
// same with alias package name
fmt.Println(alias.Get("alias call"))
// Translate text from a different domain without reconfigure
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))
@@ -43,6 +59,24 @@ func main() {
l.GetDC("domain2", "string", "ctx")
l.GetNDC("translations", "ndc", "ndcs", 7, "NDC-CTX")
// try fake structs
f := Fake{}
f.Get(3)
f2 := Fake2{}
f2.Get("3")
// use translator of sub object
t := pkg.Translate{}
t.L.Get("translate package")
t.S.L.Get("translate sub package")
// redefine alias with fake struct
alias := Fake2{}
alias.Get("3")
}
// dummy function
func dummy(locale *gotext.Locale) {
locale.Get("inside dummy")
}

View File

@@ -0,0 +1,16 @@
package pkg
import "github.com/leonelquinteros/gotext"
type SubTranslate struct {
L gotext.Locale
}
type Translate struct {
L gotext.Locale
S SubTranslate
}
func test() {
gotext.Get("inside sub package")
}