properties

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package propfile implements reading and writing of Java .properties files.

Format: key=value pairs, one per line. Lines starting with '#' or '!' are comments and are preserved verbatim in the output. Blank lines are also preserved. Multi-line values (backslash continuation) are not supported — each line is treated independently.

File naming convention: each language is stored as a separate file:

translations_dir/en.properties  (source)
translations_dir/ru.properties  (translation)

The File type maintains the original line order so that round-trip serialization reproduces the source structure with translated values.

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 keys as src, preserving existing translations and adding empty entries for new keys. Keys removed from src are also removed from target.

Types

type File

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

File represents a parsed .properties file.

func NewTranslationFile

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

NewTranslationFile creates an empty target File mirroring src's structure with all values cleared.

func Parse

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

Parse parses .properties content from a byte slice.

func ParseFile

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

ParseFile reads and parses a .properties file from disk.

func (*File) Get

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

Get returns the value for key and whether it was found.

func (*File) Keys

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

Keys returns all translation keys in document order.

func (*File) Marshal

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

Marshal serialises the file back to .properties format.

func (*File) Set

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

Set sets the value for an existing key. Returns true on success, false if the key does not exist.

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) for this file.

func (*File) UntranslatedKeys

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

UntranslatedKeys returns keys whose value is empty.

func (*File) WriteFile

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

WriteFile serialises and writes to path, creating parent directories with 0755 permissions.

Jump to

Keyboard shortcuts

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