arb

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package arb provides a parser for .ARB (Application Resource Bundle) files. (See https://github.com/google/app-resource-bundle)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidICUMessage     = errors.New("invalid ICU message")
	ErrMissingRequiredLocale = errors.New("missing required @@locale")
	ErrInvalid               = errors.New("invalid")
	ErrMalformedJSON         = errors.New("malformed JSON")
	ErrUndefinedPlaceholder  = errors.New("undefined placeholder")
)

Functions

func Encode

func Encode(w io.Writer, file *File, indent string) error

Types

type Decoder

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

func NewDecoder

func NewDecoder() *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(r io.Reader) (*File, error)

type File

type File struct {
	Locale           language.Tag
	Context          string         // @@context
	LastModified     time.Time      // @@last_modified
	Author           string         // @@author
	Comment          string         // @@comment
	CustomAttributes map[string]any // @@x-... attributes
	Messages         map[string]Message
}

File is an ARB (Application Resource Bundle) file.

func (*File) Copy added in v0.6.0

func (src *File) Copy(onMsg func(m *Message)) (dst *File)

Copy returns a partially deep copy of src calling onMsg for every new cloned message.

WARNING: Message.CustomAttributes and Placeholder.OptionalParameters won't be deep copied! If you want those to be deeply copied - do it yourself in onMsg.

type Message

type Message struct {
	ID               string // "greeting"
	ICUMessage       string // "Hello, {name}!"
	ICUMessageTokens []icumsg.Token
	Description      string                 // @greeting.description
	Comment          string                 // @greeting.comment
	Type             MessageType            // @greeting.type (text/image/css)
	Context          string                 // @greeting.context
	Placeholders     map[string]Placeholder // @greeting.placeholders
	CustomAttributes map[string]any         // @greeting.x-... attributes
}

type MessageType

type MessageType string
const (
	MessageTypeText  MessageType = "text"
	MessageTypeImage MessageType = "image"
	MessageTypeCSS   MessageType = "css"
)

type Placeholder

type Placeholder struct {
	Type               PlaceholderType // "String", "int", "double", "DateTime"
	Description        string
	Example            string
	Format             string // For DateTime or numbers.
	IsCustomDateFormat bool   // Optional.
	OptionalParameters map[string]any
}

type PlaceholderType

type PlaceholderType string
const (
	PlaceholderString   PlaceholderType = "String"
	PlaceholderInt      PlaceholderType = "int"
	PlaceholderDouble   PlaceholderType = "double"
	PlaceholderNum      PlaceholderType = "num"
	PlaceholderDateTime PlaceholderType = "DateTime"
)

Jump to

Keyboard shortcuts

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