-
Notifications
You must be signed in to change notification settings - Fork 26
/
doc.go
67 lines (56 loc) · 2.35 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package gettext implements a basic GNU's gettext library.
Example:
import (
"github.com/chai2010/gettext-go"
)
func main() {
gettext.SetLanguage("zh_CN")
// gettext.BindLocale(gettext.New("hello", "locale")) // from locale dir
// gettext.BindLocale(gettext.New("hello", "locale.zip")) // from locale zip file
// gettext.BindLocale(gettext.New("hello", "locale.zip", zipData)) // from embedded zip data
gettext.BindLocale(gettext.New("hello", "locale"))
// translate source text
fmt.Println(gettext.Gettext("Hello, world!"))
// Output: 你好, 世界!
// translate resource
fmt.Println(string(gettext.Getdata("poems.txt")))
// Output: ...
}
Translate directory struct("./examples/locale.zip"):
Root: "path" or "file.zip/zipBaseName"
+-default # locale: $(LC_MESSAGES) or $(LANG) or "default"
| +-LC_MESSAGES # just for `gettext.Gettext`
| | +-hello.mo # $(Root)/$(lang)/LC_MESSAGES/$(domain).mo
| | +-hello.po # $(Root)/$(lang)/LC_MESSAGES/$(domain).po
| | \-hello.json # $(Root)/$(lang)/LC_MESSAGES/$(domain).json
| |
| \-LC_RESOURCE # just for `gettext.Getdata`
| +-hello # domain map a dir in resource translate
| +-favicon.ico # $(Root)/$(lang)/LC_RESOURCE/$(domain)/$(filename)
| \-poems.txt
|
\-zh_CN # simple chinese translate
+-LC_MESSAGES
| +-hello.po # try "$(domain).po" first
| +-hello.mo # try "$(domain).mo" second
| \-hello.json # try "$(domain).json" third
|
\-LC_RESOURCE
+-hello
+-favicon.ico # $(lang)/$(domain)/favicon.ico
\-poems.txt # $(lang)/$(domain)/poems.txt
See:
http://en.wikipedia.org/wiki/Gettext
http://www.gnu.org/software/gettext/manual/html_node
http://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html
http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
http://www.poedit.net/
Please report bugs to <chaishushan{AT}gmail.com>.
Thanks!
*/
package gettext