gosexy / gettext Goto Github PK
View Code? Open in Web Editor NEWGolang (Go) bindings for GNU's gettext (http://www.gnu.org/software/gettext/)
License: MIT License
Golang (Go) bindings for GNU's gettext (http://www.gnu.org/software/gettext/)
License: MIT License
The following code causes a panic:
package x
func fn() {
c.client.Get()
}
go-xgettext -o "./pkg/locales/default.pot" --keyword=gotext.Get pkg/file.go
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.Ident
goroutine 1 [running]:
main.inspectNodeForTranslations(0xc000050100, 0xc000072100, 0x56c0c0, 0xc000050140, 0x8)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:163 +0xafd
main.processSingleGoSource.func1(0x56c0c0, 0xc000050140, 0xc00000a540)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:236 +0x47
go/ast.inspector.Visit(0xc00000a240, 0x56c0c0, 0xc000050140, 0x10, 0x54b084)
/usr/local/go/src/go/ast/walk.go:373 +0x3a
go/ast.Walk(0x56bd80, 0xc00000a240, 0x56c0c0, 0xc000050140)
/usr/local/go/src/go/ast/walk.go:52 +0x66
go/ast.Walk(0x56bd80, 0xc00000a240, 0x56c380, 0xc0000465b0)
/usr/local/go/src/go/ast/walk.go:196 +0x1b12
go/ast.walkStmtList(0x56bd80, 0xc00000a240, 0xc0000465c0, 0x1, 0x1)
/usr/local/go/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x56bd80, 0xc00000a240, 0x56c040, 0xc0000605d0)
/usr/local/go/src/go/ast/walk.go:224 +0x1b67
go/ast.Walk(0x56bd80, 0xc00000a240, 0x56c4c0, 0xc000060600)
/usr/local/go/src/go/ast/walk.go:344 +0xd6d
go/ast.walkDeclList(0x56bd80, 0xc00000a240, 0xc0000465d0, 0x1, 0x1)
/usr/local/go/src/go/ast/walk.go:38 +0x9e
go/ast.Walk(0x56bd80, 0xc00000a240, 0x56c440, 0xc000072100)
/usr/local/go/src/go/ast/walk.go:353 +0x2656
go/ast.Inspect(0x56c440, 0xc000072100, 0xc00000a240)
/usr/local/go/src/go/ast/walk.go:385 +0x4b
main.processSingleGoSource(0xc000050100, 0x7fffd2dc037f, 0x28, 0xc00000e140, 0x2)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:235 +0x14e
main.processFiles(0xc00000e150, 0x1, 0x4, 0x5, 0x5)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:215 +0xa8
main.main()
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:344 +0x138
But the following code doesn't cause the panic:
package x
func fn() {
c.client.Update()
}
Hey
With my downstream packaging hat on I'd like to encourage you to tag and release a formal upstream version. This simplifies downstream packaging.
Thank You
ZK
Hi,
I use gosexy in one of my projects and I'm quite happy. One issue I noticed is that xgettext does not extract `` style strings. I created a custom go xgettext for this that uses the golang/ast module and that seems to make the extraction very simple. If thats something you are interessted in I can create a branch and send you a pull request, my current proof-of-concept is at http://bazaar.launchpad.net/~mvo/snappy/snapy-out-own-xgettext/view/head:/i18n/xgettext-go/main.go (but the real version would look a lot nicer :)
Cheers,
Michael
This is really old code and needs to be cleaned up. Better tests, golint, etc.
The following code causes a panic:
package x
func fn() {
Get()
}
go-xgettext -o "./pkg/locales/default.pot" --keyword=gotext.Get pkg/apiserver/controller/site/env_var.go
panic: runtime error: index out of range
goroutine 1 [running]:
main.inspectNodeForTranslations(0xc000050100, 0xc000072100, 0x56c0c0, 0xc000050140, 0x8)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:155 +0xb7b
main.processSingleGoSource.func1(0x56c0c0, 0xc000050140, 0xc00000a4a0)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:236 +0x47
go/ast.inspector.Visit(0xc00000a1a0, 0x56c0c0, 0xc000050140, 0x10, 0x54b084)
/usr/local/go/src/go/ast/walk.go:373 +0x3a
go/ast.Walk(0x56bd80, 0xc00000a1a0, 0x56c0c0, 0xc000050140)
/usr/local/go/src/go/ast/walk.go:52 +0x66
go/ast.Walk(0x56bd80, 0xc00000a1a0, 0x56c380, 0xc000046590)
/usr/local/go/src/go/ast/walk.go:196 +0x1b12
go/ast.walkStmtList(0x56bd80, 0xc00000a1a0, 0xc0000465a0, 0x1, 0x1)
/usr/local/go/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x56bd80, 0xc00000a1a0, 0x56c040, 0xc0000605d0)
/usr/local/go/src/go/ast/walk.go:224 +0x1b67
go/ast.Walk(0x56bd80, 0xc00000a1a0, 0x56c4c0, 0xc000060600)
/usr/local/go/src/go/ast/walk.go:344 +0xd6d
go/ast.walkDeclList(0x56bd80, 0xc00000a1a0, 0xc0000465b0, 0x1, 0x1)
/usr/local/go/src/go/ast/walk.go:38 +0x9e
go/ast.Walk(0x56bd80, 0xc00000a1a0, 0x56c440, 0xc000072100)
/usr/local/go/src/go/ast/walk.go:353 +0x2656
go/ast.Inspect(0x56c440, 0xc000072100, 0xc00000a1a0)
/usr/local/go/src/go/ast/walk.go:385 +0x4b
main.processSingleGoSource(0xc000050100, 0x7fffabd2737f, 0x28, 0xc00000e140, 0x2)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:235 +0x14e
main.processFiles(0xc00000e150, 0x1, 0x4, 0x5, 0x5)
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:215 +0xa8
main.main()
/home/presslabs/go/src/github.com/gosexy/gettext/go-xgettext/main.go:344 +0x138
And the following code doesn't cause panic:
package x
func fn() {
OtherFunc()
get()
}
Hi All,
I am running jobs on travis-ci and found that jobs are failing for go1.11.X and 1.12.X. Below are the logs
$ git clone --depth=50 --branch=master https://github.com/kishorkunal-raj/gettext.git kishorkunal-raj/gettext
$ travis_export_go 1.11.x github.com/kishorkunal-raj/gettext
0.01s0.08s$ travis_setup_go
go version go1.11.13 linux/amd64
$ export GOPATH="/home/travis/gopath"
$ export PATH="/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.11.13.linux.amd64/bin:/home/travis/bin:/home/travis/bin:/home/travis/.local/bin:/usr/local/lib/jvm/openjdk11/bin:/opt/pyenv/shims:/home/travis/.phpenv/shims:/home/travis/perl5/perlbrew/bin:/home/travis/.nvm/versions/node/v8.12.0/bin:/home/travis/.rvm/gems/ruby-2.5.3/bin:/home/travis/.rvm/gems/ruby-2.5.3@global/bin:/home/travis/.rvm/rubies/ruby-2.5.3/bin:/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.11.1.linux.amd64/bin:/usr/local/maven-3.6.3/bin:/usr/local/cmake-3.12.4/bin:/usr/local/clang-7.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/travis/.rvm/bin:/home/travis/.phpenv/bin:/opt/pyenv/bin:/home/travis/.yarn/bin"
$ export GO111MODULE="auto"
$ gimme version
v1.5.4
$ go version
go version go1.11.13 linux/amd64
go.env
$ go env
install
13.36s$ go get -t -v ./...
6.36s$ go test -v ./...
../../stretchr/testify/assert/assertions.go:1703:5: undefined: errors.Is
../../stretchr/testify/assert/assertions.go:1726:6: undefined: errors.Is
../../stretchr/testify/assert/assertions.go:1749:5: undefined: errors.As
../../stretchr/testify/assert/assertions.go:1766:7: undefined: errors.Unwrap
../../stretchr/testify/assert/assertions.go:1770:7: undefined: errors.Unwrap
FAIL github.com/kishorkunal-raj/gettext [build failed]
=== RUN Test
OK: 16 passed
--- PASS: Test (0.00s)
PASS
ok github.com/kishorkunal-raj/gettext/go-xgettext 0.006s
The command "go test -v ./..." exited with 2.
Done. Your build exited with 1.
Please help me out to fix it.
I want to use this in a web app, where potentially every request comes in for a different locale.
The SetLocale() command seems to be global.
How do you handle this in case where an app is serving in multiple languages similtaneously, different locale per goroutine?
If this functionality already exists, please document how.
Thank you
After running make or trying to just run go get github.com/lxc/lxd . The gettext errors are produced as shown below.
go build
# _/home/admin/src/port2port/lxc/gettext
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_bind_textdomain_codeset':
./gettext.go:64: undefined reference to `libintl_bind_textdomain_codeset'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_bindtextdomain':
./gettext.go:78: undefined reference to `libintl_bindtextdomain'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dcgettext':
./gettext.go:94: undefined reference to `libintl_dcgettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dcngettext':
./gettext.go:112: undefined reference to `libintl_dcngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dgettext':
./gettext.go:126: undefined reference to `libintl_dgettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dngettext':
./gettext.go:142: undefined reference to `libintl_dngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_gettext':
./gettext.go:164: undefined reference to `libintl_gettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_ngettext':
./gettext.go:179: undefined reference to `libintl_ngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_textdomain':
./gettext.go:207: undefined reference to `libintl_textdomain'
collect2: error: ld returned 1 exit status
Tell cgo to link libintl by changing line 26 of gettext.go from /*
to
// #cgo LDFLAGS: -lintl
and then insert /*
into line 27 of the same file.
go build
go test
¡Hola mundo!
Una manzana
3 manzanas
Buenos días
¡Hasta luego!
Hallo, Welt!
Ein Apfel
3 Äpfel
Guten morgen
Aufwiedersehen!
PASS
ok _/home/admin/src/port2port/lxc/gettext 0.002s
Hey,
Thanks for this project!
One inconsistency I notice in the "Usage" section of the README
:
gettext.Gettext
.go-xgettext
example command uses --keyword=Gettext
, which doesn't extract anything; it should instead be --keyword=gettext.Gettext --keyword-plural=gettext.NGettext
.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.