Coder Social home page Coder Social logo

gettext-go's Introduction

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.

gettext-go's People

Contributors

xiam avatar mvo5 avatar adamcstephens avatar sqp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.