i18n

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package i18n provides internationalization support for the application.

Index

Constants

This section is empty.

Variables

View Source
var (
	// English is a locale for English.
	English = Locale{
			// contains filtered or unexported fields
	}
	// Japanese is a locale for Japanese.
	Japanese = Locale{
				// contains filtered or unexported fields
	}

	// Default is the default locale.
	Default = English
)

Functions

This section is empty.

Types

type Locale

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

Locale is a locale for a language.

type Message

type Message struct {
	// ID uniquely identifies the message.
	ID string

	// Hash uniquely identifies the content of the message
	// that this message was translated from.
	Hash string

	// Description describes the message to give additional
	// context to translators that may be relevant for translation.
	Description string

	// LeftDelim is the left Go template delimiter.
	LeftDelim string

	// RightDelim is the right Go template delimiter.
	RightDelim string

	// Zero is the content of the message for the CLDR plural form "zero".
	Zero string

	// One is the content of the message for the CLDR plural form "one".
	One string

	// Two is the content of the message for the CLDR plural form "two".
	Two string

	// Few is the content of the message for the CLDR plural form "few".
	Few string

	// Many is the content of the message for the CLDR plural form "many".
	Many string

	// Other is the content of the message for the CLDR plural form "other".
	Other string
}

Message is a string that can be localized.

type Options

type Options struct {
	// TemplateData is the data passed when executing the message's template.
	// If TemplateData is nil and PluralCount is not nil, then the message template
	// will be executed with data that contains the plural count.
	TemplateData any

	// PluralCount determines which plural form of the message is used.
	PluralCount any

	// DefaultMessage is used if the message is not found in any message files.
	DefaultMessage *Message
}

Options is used to configure a translation.

type Translation

type Translation interface {
	Translate(id string) string
	TranslateWithOpts(id string, opts Options) string
	TranslateWithLocale(locale Locale, id string) string
	TranslateWithLocaleAndOpts(locale Locale, id string, opts Options) string
}

Translation is an interface for translating messages.

type Translator

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

Translator is a translation service.

func NewTranslator

func NewTranslator() (*Translator, error)

NewTranslator creates a new Translator.

func (*Translator) Translate

func (t *Translator) Translate(id string) string

Translate translates a message with the given ID.

func (*Translator) TranslateWithLocale

func (t *Translator) TranslateWithLocale(locale Locale, id string) string

TranslateWithLocale translates a message with the given ID to the given locale.

func (*Translator) TranslateWithLocaleAndOpts

func (t *Translator) TranslateWithLocaleAndOpts(locale Locale, id string, opts Options) string

TranslateWithLocaleAndOpts translates a message with the given ID to the given locale.

func (*Translator) TranslateWithOpts

func (t *Translator) TranslateWithOpts(id string, opts Options) string

TranslateWithOpts translates a message with the given ID.

Jump to

Keyboard shortcuts

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