3
Go bindings for [GNU gettext][1], an internationalization and localization
4
library for writing multilingual systems.
8
The GNU C library. If you're using GNU/Linux, FreeBSD or OSX you should already
13
Use `go get` to download and install the binding:
16
go get github.com/gosexy/gettext
25
"github.com/gosexy/gettext"
31
gettext.BindTextdomain("example", ".")
32
gettext.Textdomain("example")
34
os.Setenv("LANGUAGE", "es_MX.utf8")
36
gettext.SetLocale(gettext.LC_ALL, "")
38
fmt.Println(gettext.Gettext("Hello, world!"))
42
You can use `os.Setenv` to set the `LANGUAGE` environment variable or set it
46
export LANGUAGE="es_MX.utf8"
50
Note that `xgettext` does not officially support Go syntax yet, however, you
51
can generate a valid `.pot` file by forcing `xgettest` to use the C++
55
xgettext -d example -s gettext_test.go -o example.pot -L c++ -i \
56
--keyword=NGettext:1,2 --keyword=Gettext
59
This will generate a `example.pot` file.
61
After translating the `.pot` file, you must generate `.po` and `.mo` files and
62
remember to set the UTF-8 charset.
65
msginit -l es_MX -o example.po -i example.pot
66
msgfmt -c -v -o example.mo example.po
69
Finally, move the `.mo` file to an appropriate location.
72
mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo
77
You can read `gosexy/gettext` documentation from a terminal
80
go doc github.com/gosexy/gettext
83
Or you can [browse it](http://godoc.org/github.com/gosexy/gettext) online.
85
The original gettext documentation could be very useful as well:
91
Here's another [good tutorial][2] on using gettext.
93
[1]: http://www.gnu.org/software/gettext/
94
[2]: http://oriya.sarovar.org/docs/gettext_single.html