Help us shape the future of Go! Take the 2026 Go Developer Survey

ginta

package module
v0.0.0-...-7d66296 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

The root of the ginta i18n library. Ginta is an i18n solution that provides both simple (name=value) lookups, context-dependant translations and support for formatted output.

Ginta is designed to be easy to use and extend. Easy to use insofar as that the user needs not worry about internals such as resource loading, synchronization and lifetime. Easy to extend insofar as that it should be easy to "plug in" new ways to acquire resources or formats.

Ginta has two modes of query for a resource. A Resource can be queried, or it can be resolved. When a resource is queried, a direct lookup of the resource name is performed. If no resource with the specified name is known, an error is returned. In contrast, if a resource is resolved, its name is interpreted as a "hierarchical key" (See package common). Such a hierarchical key defines one or more super-keys. If a resource is not found under its hierarchical key, the system automatically walks through the super-keys until either a matching resource is located, or resolution fails even on the "root key", in which case an error is returned.

This package contains the basic primitive functions of ginta. These functions are used to query the translation database for resource entries, either individually or in bulk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List() []*types.Language

Lists all currently known languages

func Register

func Register(p LanguageProvider)

Adds a language provider to the system. Often there will be a single provider, but there may be more. In case of multiple providers defining the same language, their definitions will be merged (that is, their resource sets combined). In this case, providers registered later will overwrite these defined earlier.

Types

type Enumerator

type Enumerator interface {
	/* Returns all languages available on this enumerator. The returned channel must be closed after the last language has been send */
	Enumerate() <-chan types.Language
}

An Enumerator is any type that can enumerate one or more languages for which resources can be loaded. Result channel must be filled with all available languages, then closed. An empty Enumerator should therefore return a closed channel.

type LanguageProvider

type LanguageProvider interface {
	// enumeration functionality
	Enumerator
	// list functionality
	Lister
}

The full service provider interface. Implementions are able to provide a number of lanugages (and their contents). See the package providers for some samples.

type Lister

type Lister interface {
	/* Returns all resources for the language code available on this source. The returned channel must be closed after the last resource has been send */
	List(code string) <-chan types.Resource
}

A Lister is any type that can list the available resources (in some backing storage) for a given language code. After all available resources have been transmitted, the returned channel must be closed.

type Locale

type Locale string

Locale defines methods to access resources for a language

var DefaultLocale Locale = Locale("en")

The default locale of the application - may be changed by the application.

func (Locale) GetResource

func (l Locale) GetResource(key string) (string, error)

Returns a resource by simple name matching

func (Locale) GetResourceBundle

func (l Locale) GetResourceBundle(prefix string) map[string]string

Returns a "resource bundle". This bundle is contains all resource whose hierarchical key has exactly the specified prefix - but no resources with shorter or longer prefix paths.

func (Locale) ResolveResource

func (l Locale) ResolveResource(k types.HierarchicalKey) (string, error)

Resolves a resource by its hierarchical key.

func (Locale) ResolveResourceBundle

func (l Locale) ResolveResourceBundle(prefix string) map[string]string

Returns the combination of this resource bundle and all its parent bundles. The resources defined in a child are not overwritten by its parent.

Directories

Path Synopsis
Defines the basic types of ginta, with their methods.
Defines the basic types of ginta, with their methods.
fmt
Provides function for messages containing variable, formatted values.
Provides function for messages containing variable, formatted values.
nr
Detailed formatter for integers.
Detailed formatter for integers.
plural
The plural package substitutes numeric values for "plural words".
The plural package substitutes numeric values for "plural words".
quoted
allows output of quoted-literal (%#v) values.
allows output of quoted-literal (%#v) values.
time
Allows formatted output of time values.
Allows formatted output of time values.
Internal workhorse of ginta.
Internal workhorse of ginta.
providers
fs
A simple, file system based provider that uses multisrc conventions to load its resources.
A simple, file system based provider that uses multisrc conventions to load its resources.
multisrc
Parser for "resource-file" like inputs.
Parser for "resource-file" like inputs.
simple
Simple static resource provider.
Simple static resource provider.
The setup package makes it easy and convenient to bootstrap the ginta library
The setup package makes it easy and convenient to bootstrap the ginta library

Jump to

Keyboard shortcuts

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