Skip to content
Gettext for Go, stripped down to the bare metal
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Internationalization and localization support.

This module is a subset and rewrite of the Python gettext module 
in the Go language. It is NOT intended for use in a production environment.

Links to other gettext packages in the Go language:   (feature complete, cgo)      (multi language support)

The main difference between this module and the Python gettext module is that
this one only uses unicode AND with only one language file at a time (which is 
good enough for most programs). This approach reduces the code size 

This module contains only four exported functions:

	Parse()		// This is the ".mo" file parser and is overridable
	Setup()		// This function sets the translation
	String()	// This function returns a translated string
	StringN()	// This function returns a translated string in plural form

Usage (short):

	1) To use this package in your application, write this line (it's 
		import ""
	2) In your application define two function variables (for singualar and plural):
		var G = g5t.String
		var GN = g5t.StringN

	3) Code the rest of your program. When you want a string that needs to be 
	   translated, write G("string to translate") etc.
	4) Run for each ".go" file:
		xgettext -o messages.po -C -kG -kGN:1,2 yourprogramfile.go
	5) If you want to place the translation files to a sub directory of 
	   your application, make a directory called "translations" (for example)
	   To locate your translations place this function in your app:
		g5t.Setup("your_app", "directory_to_transl_files", "language", Parser)

	6) Translate "messages.po" with a text editor to a specific language and
	   save the file to "yourdomain.po". Then run
	   msgfmt yourdomain.po

	   Msgfmt creates "". Copy this file to the language
	   translation directory (in Debian this is "/usr/share/locale/")
	7) That's it.

Something went wrong with that request. Please try again.