arb

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package arbfile implements reading and writing of Flutter ARB (Application Resource Bundle) files.

ARB files are JSON files with a specific structure:

  • "@@locale" holds the BCP-47 language code (e.g. "en", "ru").
  • Keys starting with "@" (other than "@@locale") are metadata entries (e.g. "@greeting") and are preserved verbatim — never translated.
  • All other string values are translatable.

File naming convention: app_LANG.arb (e.g. app_en.arb, app_ru.arb) stored in a single directory (e.g. lib/l10n/).

Round-trip fidelity: key order from the source file is preserved, and metadata keys immediately follow their corresponding translatable key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncKeys

func SyncKeys(src, target *File)

SyncKeys ensures target has the same translatable keys as src, preserving existing translations and adding empty entries for new keys. Obsolete keys (in target but not src) are removed.

Types

type File

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

File represents a parsed ARB file.

func NewTranslationFile

func NewTranslationFile(src *File, targetLocale string) *File

NewTranslationFile creates a new File for targetLocale mirroring src's structure but with all translatable values cleared.

func Parse

func Parse(data []byte) (*File, error)

Parse parses ARB content from a byte slice.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile reads and parses an ARB file from disk.

func (*File) Get

func (f *File) Get(key string) (string, bool)

Get returns the string value for a translatable key.

func (*File) Keys

func (f *File) Keys() []string

Keys returns all translatable (non-metadata) keys in document order.

func (*File) Locale

func (f *File) Locale() string

Locale returns the @@locale value.

func (*File) Marshal

func (f *File) Marshal() ([]byte, error)

Marshal serialises the ARB file to JSON with 2-space indentation. The @@locale key is always written first.

func (*File) Set

func (f *File) Set(key, value string) bool

Set sets the value of an existing translatable key. Returns true on success, false if the key is not found or is metadata.

func (*File) SourceValues

func (f *File) SourceValues() map[string]string

SourceValues returns a map of key → value for use as translation source.

func (*File) Stats

func (f *File) Stats() (int, int, float64)

Stats returns (total, translated, percentTranslated).

func (*File) UntranslatedKeys

func (f *File) UntranslatedKeys() []string

UntranslatedKeys returns translatable keys whose value is empty.

func (*File) WriteFile

func (f *File) WriteFile(path string) error

WriteFile serialises and writes to path.

Jump to

Keyboard shortcuts

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