gettext-go

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2020 License: BSD-3-Clause

README

  • 赞助 BTC: 1Cbd6oGAUUyBi7X7MaR4np4nTmQZXVgkCW
  • 赞助 ETH: 0x623A3C3a72186A6336C79b18Ac1eD36e1c71A8a6
  • Go语言付费QQ群: 1055927514

gettext-go

PkgDoc: http://godoc.org/github.com/chai2010/gettext-go/gettext

Install

  1. go get github.com/chai2010/gettext-go/gettext
  2. go run hello.go

The godoc.org or gowalker.org has more information.

Example

package main

import (
	"fmt"

	"github.com/chai2010/gettext-go/gettext"
)

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

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

	// 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

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

	// if no msgctxt in PO file (only msgid and msgstr),
	// specify context as "" by
	fmt.Println(gettext.PGettext("", "Hello, world!"))
	// Output: 你好, 世界!

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

Go file: hello.go; PO file: hello.po;

BUGS

Please report bugs to chaishushan@gmail.com.

Thanks!

Directories

Path Synopsis
This is a gettext-go exmaple.
This is a gettext-go exmaple.
hi
Package hi is a example pkg.
Package hi is a example pkg.
Package gettext implements a basic GNU's gettext library.
Package gettext implements a basic GNU's gettext library.
mo
Package mo provides support for reading and writing GNU MO file.
Package mo provides support for reading and writing GNU MO file.
plural
Package plural provides standard plural formulas.
Package plural provides standard plural formulas.
po
Package po provides support for reading and writing GNU PO file.
Package po provides support for reading and writing GNU PO file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL