parse

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: MIT Imports: 14 Imported by: 0

README

Parse

structure

Documentation

Index

Constants

View Source
const (
	LittleEndian = util.LittleEndian // Force little-endian parsing
	BigEndian    = util.BigEndian    // Force big-endian parsing
	NativeEndian = util.NativeEndian // Auto-detect byte order
)

Variables

This section is empty.

Functions

func Mo

func Mo(path string, opts ...MoOption) (*po.File, error)

func MoFromBytes

func MoFromBytes(b []byte, name string, opts ...MoOption) (*po.File, error)

func MoFromFile

func MoFromFile(f *os.File, opts ...MoOption) (*po.File, error)

func MoFromReader

func MoFromReader(r io.Reader, name string, opts ...MoOption) (*po.File, error)

func Po

func Po(path string, opts ...PoOption) (*po.File, error)

func PoFromBytes

func PoFromBytes(b []byte, name string, opts ...PoOption) (*po.File, error)

func PoFromFile

func PoFromFile(f *os.File, opts ...PoOption) (*po.File, error)

func PoFromReader

func PoFromReader(r io.Reader, name string, opts ...PoOption) (*po.File, error)

func PoFromString

func PoFromString(s, name string, opts ...PoOption) (*po.File, error)

Types

type Endianness added in v2.3.0

type Endianness = util.Endianness

Endianness represents byte order options for MO files.

type MoConfig added in v2.3.0

type MoConfig struct {

	// The logger can be nil, otherwise this logger will be used to print all errors by default.
	Logger *log.Logger
	// Specifies the endianness to work with,
	// if [NativeEndian], the endianness
	// automatically determined by the magic number will be used,
	// otherwise, the specified endianness will be used.
	Endianness Endianness
	// Causes parsing to fail if the entries are not sorted properly.
	MustBeSorted bool
	// contains filtered or unexported fields
}

MoConfig holds configuration options for MO file parsing.

func DefaultMoConfig added in v2.3.0

func DefaultMoConfig(opts ...MoOption) MoConfig

func (*MoConfig) ApplyOptions added in v2.3.0

func (mc *MoConfig) ApplyOptions(opts ...MoOption)

Overwrite the configuration with the options provided, saving the previous state so that it can be restored later with MoConfig.RestoreLastCfg if desired.

func (*MoConfig) RestoreLastCfg added in v2.3.0

func (mc *MoConfig) RestoreLastCfg()

Restores the configuration state prior to the last MoConfig.ApplyOptions if it exists, otherwise it does nothing.

type MoOption added in v2.3.0

type MoOption func(*MoConfig)

MoOption defines a function type for modifying MoConfig.

func MoWithConfig added in v2.3.0

func MoWithConfig(c MoConfig) MoOption

MoWithConfig creates an option to replace the entire configuration.

func MoWithEndianness added in v2.3.0

func MoWithEndianness(e Endianness) MoOption

MoWithEndianness creates an option to set the byte order.

func MoWithLogger added in v2.5.0

func MoWithLogger(logger *log.Logger) MoOption

MoWithLogger creates an option to set the error logger.

func MoWithMustBeSorted added in v2.5.0

func MoWithMustBeSorted(m bool) MoOption

MoWithMustBeSorted creates an option to enforce entry sorting.

type MoParser

type MoParser struct {
	Config MoConfig // Configuration for parsing behavior
	// contains filtered or unexported fields
}

MoParser handles parsing of MO files into po.File structures.

func NewMo

func NewMo(path string, opts ...MoOption) (*MoParser, error)

NewMo creates a new MoParser from a file path.

func NewMoFromBytes

func NewMoFromBytes(b []byte, name string, opts ...MoOption) *MoParser

NewMoFromBytes creates a new MoParser from a byte slice.

func NewMoFromFile

func NewMoFromFile(f *os.File, opts ...MoOption) (*MoParser, error)

NewMoFromFile creates a new MoParser from an open *os.File.

func NewMoFromReader

func NewMoFromReader(r io.Reader, name string, opts ...MoOption) (*MoParser, error)

NewMoFromReader creates a new MoParser from an io.Reader.

func (MoParser) Error

func (m MoParser) Error() error

Error returns the first error encountered during parsing, if any.

func (MoParser) Errors

func (m MoParser) Errors() []error

Errors returns all errors encountered during parsing.

func (*MoParser) Parse

func (m *MoParser) Parse() (file *po.File)

Parse reads and parses the MO file into a po.File structure.

func (*MoParser) ParseWithOptions added in v2.3.0

func (m *MoParser) ParseWithOptions(opts ...MoOption) (file *po.File)

ParseWithOptions parses the MO file with temporary configuration options. The original configuration is restored after parsing.

type PoConfig

type PoConfig struct {

	// IgnoreComments controls whether to discard translator comments.
	IgnoreComments bool
	// IgnoreAllComments controls whether to discard all comments including extracted comments and flags.
	IgnoreAllComments bool
	// Logger is an optional logger for error output. If nil, errors are only stored internally.
	Logger *log.Logger
	// Verbose enables more detailed logging when true.
	Verbose bool
	// SkipHeader controls whether to skip the metadata header entry.
	SkipHeader bool
	// CleanDuplicates controls whether to remove duplicate entries during parsing.
	CleanDuplicates bool
	// ParseObsoletes controls whether to parse obsolete entries (marked with #~).
	ParseObsoletes bool
	// UseCustomObsoletePrefix enables using a custom prefix for obsolete entries.
	UseCustomObsoletePrefix bool
	// CustomObsoletePrefix defines the custom marker for obsolete entries.
	CustomObsoletePrefix rune
	// contains filtered or unexported fields
}

func DefaultPoConfig

func DefaultPoConfig(opts ...PoOption) PoConfig

DefaultPoConfig returns a new PoConfig with recommended defaults: - CleanDuplicates: true - ParseObsoletes: true.

func (*PoConfig) ApplyOptions

func (p *PoConfig) ApplyOptions(opts ...PoOption)

ApplyOptions overwrite the configuration with the options provided, saving the previous state so that it can be restored later with PoConfig.RestoreLastCfg if desired.

func (*PoConfig) RestoreLastCfg

func (p *PoConfig) RestoreLastCfg()

RestoreLastCfg restores the configuration state prior to the last PoConfig.ApplyOptions if it exists, otherwise it does nothing.

type PoOption

type PoOption func(*PoConfig)

PoOption defines a function type for modifying PoConfig.

func PoWithCleanDuplicates

func PoWithCleanDuplicates(cd bool) PoOption

PoWithCleanDuplicates creates an option to control duplicate removal.

func PoWithConfig

func PoWithConfig(cfg PoConfig) PoOption

PoWithConfig creates an option to replace the entire configuration.

func PoWithCustomObsoletePrefix

func PoWithCustomObsoletePrefix(r rune) PoOption

PoWithCustomObsoletePrefix creates an option to set a custom obsolete marker.

func PoWithIgnoreAllComments

func PoWithIgnoreAllComments(iag bool) PoOption

PoWithIgnoreAllComments creates an option to discard all comments.

func PoWithIgnoreComments

func PoWithIgnoreComments(ig bool) PoOption

PoWithIgnoreComments creates an option to discard translator comments.

func PoWithLogger

func PoWithLogger(logger *log.Logger) PoOption

PoWithLogger creates an option to set the error logger.

func PoWithParseObsolete

func PoWithParseObsolete(p bool) PoOption

PoWithParseObsolete creates an option to control obsolete entry parsing.

func PoWithSkipHeader

func PoWithSkipHeader(s bool) PoOption

PoWithSkipHeader creates an option to skip the metadata header.

func PoWithUseCustomObsoletePrefix

func PoWithUseCustomObsoletePrefix(u bool) PoOption

PoWithUseCustomObsoletePrefix creates an option to enable custom obsolete markers.

func PoWithVerbose added in v2.5.0

func PoWithVerbose(v bool) PoOption

PoWithVerbose creates an option to enable verbose logging.

type PoParser

type PoParser struct {
	Config PoConfig // Configuration for parsing behavior
	// contains filtered or unexported fields
}

PoParser handles parsing of PO files into po.File structures.

func NewPo

func NewPo(path string, options ...PoOption) (*PoParser, error)

NewPo creates a new PoParser from a file path.

func NewPoFromBytes

func NewPoFromBytes(data []byte, name string, options ...PoOption) *PoParser

NewPoFromBytes creates a new PoParser from a byte slice.

func NewPoFromFile

func NewPoFromFile(f *os.File, options ...PoOption) (*PoParser, error)

NewPoFromFile creates a new PoParser from an open *os.File.

func NewPoFromReader

func NewPoFromReader(r io.Reader, name string, options ...PoOption) (*PoParser, error)

NewPoFromReader creates a new PoParser from an io.Reader.

func NewPoFromString

func NewPoFromString(s, name string, options ...PoOption) *PoParser

NewPoFromString creates a new PoParser from a string.

func (*PoParser) Error

func (p *PoParser) Error() error

Error returns the first error encountered during parsing, if any.

func (*PoParser) Errors

func (p *PoParser) Errors() []error

Errors returns all errors encountered during parsing.

func (*PoParser) Parse

func (p *PoParser) Parse() *po.File

Parse reads and parses the PO file into a po.File structure.

func (*PoParser) ParseWithOptions

func (p *PoParser) ParseWithOptions(opts ...PoOption) *po.File

ParseWithOptions parses the PO file with temporary configuration options. The original configuration is restored after parsing.

func (*PoParser) Warnings

func (p *PoParser) Warnings() []error

Warnings returns all non-critical warnings encountered during parsing.

Jump to

Keyboard shortcuts

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