Documentation
¶
Overview ¶
Package goparse provides tools to parse and process Go source files, extracting translations and handling various configurations.
Index ¶
- Constants
- func FromBytes(b []byte, name string, opts ...Option) (*po.File, error)
- func FromFile(f *os.File, opts ...Option) (*po.File, error)
- func FromFiles(files []*os.File, opts ...Option) (*po.File, error)
- func FromPath(path string, opts ...Option) (*po.File, error)
- func FromPaths(paths []string, opts ...Option) (*po.File, error)
- func FromReader(r io.Reader, name string, opts ...Option) (*po.File, error)
- func FromString(s, name string, opts ...Option) (*po.File, error)
- type Config
- type File
- type Option
- func WithCleanDuplicates(cl bool) Option
- func WithConfig(cfg Config) Option
- func WithCustomHeader(h *po.Header) Option
- func WithExclude(exclude ...string) Option
- func WithExtractAll(e bool) Option
- func WithHeaderConfig(h *po.HeaderConfig) Option
- func WithLogger(l *log.Logger) Option
- func WithNoHeader(h bool) Option
- func WithVerbose(v bool) Option
- type Parser
- func NewParser(path string, options ...Option) (*Parser, error)
- func NewParserFromBytes(b []byte, name string, options ...Option) (*Parser, error)
- func NewParserFromFile(file *os.File, options ...Option) (*Parser, error)
- func NewParserFromFiles(files []*os.File, options ...Option) (*Parser, error)
- func NewParserFromPaths(files []string, options ...Option) (*Parser, error)
- func NewParserFromReader(r io.Reader, name string, options ...Option) (*Parser, error)
- func NewParserFromString(s string, name string, options ...Option) (*Parser, error)
Constants ¶
const ( DefaultPackageName = "gotext" // WantedImport specifies the import path of the "gotext" library // that the parser is looking for in the Go files. WantedImport = `"github.com/leonelquinteros/gotext"` )
Constants.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Exclude []string ExtractAll bool NoHeader bool HeaderConfig *po.HeaderConfig CustomHeader *po.Header Logger *log.Logger Verbose bool CleanDuplicates bool // contains filtered or unexported fields }
func DefaultConfig ¶
func (*Config) ApplyOptions ¶
Overwrite the configuration with the options provided, saving the previous state so that it can be restored later with Config.RestoreLastCfg if desired.
func (*Config) RestoreLastCfg ¶
func (c *Config) RestoreLastCfg()
Restores the configuration state prior to the last Config.ApplyOptions if it exists, otherwise it does nothing.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents the parser of an individual go file, I do it this way to keep track of the location and name of each file.
It does not generate Header, it only extracts the entries according to the configuration.
func NewFileFromPath ¶
NewFileFromPath creates a new File instance by reading content from a file on disk.
type Option ¶
type Option func(c *Config)
func WithCleanDuplicates ¶
func WithConfig ¶
func WithCustomHeader ¶ added in v2.6.0
func WithExclude ¶
func WithExtractAll ¶
func WithHeaderConfig ¶
func WithHeaderConfig(h *po.HeaderConfig) Option
func WithLogger ¶
func WithNoHeader ¶
func WithVerbose ¶
type Parser ¶
type Parser struct { Config Config // Configuration settings for parsing. // contains filtered or unexported fields }
func NewParserFromBytes ¶
NewParserFromBytes creates a Parser from raw byte data after validating the configuration.
func NewParserFromFile ¶
NewParserFromFile creates a Parser from an os.File instance.
func NewParserFromFiles ¶
func NewParserFromPaths ¶
NewParserFromPaths initializes a Parser from a list of file paths.
func NewParserFromReader ¶
NewParserFromReader creates a Parser from an io.Reader, such as a file or memory buffer.