language

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 11 Imported by: 1

README

language

The package helps with multi language support (i18n)

Resource Files

Database Column Holding Multi-Language data

Documentation

Index

Constants

View Source
const UnknownLanguageCode = "?"

Variables

View Source
var (
	FileExtension  = ".i18n"
	HintSeparator  = "//"
	NotFoundMarker = "\u2638"
)

Functions

func IndexToCode

func IndexToCode(index Index) string

IndexToCode returns language code.

func IsLanguageName

func IsLanguageName(b []byte) bool

func Supported

func Supported() []string

Supported returns code of supported languages.

func TranslationResource

func TranslationResource(dir string, langfilename string, customSuffixes ...string) ([]string, error)

func WithBrackets added in v0.2.0

func WithBrackets(bracketSymbol string) func(o *Option)

WithBrackets assignss wrapping symbol used by .

func WithPrimaryLanguage added in v0.2.0

func WithPrimaryLanguage(li Index) func(o *Option)

WithPrimaryLanguage assigns a primary language.

func WithSuffixes added in v0.2.0

func WithSuffixes(suffix ...string) func(o *Option)

WithSuffixes assigns suffixes of translation files in the order of applying priority. The first suffix has the highest priority.

Types

type Container added in v0.2.0

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

Container stores for all translation resources.

func New added in v0.2.0

func New(fn ...func(o *Option)) *Container

New creates a new translations container.

func (*Container) AddCustomDir added in v0.2.0

func (c *Container) AddCustomDir(dirs ...string) error

AddCustomDir registers a directory with custom translation files.

func (*Container) AddFileByMask added in v0.2.0

func (c *Container) AddFileByMask(dir string, mask string) error

AddFileByMask registers .i18n files matching mask from the path specified by path.

func (*Container) AddFiles added in v0.2.0

func (c *Container) AddFiles(filenames ...string) error

AddFiles registers .i18n files in the container. Returns error if even one could not be found or it's a directory.

func (*Container) Lang added in v0.2.0

func (c *Container) Lang(li Index) ContainerRequest

func (*Container) ListenFileChange added in v0.2.0

func (c *Container) ListenFileChange() error

func (*Container) ReadRegisteredFiles added in v0.2.0

func (c *Container) ReadRegisteredFiles() error

ReadRegisteredFiles reads content of all registered files and stores items in the container.

type ContainerRequest added in v0.2.0

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

func (*ContainerRequest) Hint added in v0.2.0

func (c *ContainerRequest) Hint(id string) string

func (*ContainerRequest) JSON added in v0.2.0

func (cr *ContainerRequest) JSON() ([]byte, error)

JSON returns translation in JSON format.

func (*ContainerRequest) Value added in v0.2.0

func (c *ContainerRequest) Value(id string) string

func (*ContainerRequest) ValueWithDefault added in v0.2.0

func (c *ContainerRequest) ValueWithDefault(id string, notFoundValue string) string

type Index

type Index int

Index is integer representative of language short code.

const Unknown Index = -1

Unknown value is used if language code is not found.

var (
	NoIndex Index = Unknown
)

func Parse added in v0.1.0

func Parse(lang string) Index

Parse returns index of language code, if not found returns -1.

func SetNoLanguage added in v0.1.1

func SetNoLanguage(lang string) Index

func ToIndex

func ToIndex(lang string) Index

ToIndex returns index by language code: ru, en, sr, cz, created new if not found.

type Item added in v0.2.0

type Item struct {
	Key   string
	Value string
	Hint  string
}

Item represents a row in a .i18n file.

type Name

type Name []string

Name holds decoded names. Index of the slice calculates by ToIndex().

func ToName

func ToName(b []byte) (Name, error)

Name decodes jsonb into array of strings

func (*Name) Byte

func (rn *Name) Byte() []byte

func (Name) Elem added in v0.1.0

func (n Name) Elem(index Index) string

Elem

func (Name) MarshalJSON

func (n Name) MarshalJSON() ([]byte, error)

func (*Name) Scan

func (n *Name) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (*Name) UnmarshalJSON

func (n *Name) UnmarshalJSON(buf []byte) error

func (Name) Value

func (n Name) Value() (driver.Value, error)

Value implements interface sql.Valuer

type NameColumn

type NameColumn []byte

NameColumn is a type of column Name in regular reference table

func (NameColumn) Name

func (rn NameColumn) Name() (Name, error)

Name decodes jsonb into array of strings

type Option added in v0.2.0

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

Option defines options for Container.

type RequestStrategy added in v0.2.0

type RequestStrategy int8
const (
	ReturnNotFoundVariable RequestStrategy = iota
	ReturnEmptyString
	ReturnInPrimaryLanguage
)

type ResponseItem added in v0.2.0

type ResponseItem struct {
	Value string `json:"v"`
	Hint  string `json:"h,omitempty"`
}

ResponseItem represents a row to be returned to the client.

type Set added in v0.2.0

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

Set holds a set of items.

Jump to

Keyboard shortcuts

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