~nikwen/account-polld/directly-poll-with-new-account-data-fix

« back to all changes in this revision

Viewing changes to gettext/README.md

  • Committer: Roberto Alsina
  • Date: 2014-07-29 18:02:58 UTC
  • mto: (27.5.2 gmail_url)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: roberto.alsina@canonical.com-20140729180258-o4jzr93dcpamiahb
gettext package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# gosexy/gettext
 
2
 
 
3
Go bindings for [GNU gettext][1], an internationalization and localization
 
4
library for writing multilingual systems.
 
5
 
 
6
## Requeriments
 
7
 
 
8
The GNU C library. If you're using GNU/Linux, FreeBSD or OSX you should already
 
9
have it.
 
10
 
 
11
## Installation
 
12
 
 
13
Use `go get` to download and install the binding:
 
14
 
 
15
```sh
 
16
go get github.com/gosexy/gettext
 
17
```
 
18
 
 
19
## Usage
 
20
 
 
21
```go
 
22
package main
 
23
 
 
24
import (
 
25
        "github.com/gosexy/gettext"
 
26
        "fmt"
 
27
        "os"
 
28
)
 
29
 
 
30
func main() {
 
31
        gettext.BindTextdomain("example", ".")
 
32
        gettext.Textdomain("example")
 
33
 
 
34
        os.Setenv("LANGUAGE", "es_MX.utf8")
 
35
 
 
36
        gettext.SetLocale(gettext.LC_ALL, "")
 
37
 
 
38
        fmt.Println(gettext.Gettext("Hello, world!"))
 
39
}
 
40
```
 
41
 
 
42
You can use `os.Setenv` to set the `LANGUAGE` environment variable or set it
 
43
on a terminal:
 
44
 
 
45
```sh
 
46
export LANGUAGE="es_MX.utf8"
 
47
./gettext-program
 
48
```
 
49
 
 
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++
 
52
syntax:
 
53
 
 
54
```sh
 
55
xgettext -d example -s gettext_test.go -o example.pot -L c++ -i \
 
56
--keyword=NGettext:1,2 --keyword=Gettext
 
57
```
 
58
 
 
59
This will generate a `example.pot` file.
 
60
 
 
61
After translating the `.pot` file, you must generate `.po` and `.mo` files and
 
62
remember to set the UTF-8 charset.
 
63
 
 
64
```sh
 
65
msginit -l es_MX -o example.po -i example.pot
 
66
msgfmt -c -v -o example.mo example.po
 
67
```
 
68
 
 
69
Finally, move the `.mo` file to an appropriate location.
 
70
 
 
71
```sh
 
72
mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo
 
73
```
 
74
 
 
75
## Documentation
 
76
 
 
77
You can read `gosexy/gettext` documentation from a terminal
 
78
 
 
79
```sh
 
80
go doc github.com/gosexy/gettext
 
81
```
 
82
 
 
83
Or you can [browse it](http://godoc.org/github.com/gosexy/gettext) online.
 
84
 
 
85
The original gettext documentation could be very useful as well:
 
86
 
 
87
```sh
 
88
man 3 gettext
 
89
```
 
90
 
 
91
Here's another [good tutorial][2] on using gettext.
 
92
 
 
93
[1]: http://www.gnu.org/software/gettext/
 
94
[2]: http://oriya.sarovar.org/docs/gettext_single.html