polyglot

package module
v0.0.0-...-3427b7b Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2012 License: BSD-3-Clause Imports: 7 Imported by: 0

README

About polyglot

polyglot is a String translation package and tool for Go.

Setup

Make sure you have a working Go installation. See Getting Started

Now run go get github.com/lxn/polyglot and go get github.com/lxn/polyglot/polyglot.

How does it work?

  1. It's pretty simple. Wrap translatable strings in your code in a call to a func tr(source string, context ...string) string, e.g. tr("bla"). You have to provide this function for every package you wish to use polyglot from.
  2. After adding new translatable strings to your code, run the polyglot command, which scans your Go code for calls to a tr function. It will create or update JSON .tr files, adding new translatable strings that it finds.
  3. Translate the strings.

Please see the hellopolyglot example for more details.

Documentation

Overview

Package polyglot provides a simple string translation mechanism.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLocale is returned if a specified locale is invalid.
	ErrInvalidLocale = errors.New("invalid locale")
)

Functions

This section is empty.

Types

type Dict

type Dict struct {
	// contains filtered or unexported fields
}

Dict provides translated strings appropriate for a specific locale.

func NewDict

func NewDict(translationsDirPath, locale string) (*Dict, error)

NewDict returns a new Dict with the specified translations directory path and locale.

The directory will be scanned recursively for JSON encoded .tr translation files, as created by the polyglot tool, that have a name suffix matching one of the locales in the locale chain. Example: Locale "en_US" has chain ["en_US", "en"], so files like foo-en_US.tr, foo-en.tr, bar-en.tr, baz-en.tr would be picked up.

func (*Dict) DirPath

func (d *Dict) DirPath() string

DirPath returns the translations directory path of the Dict.

func (*Dict) Locale

func (d *Dict) Locale() string

Locale returns the locale of the Dict.

func (*Dict) Translation

func (d *Dict) Translation(source string, context ...string) string

Translation returns a translation of the source string to the locale of the Dict or the source string, if no matching translation was found.

Provided context arguments are used for disambiguation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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