translation

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package translation provides an i18n implementation for the back- and frontend.

Index

Constants

View Source
const (
	COMMON  = "COMMON."
	CTRL    = "CONTROLLER."
	ORM     = "ORM."
	NAV     = "NAVIGATION."
	GRID    = "GRID."
	HISTORY = "HISTORY."
)

Translation groups.

View Source
const (
	DB = "db"
)

predefined translation providers.

View Source
const RAW = "raw"

RAW language.

Variables

View Source
var (
	ErrWrap     = "translation: %w"
	ErrProvider = errors.New("translation: provider is not set")
)

Error messages.

Functions

func AddRawMessage

func AddRawMessage(m ...i18n.Message)

AddRawMessage provides an option to define all the RAW messages of the application. This can be used in the init() function for the packages. Raw messages will be sorted by ID.

func Register

func Register(name string, provider providerFn) error

Register a translation provider.

Types

type Config

type Config struct {
	// Controller - if enabled, translations will be available in the controller.
	Controller bool
	// JSONFilePath - if not zero, JSON files will be generated for each defined language.
	JSONFilePath string
	// DefaultLanguage - Default language of the application.
	DefaultLanguage string `frontend:""`
}

Config for the translation.

type Locale

type Locale interface {
	Translate(messageID string, template ...map[string]interface{}) (string, error)
	TranslatePlural(messageID string, pluralCount interface{}, template ...map[string]interface{}) (string, error)
}

Locale interface.

func Localizer

func Localizer(lang ...string) Locale

Localizer will create a new Locale for the controller.

type Manager

type Manager interface {
	Reload() error
	Languages() ([]language.Tag, error)
	RawMessages() []i18n.Message
}

Manager interface.

func New

func New(provider string, providerOption interface{}, config Config) (Manager, error)

New creates a new translation Manager. JSON Files and i18n.Bundle will be generated if configured.

type Provider

type Provider interface {
	Bundle() (*i18n.Bundle, error)
	Languages() ([]language.Tag, error)
	JSON(path string) error
	AddRawMessage([]i18n.Message) error
	DefaultMessage(id string) *i18n.Message
	SetDefaultLanguage(language.Tag)
}

Provider interface.

Directories

Path Synopsis
Package db provides a database translation provider.
Package db provides a database translation provider.

Jump to

Keyboard shortcuts

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