Documentation
¶
Overview ¶
The compile package contains structures and functions used to compile Mo/Po files with their respective options
Index ¶
- Constants
- Variables
- func Highlight(cfg *HighlightConfig, name, input string) ([]byte, error)
- func HighlightFromBytes(cfg *HighlightConfig, name string, input []byte) ([]byte, error)
- func HighlightFromReader(cfg *HighlightConfig, name string, input io.Reader) ([]byte, error)
- func MoToBytes[T po.EntriesOrFile](f T, opts ...MoOption) []byte
- func MoToFile[T po.EntriesOrFile](f T, path string, opts ...MoOption) error
- func MoToWriter[T po.EntriesOrFile](f T, w io.Writer, opts ...MoOption) error
- func PoToBytes[T po.EntriesOrFile](f T, opts ...PoOption) []byte
- func PoToFile[T po.EntriesOrFile](f T, path string, opts ...PoOption) error
- func PoToString[T po.EntriesOrFile](f T, opts ...PoOption) string
- func PoToWriter[T po.EntriesOrFile](f T, w io.Writer, opts ...PoOption) error
- type Endianness
- type HighlightConfig
- type MoCompiler
- func (mc *MoCompiler) SetFile(f *po.File)
- func (mc MoCompiler) ToBytes() []byte
- func (mc *MoCompiler) ToBytesWithOptions(options ...MoOption) []byte
- func (mc MoCompiler) ToFile(f string) error
- func (mc *MoCompiler) ToFileWithOptions(f string, options ...MoOption) error
- func (mc MoCompiler) ToWriter(w io.Writer) error
- func (mc *MoCompiler) ToWriterWithOptions(w io.Writer, opts ...MoOption) error
- type MoConfig
- type MoOption
- type PoCompiler
- func (c *PoCompiler) SetFile(f *po.File)
- func (c PoCompiler) ToBytes() []byte
- func (c *PoCompiler) ToBytesWithOptions(opts ...PoOption) []byte
- func (c PoCompiler) ToFile(f string) error
- func (c *PoCompiler) ToFileWithOptions(f string, opts ...PoOption) error
- func (c PoCompiler) ToString() string
- func (c *PoCompiler) ToStringWithOptions(opts ...PoOption) string
- func (c PoCompiler) ToWriter(w io.Writer) error
- func (c *PoCompiler) ToWriterWithOptions(w io.Writer, opts ...PoOption) error
- type PoConfig
- type PoLocationMode
- type PoOption
- func PoWithAddLocation(loc PoLocationMode) PoOption
- func PoWithCommentFuzzy(c bool) PoOption
- func PoWithConfig(cfg PoConfig) PoOption
- func PoWithCopyrightHolder(holder string) PoOption
- func PoWithCustomObsoletePrefixRune(r rune) PoOption
- func PoWithForcePo(f bool) PoOption
- func PoWithForeignUser(f bool) PoOption
- func PoWithHeaderComments(hc bool) PoOption
- func PoWithHeaderFields(w bool) PoOption
- func PoWithHighlight(h *HighlightConfig) PoOption
- func PoWithIgnoreErrors(i bool) PoOption
- func PoWithLogger(logger *log.Logger) PoOption
- func PoWithMsgstrPrefix(prefix string) PoOption
- func PoWithMsgstrSuffix(suffix string) PoOption
- func PoWithNoLocation(n bool) PoOption
- func PoWithOmitHeader(o bool) PoOption
- func PoWithPackageName(name string) PoOption
- func PoWithTitle(t string) PoOption
- func PoWithUseCustomObsoletePrefix(u bool) PoOption
- func PoWithVerbose(v bool) PoOption
- func PoWithWordWrap(w bool) PoOption
Constants ¶
const ( LittleEndian = util.LittleEndian BigEndian = util.BigEndian NativeEndian = util.NativeEndian )
Variables ¶
var DefaultHighlight = &HighlightConfig{color.Magenta, color.Blue, color.Green}
Functions ¶
func Highlight ¶ added in v2.5.0
func Highlight(cfg *HighlightConfig, name, input string) ([]byte, error)
func HighlightFromBytes ¶ added in v2.5.0
func HighlightFromBytes(cfg *HighlightConfig, name string, input []byte) ([]byte, error)
func HighlightFromReader ¶ added in v2.5.0
func MoToWriter ¶
func PoToString ¶
func PoToString[T po.EntriesOrFile](f T, opts ...PoOption) string
func PoToWriter ¶
Types ¶
type Endianness ¶ added in v2.3.0
type Endianness = util.Endianness
type HighlightConfig ¶ added in v2.4.0
type MoCompiler ¶
func (*MoCompiler) SetFile ¶
func (mc *MoCompiler) SetFile(f *po.File)
func (MoCompiler) ToBytes ¶
func (mc MoCompiler) ToBytes() []byte
func (*MoCompiler) ToBytesWithOptions ¶
func (mc *MoCompiler) ToBytesWithOptions(options ...MoOption) []byte
func (MoCompiler) ToFile ¶
func (mc MoCompiler) ToFile(f string) error
func (*MoCompiler) ToFileWithOptions ¶
func (mc *MoCompiler) ToFileWithOptions(f string, options ...MoOption) error
func (*MoCompiler) ToWriterWithOptions ¶
func (mc *MoCompiler) ToWriterWithOptions(w io.Writer, opts ...MoOption) error
type MoConfig ¶
type MoConfig struct {
// The logger can be nil, otherwise this logger will be used to print all errors by default.
Logger *log.Logger
// If true, it still writes to the file if it already exists, in the method [MoCompiler.ToFile].
Force bool
// If true, process information and warnings are also printed.
Verbose bool
IgnoreErrors bool
Endianness Endianness
// If true, compiles the hash table.
HashTable bool
// contains filtered or unexported fields
}
func DefaultMoConfig ¶
func (*MoConfig) ApplyOptions ¶
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 ¶
func (mc *MoConfig) RestoreLastCfg()
Restores the configuration state prior to the last MoConfig.ApplyOptions if it exists, otherwise it does nothing.
type MoOption ¶
type MoOption func(c *MoConfig)
func MoWithConfig ¶
func MoWithEndianness ¶ added in v2.3.0
func MoWithEndianness(e Endianness) MoOption
func MoWithForce ¶
func MoWithHashTable ¶ added in v2.3.0
func MoWithIgnoreErrors ¶
func MoWithLogger ¶
func MoWithVerbose ¶
type PoCompiler ¶
type PoCompiler struct {
File *po.File // The source file containing translation entries.
Config PoConfig // Configuration settings for compilation.
// contains filtered or unexported fields
}
func (*PoCompiler) SetFile ¶
func (c *PoCompiler) SetFile(f *po.File)
func (PoCompiler) ToBytes ¶
func (c PoCompiler) ToBytes() []byte
func (*PoCompiler) ToBytesWithOptions ¶
func (c *PoCompiler) ToBytesWithOptions(opts ...PoOption) []byte
func (PoCompiler) ToFile ¶
func (c PoCompiler) ToFile(f string) error
func (*PoCompiler) ToFileWithOptions ¶
func (c *PoCompiler) ToFileWithOptions(f string, opts ...PoOption) error
func (PoCompiler) ToString ¶
func (c PoCompiler) ToString() string
func (*PoCompiler) ToStringWithOptions ¶
func (c *PoCompiler) ToStringWithOptions(opts ...PoOption) string
func (*PoCompiler) ToWriterWithOptions ¶
func (c *PoCompiler) ToWriterWithOptions(w io.Writer, opts ...PoOption) error
type PoConfig ¶
type PoConfig struct {
// The logger can be nil, otherwise this logger will be used to print all errors by default.
Logger *log.Logger
ForcePo bool // If true, forces the creation of a `.po` file, even if not strictly needed.
OmitHeader bool // If true, omits the header section in the generated `.po` file.
PackageName string // Name of the package associated with the translation.
CopyrightHolder string // Name of the entity holding copyright over the translation.
ForeignUser bool // If true, marks the translation as public domain.
Title string // Title to be included in the `.po` file header.
NoLocation bool // If true, suppresses location comments in the `.po` file.
AddLocation PoLocationMode // Specifies how location comments should be included ("never", "file", "full").
MsgstrPrefix string // Prefix added to all translation strings.
MsgstrSuffix string // Suffix added to all translation strings.
IgnoreErrors bool // If true, allows compilation to proceed despite non-critical errors.
Verbose bool
CommentFuzzy bool
HeaderComments bool
HeaderFields bool
WordWrap bool
UseCustomObsoletePrefix bool
CustomObsoletePrefixRune rune
Highlight *HighlightConfig
// contains filtered or unexported fields
}
PoConfig holds the settings for the compiler, affecting how translations are processed.
func DefaultPoConfig ¶
func NewPoConfigFromOptions ¶
func (*PoConfig) 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 (c *PoConfig) RestoreLastCfg()
Restores the configuration state prior to the last PoConfig.ApplyOptions if it exists, otherwise it does nothing.
type PoLocationMode ¶
type PoLocationMode string
const ( PoLocationModeFull PoLocationMode = "full" PoLocationModeNever PoLocationMode = "never" PoLocationModeFile PoLocationMode = "file" )
type PoOption ¶
type PoOption func(*PoConfig)
func PoWithAddLocation ¶
func PoWithAddLocation(loc PoLocationMode) PoOption
func PoWithCommentFuzzy ¶
func PoWithConfig ¶
func PoWithCopyrightHolder ¶
func PoWithForcePo ¶
func PoWithForeignUser ¶
func PoWithHeaderComments ¶
func PoWithHeaderFields ¶
func PoWithHighlight ¶ added in v2.4.0
func PoWithHighlight(h *HighlightConfig) PoOption
