doc.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. Package gettext implements a basic GNU's gettext library.
  6. Example:
  7. import (
  8. "github.com/chai2010/gettext-go/gettext"
  9. )
  10. func main() {
  11. gettext.SetLocale("zh_CN")
  12. gettext.Textdomain("hello")
  13. // gettext.BindTextdomain("hello", "local", nil) // from local dir
  14. // gettext.BindTextdomain("hello", "local.zip", nil) // from local zip file
  15. // gettext.BindTextdomain("hello", "local.zip", zipData) // from embedded zip data
  16. gettext.BindTextdomain("hello", "local", nil)
  17. // translate source text
  18. fmt.Println(gettext.Gettext("Hello, world!"))
  19. // Output: 你好, 世界!
  20. // translate resource
  21. fmt.Println(string(gettext.Getdata("poems.txt")))
  22. // Output: ...
  23. }
  24. Translate directory struct("../examples/local.zip"):
  25. Root: "path" or "file.zip/zipBaseName"
  26. +-default # local: $(LC_MESSAGES) or $(LANG) or "default"
  27. | +-LC_MESSAGES # just for `gettext.Gettext`
  28. | | +-hello.mo # $(Root)/$(local)/LC_MESSAGES/$(domain).mo
  29. | | \-hello.po # $(Root)/$(local)/LC_MESSAGES/$(domain).mo
  30. | |
  31. | \-LC_RESOURCE # just for `gettext.Getdata`
  32. | +-hello # domain map a dir in resource translate
  33. | +-favicon.ico # $(Root)/$(local)/LC_RESOURCE/$(domain)/$(filename)
  34. | \-poems.txt
  35. |
  36. \-zh_CN # simple chinese translate
  37. +-LC_MESSAGES
  38. | +-hello.mo # try "$(domain).mo" first
  39. | \-hello.po # try "$(domain).po" second
  40. |
  41. \-LC_RESOURCE
  42. +-hello
  43. +-favicon.ico # try "$(local)/$(domain)/file" first
  44. \-poems.txt # try "default/$(domain)/file" second
  45. See:
  46. http://en.wikipedia.org/wiki/Gettext
  47. http://www.gnu.org/software/gettext/manual/html_node
  48. http://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html
  49. http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
  50. http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
  51. http://www.poedit.net/
  52. Please report bugs to <chaishushan{AT}gmail.com>.
  53. Thanks!
  54. */
  55. package gettext