gettext

package
v0.0.0-...-ab10d8f Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: Apache-2.0, MIT Imports: 4 Imported by: 0

README

gosexy/gettext

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

Requeriments

The GNU C library. If you're using GNU/Linux, FreeBSD or OSX you should already have it.

Installation

Use go get to download and install the binding:

go get github.com/gosexy/gettext

Usage

package main

import (
	"github.com/gosexy/gettext"
	"fmt"
	"os"
)

func main() {
	gettext.BindTextdomain("example", ".")
	gettext.Textdomain("example")

	os.Setenv("LANGUAGE", "es_MX.utf8")

	gettext.SetLocale(gettext.LC_ALL, "")

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

You can use os.Setenv to set the LANGUAGE environment variable or set it on a terminal:

export LANGUAGE="es_MX.utf8"
./gettext-program

Note that xgettext does not officially support Go syntax yet, however, you can generate a valid .pot file by forcing xgettest to use the C++ syntax:

xgettext -d example -s gettext_test.go -o example.pot -L c++ -i \
--keyword=NGettext:1,2 --keyword=Gettext

This will generate a example.pot file.

After translating the .pot file, you must generate .po and .mo files and remember to set the UTF-8 charset.

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

You can read gosexy/gettext documentation from a terminal

go doc github.com/gosexy/gettext

Or you can browse it online.

The original gettext documentation could be very useful as well:

man 3 gettext

Here's another good tutorial on using gettext.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// For all of the locale.
	LC_ALL = uint(C.LC_ALL)

	// For regular expression matching (it determines the meaning of range
	// expressions and equivalence classes) and string collation.
	LC_COLATE = uint(C.LC_ALL)

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

	// For localizable natural-language messages.
	LC_MESSAGES = uint(C.LC_MESSAGES)

	// For monetary formatting.
	LC_MONETARY = uint(C.LC_MONETARY)

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

	// For time and date formatting.
	LC_TIME = uint(C.LC_TIME)
)

Functions

func BindTextdomain

func BindTextdomain(domainname string, dirname string) string

Sets directory containing message catalogs.

func BindTextdomainCodeset

func BindTextdomainCodeset(domainname string, codeset string) string

Sets the output codeset for message catalogs for domain domainname.

func DCGettext

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

Like Gettext(), but looking up the message in the specified domain and category.

func DCNGettext

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

Like NGettext(), but looking up the message in the specified domain and category.

func DGettext

func DGettext(domain string, msgid string) string

Like Gettext(), but looking up the message in the specified domain.

func DNGettext

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

Like NGettext(), but looking up the message in the specified domain.

func Gettext

func Gettext(msgid string) string

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

func NGettext

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

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

func SetLocale

func SetLocale(category uint, locale string) string

Sets or queries the program's current locale.

func Sprintf

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

Like fmt.Sprintf() but without %!(EXTRA) errors.

func Textdomain

func Textdomain(domainname string) string

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