gettext

package module
v0.0.0-...-74466a0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2016 License: MIT Imports: 4 Imported by: 72

README

Build Status

gosexy/gettext

Go bindings for GNU gettext, an internationalization and localization library for writing multilingual systems.

Requeriments

Linux

Installation should be straightforward on Linux.

OSX

Installing gettext on a Mac is a bit awkward:

brew install gettext

export CGO_LDFLAGS=-L/usr/local/opt/gettext/lib
export CGO_CPPFLAGS=-I/usr/local/opt/gettext/include

go get github.com/gosexy/gettext

Getting the library

Use go get to download and install the binding:

go get github.com/gosexy/gettext

Usage

This is an example program showing the BindTextdomain, Textdomain and SetLocale bindings:

package main

import (
	"fmt"

	"github.com/gosexy/gettext"
)

func main() {
	textDomain := "default"

	gettext.BindTextdomain(textDomain, "path/to/domains")
	gettext.Textdomain(textDomain)

	gettext.SetLocale(gettext.LcAll, "es_MX.utf8")

	fmt.Println(gettext.Gettext("Hello, world!"))
}

Set the LANGUAGE env to the name of the language you want to use in your program:

export LANGUAGE="es_MX.utf8"
./myapp

You can use the xgettext command to extract strings to be translated from a Go program:

go get github.com/gosexy/gettext/go-xgettext

go-xgettext -o outfile.pot --keyword=Gettext --keyword-plural=NGettext infile.go

This will generate a example.pot file.

After actually translating the .pot file, you'll have to generate .po and .mo files with msginit and msgfmt:

msginit -l es_MX -o example.po -i example.pot
msgfmt -c -v -o example.mo example.po

Finally, move the .mo file to an appropriate location.

mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo

Documentation

Check out the API documentation godoc.org/github.com/gosexy/gettext).

The original gettext documentation:

man 3 gettext

And here's a good tutorial on using gettext.

Documentation

Overview

Package gettext provides bindings for GNU Gettext.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LcAll is for all of the locale.
	LcAll = uint(C.LC_ALL)

	// LcCollate is for regular expression matching (it determines the meaning of
	// range expressions and equivalence classes) and string collation.
	LcCollate = uint(C.LC_COLLATE)

	// LcCtype is for regular expression matching, character classification,
	// conversion, case-sensitive comparison, and wide character functions.
	LcCtype = uint(C.LC_CTYPE)

	// LcMessages is for localizable natural-language messages.
	LcMessages = uint(C.LC_MESSAGES)

	// LcMonetary is for monetary formatting.
	LcMonetary = uint(C.LC_MONETARY)

	// LcNumeric is for number formatting (such as the decimal point and the
	// thousands separator).
	LcNumeric = uint(C.LC_NUMERIC)

	// LcTime is for time and date formatting.
	LcTime = uint(C.LC_TIME)
)
View Source
var (
	LC_ALL      = LcAll
	LC_COLLATE  = LcCollate
	LC_CTYPE    = LcCtype
	LC_MESSAGES = LcMessages
	LC_MONETARY = LcMonetary
	LC_NUMERIC  = LcNumeric
	LC_TIME     = LcTime
)

Deprecated but kept for backwards compatibility.

Functions

func BindTextdomain

func BindTextdomain(domainname string, dirname string) string

BindTextdomain sets the directory containing message catalogs.

func BindTextdomainCodeset

func BindTextdomainCodeset(domainname string, codeset string) string

BindTextdomainCodeset sets the output codeset for message catalogs on the given domainname.

func DCGettext

func DCGettext(domain string, msgid string, category uint) string

DCGettext is like Gettext(), but looks up the message in the specified domain and category.

func DCNGettext

func DCNGettext(domainname string, msgid string, msgidPlural string, n uint64, category uint) string

DCNGettext is like NGettext(), but looks up the message in the specified domain and category.

func DGettext

func DGettext(domain string, msgid string) string

DGettext is like Gettext(), but looks up the message in the specified domain.

func DNGettext

func DNGettext(domainname string, msgid string, msgidPlural string, n uint64) string

DNGettext is like NGettext(), but looks up the message in the specified domain.

func Gettext

func Gettext(msgid string) string

Gettext attempts to translate a text string into the user's system language, by looking up the translation in a message catalog.

func NGettext

func NGettext(msgid string, msgidPlural string, n uint64) string

NGettext attempts to translate a text string into the user's system language, by looking up the appropriate plural form of the translation in a message catalog.

func SetLocale

func SetLocale(category uint, locale string) string

SetLocale sets the program's current locale.

func Sprintf

func Sprintf(format string, a ...interface{}) string

Sprintf is like fmt.Sprintf() but without %!(EXTRA) errors.

func Textdomain

func Textdomain(domainname string) string

Textdomain sets or retrieves the current message domain.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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