File: doc.go

package info (click to toggle)
golang-github-chai2010-gettext-go 0.0~git20191225.6b9f4b1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 3,256 kB
  • sloc: makefile: 23
file content (66 lines) | stat: -rw-r--r-- 2,288 bytes parent folder | download | duplicates (4)
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
// 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/gettext"
	)

	func main() {
		gettext.SetLocale("zh_CN")
		gettext.Textdomain("hello")

		// gettext.BindTextdomain("hello", "local", nil)         // from local dir
		// gettext.BindTextdomain("hello", "local.zip", nil)     // from local zip file
		// gettext.BindTextdomain("hello", "local.zip", zipData) // from embedded zip data

		gettext.BindTextdomain("hello", "local", nil)

		// translate source text
		fmt.Println(gettext.Gettext("Hello, world!"))
		// Output: 你好, 世界!

		// translate resource
		fmt.Println(string(gettext.Getdata("poems.txt")))
		// Output: ...
	}

Translate directory struct("../examples/local.zip"):

	Root: "path" or "file.zip/zipBaseName"
	 +-default                 # local: $(LC_MESSAGES) or $(LANG) or "default"
	 |  +-LC_MESSAGES            # just for `gettext.Gettext`
	 |  |   +-hello.mo             # $(Root)/$(local)/LC_MESSAGES/$(domain).mo
	 |  |   \-hello.po             # $(Root)/$(local)/LC_MESSAGES/$(domain).mo
	 |  |
	 |  \-LC_RESOURCE            # just for `gettext.Getdata`
	 |      +-hello                # domain map a dir in resource translate
	 |         +-favicon.ico       # $(Root)/$(local)/LC_RESOURCE/$(domain)/$(filename)
	 |         \-poems.txt
	 |
	 \-zh_CN                   # simple chinese translate
	    +-LC_MESSAGES
	    |   +-hello.mo             # try "$(domain).mo" first
	    |   \-hello.po             # try "$(domain).po" second
	    |
	    \-LC_RESOURCE
	        +-hello
	           +-favicon.ico       # try "$(local)/$(domain)/file" first
	           \-poems.txt         # try "default/$(domain)/file" second

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