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