diff --git a/cli/xgotext/fixtures/main.go b/cli/xgotext/fixtures/main.go deleted file mode 100644 index 11588f0..0000000 --- a/cli/xgotext/fixtures/main.go +++ /dev/null @@ -1,105 +0,0 @@ -package main - -import ( - "errors" - "fmt" - - "github.com/donseba/gotext" - alias "github.com/donseba/gotext" - "github.com/donseba/gotext/cli/xgotext/fixtures/pkg" -) - -// Fake object with methods similar to gotext -type Fake struct { -} - -// Get by id -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")) - - // unsupported function call - trStr := "some string to translate" - fmt.Println(gotext.Get(trStr)) - - // same with alias package name - fmt.Println(alias.Get("alias call")) - - // Special strings - fmt.Println(gotext.Get(`string with backquotes`)) - fmt.Println(gotext.Get("string ending with EOL\n")) - fmt.Println(gotext.Get("string with\nmultiple\nEOL")) - fmt.Println(gotext.Get(`raw string with\nmultiple\nEOL`)) - fmt.Println(gotext.Get(`multi -line -string`)) - fmt.Println(gotext.Get(`multi -line -string -ending with -EOL`)) - fmt.Println(gotext.Get("multline\nending with EOL\n")) - - // Translate text from a different domain without reconfigure - fmt.Println(gotext.GetD("domain2", "Another text on a different domain")) - - // Create Locale with library path and language code - l := gotext.NewLocale("/path/to/locales/root/dir", "es_UY") - - // Load domain '/path/to/locales/root/dir/es_UY/default.po' - l.AddDomain("translations") - l.SetDomain("translations") - - // Translate text from domain - fmt.Println(l.GetD("translations", "Translate this")) - - // Get plural translations - l.GetN("Singular", "Plural", 4) - num := 17 - l.GetN("SingularVar", "PluralVar", num) - - 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") - - err := errors.New("test") - fmt.Print(err.Error()) -} - -// dummy function -func dummy(locale *gotext.Locale) { - locale.Get("inside dummy") -} diff --git a/cli/xgotext/fixtures/pkg/pkg.go b/cli/xgotext/fixtures/pkg/pkg.go index 60f6aa8..640351f 100644 --- a/cli/xgotext/fixtures/pkg/pkg.go +++ b/cli/xgotext/fixtures/pkg/pkg.go @@ -10,7 +10,3 @@ type Translate struct { L gotext.Locale S SubTranslate } - -func test() { - gotext.Get("inside sub package") -} diff --git a/cli/xgotext/parser/pkg-tree/golang.go b/cli/xgotext/parser/pkg-tree/golang.go index e9f4c77..4b2ea46 100644 --- a/cli/xgotext/parser/pkg-tree/golang.go +++ b/cli/xgotext/parser/pkg-tree/golang.go @@ -2,6 +2,7 @@ package pkg_tree import ( "fmt" + "github.com/donseba/gotext/cli/xgotext/parser" "go/ast" "go/token" "go/types" @@ -10,9 +11,6 @@ import ( "os" "path/filepath" "strconv" - "strings" - - "github.com/donseba/gotext/cli/xgotext/parser" ) const gotextPkgPath = "github.com/donseba/gotext" @@ -112,13 +110,13 @@ func loadPackage(name string) (*packages.Package, error) { return pkgs[0], nil } -func getPkgPath(pkg *packages.Package) string { - if len(pkg.GoFiles) == 0 { - return pkg.PkgPath - } - pkgPath, _ := filepath.Split(pkg.GoFiles[0]) - return strings.TrimRight(pkgPath, "/") -} +//func getPkgPath(pkg *packages.Package) string { +// if len(pkg.GoFiles) == 0 { +// return pkg.PkgPath +// } +// pkgPath, _ := filepath.Split(pkg.GoFiles[0]) +// return strings.TrimRight(pkgPath, "/") +//} func filterPkgs(pkg *packages.Package) []*packages.Package { result := filterPkgsRec(pkg) @@ -147,7 +145,7 @@ type GoFile struct { data *parser.DomainMap fileSet *token.FileSet - pkgConf *packages.Config + //pkgConf *packages.Config importedPackages map[string]*packages.Package } diff --git a/domain.go b/domain.go index 42fae94..26690c8 100644 --- a/domain.go +++ b/domain.go @@ -572,7 +572,7 @@ func (do *Domain) MarshalText() ([]byte, error) { headerKeys := make([]string, 0, len(do.Headers)) - for k, _ := range do.Headers { + for k := range do.Headers { headerKeys = append(headerKeys, k) } diff --git a/po_test.go b/po_test.go index 9fd602f..b78f603 100644 --- a/po_test.go +++ b/po_test.go @@ -361,7 +361,7 @@ func pluralExpected(t *testing.T, pluralTests []pluralTest, domain *Domain) { for _, pt := range pluralTests { pt := pt t.Run(fmt.Sprintf("pluralForm(%d)", pt.num), func(t *testing.T) { - n := domain.pluralForm(pt.num) + n := domain.PluralForm(pt.num) if n != pt.form { t.Errorf("Expected %d for pluralForm(%d), got %d", pt.form, pt.num, n) } diff --git a/translation.go b/translation.go index 0e15cc0..5d3a993 100644 --- a/translation.go +++ b/translation.go @@ -30,7 +30,7 @@ func NewTranslationWithRefs(refs []string) *Translation { } func (t *Translation) IsStale() bool { - return t.dirty == false + return !t.dirty } func (t *Translation) SetRefs(refs []string) { diff --git a/translator.go b/translator.go index a53776d..0443028 100644 --- a/translator.go +++ b/translator.go @@ -8,7 +8,6 @@ package gotext import ( "errors" "io/fs" - "io/ioutil" "os" ) @@ -83,5 +82,5 @@ func getFileData(f string, filesystem fs.FS) ([]byte, error) { return nil, errors.New("cannot parse a directory") } - return ioutil.ReadFile(f) + return os.ReadFile(f) }