Documentation
¶
Index ¶
- func CompareEntriesFunc(a, b Entries, cmp Cmp[Entry]) int
- func CompareEntry(a, b Entry) int
- func CompareEntryByFile(a, b Entry) int
- func CompareEntryByFuzzy(a, b Entry) int
- func CompareEntryByID(a, b Entry) int
- func CompareEntryByLine(a, b Entry) int
- func CompareEntryByLocation(a, b Entry) int
- func CompareEntryByObsolete(a, b Entry) int
- func CompareEntryByStr(a, b Entry) int
- func CompareLocation(a, b Location) int
- func CompareLocationByFile(a, b Location) int
- func CompareLocationByLine(a, b Location) int
- func CompareLocationsFunc(a, b Locations, cmp Cmp[Location]) int
- func ComparePluralEntriesFunc(a, b PluralEntries, cmp Cmp[PluralEntry]) int
- func ComparePluralEntry(a, b PluralEntry) int
- func ComparePluralEntryByID(a, b PluralEntry) int
- func ComparePluralEntryByStr(a, b PluralEntry) int
- func EntryIDMatchRatio(e1, e2 Entry) int
- func EntryStrMatchRatio(e1, e2 Entry) int
- type Cmp
- type Compiler
- type Entries
- func (e Entries) BestIDRatio(e1 Entry) (best, highestRatio int)
- func (e Entries) BestStrRatio(e1 Entry) (best, highestRatio int)
- func (e Entries) CleanDuplicates() Entries
- func (e Entries) CleanEmpties() Entries
- func (e Entries) CleanFuzzy() Entries
- func (e Entries) CleanObsoletes() Entries
- func (e Entries) ContainsFunc(f func(e Entry) bool) bool
- func (e Entries) ContainsUnifiedID(uid string) bool
- func (e Entries) CutHeader() Entries
- func (e Entries) Equal(e2 Entries) bool
- func (e Entries) FuzzyFind(id, context string) int
- func (e Entries) HasDuplicates() bool
- func (e Entries) Header() (h Header)
- func (e Entries) Index(id, context string) int
- func (e Entries) IndexByUnifiedID(uid string) int
- func (e Entries) IndexFunc(f func(Entry) bool) int
- func (e Entries) IsSorted() bool
- func (e Entries) IsSortedFunc(cmp Cmp[Entry]) bool
- func (e Entries) PrepareSorter(cmp Cmp[Entry]) func() Entries
- func (e Entries) Solve() Entries
- func (e Entries) SolveFunc(merger MergeFunc) Entries
- func (e Entries) Sort() Entries
- func (e Entries) SortFunc(cmp Cmp[Entry]) Entries
- func (e Entries) Validate() error
- type EntriesOrFile
- type Entry
- func (e Entry) Equal(x Entry) bool
- func (e Entry) HasContext() bool
- func (e Entry) Hash() uint32
- func (e Entry) IsFuzzy() bool
- func (e Entry) IsHeader() bool
- func (e Entry) IsPlural() bool
- func (e Entry) String() string
- func (e Entry) UnifiedID() string
- func (e Entry) UnifiedStr() string
- func (e Entry) Validate() error
- type File
- type Header
- type HeaderConfig
- type HeaderField
- type HeaderOption
- func HeaderWithConfig(c HeaderConfig) HeaderOption
- func HeaderWithLanguage(lang string) HeaderOption
- func HeaderWithLanguageTeam(team string) HeaderOption
- func HeaderWithLastTranslator(translator string) HeaderOption
- func HeaderWithNplurals(n uint) HeaderOption
- func HeaderWithProjectIDVersion(v string) HeaderOption
- func HeaderWithReportMsgidBugsTo(r string) HeaderOption
- type Location
- type Locations
- type MergeConfig
- type MergeFunc
- type MergeOption
- type Parser
- type PluralEntries
- func (p PluralEntries) Equal(p2 PluralEntries) bool
- func (p PluralEntries) IsSorted() bool
- func (p PluralEntries) IsSortedFunc(cmp Cmp[PluralEntry]) bool
- func (p PluralEntries) Solve() PluralEntries
- func (p PluralEntries) Sort() PluralEntries
- func (p PluralEntries) SortFunc(cmp Cmp[PluralEntry]) PluralEntries
- type PluralEntry
- type SortMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareEntry ¶
func CompareEntryByFile ¶
func CompareEntryByFuzzy ¶
func CompareEntryByID ¶
func CompareEntryByLine ¶
func CompareEntryByLocation ¶
func CompareEntryByObsolete ¶
func CompareEntryByStr ¶
func CompareLocation ¶
func CompareLocationByFile ¶
func CompareLocationByLine ¶
func ComparePluralEntriesFunc ¶
func ComparePluralEntriesFunc(a, b PluralEntries, cmp Cmp[PluralEntry]) int
func ComparePluralEntry ¶
func ComparePluralEntry(a, b PluralEntry) int
func ComparePluralEntryByID ¶
func ComparePluralEntryByID(a, b PluralEntry) int
func ComparePluralEntryByStr ¶
func ComparePluralEntryByStr(a, b PluralEntry) int
func EntryIDMatchRatio ¶
func EntryStrMatchRatio ¶
Types ¶
type Entries ¶
type Entries []Entry
Entries represents a collection of Entry objects.
func Merge ¶
func Merge(def, ref Entries, options ...MergeOption) Entries
func MergeWithConfig ¶
func MergeWithConfig(config MergeConfig, def, ref Entries) Entries
func (Entries) BestIDRatio ¶
func (Entries) BestStrRatio ¶
func (Entries) CleanDuplicates ¶
CleanDuplicates removes duplicate entries with the same ID and context, merging their locations.
func (Entries) CleanEmpties ¶ added in v2.3.0
func (Entries) CleanFuzzy ¶
func (Entries) CleanObsoletes ¶
func (Entries) ContainsFunc ¶ added in v2.3.0
func (Entries) ContainsUnifiedID ¶
func (Entries) HasDuplicates ¶
func (Entries) IndexByUnifiedID ¶
func (Entries) Solve ¶
Solve is a convenience method that uses the default SolveMerge function to resolve duplicates in Entries. It calls SolveFunc with SolveMerge as the merger function.
func (Entries) SolveFunc ¶
SolveFunc processes a slice of Entries using a provided merging function (merger). It groups entries by a unified identifier (UnifiedID) and merges duplicates using the merger. The result is a cleaned list of Entries with duplicates resolved.
type EntriesOrFile ¶
type Entry ¶
type Entry struct {
Flags []string
Comments []string
ExtractedComments []string
Previous []string
Obsolete bool
ID string // The original string to be translated.
Context string // The context in which the string is used (optional).
Plural string // The plural form of the string (optional).
Plurals PluralEntries
Str string
Locations Locations // A list of source code locations for the string.
}
Entry represents a translatable string, including its context, plural forms, and source code locations.
func SolveMerge ¶
SolveMerge merges two Entry objects based on certain preference criteria. It prefers the Entry with a higher priority according to CompareEntry. It combines the Locations from both entries. Then, it chooses the Str and Plurals fields based on CompareEntryByStr.
func (Entry) HasContext ¶
func (Entry) UnifiedID ¶
Returns the unified msgid, msgid_plural and context according to MO format (CTXT \x04 ID (\x00 PLURAL)...).
func (Entry) UnifiedStr ¶
Returns the msgstr (STR) or plurals (PluralStr1 \x00 PluralStr2 \x00 PluralStr3...) unified according to the MO format.
type File ¶
func (File) LoadByUnifiedID ¶
type Header ¶
type Header struct {
Fields []HeaderField // A slice storing all registered header fields.
}
Header represents a collection of header fields.
func DefaultTemplateHeader ¶
func DefaultTemplateHeader() (h Header)
DefaultTemplateHeader initializes a Header object with commonly used default fields. These fields are typically found in .po files for localization.
func NewHeader ¶
func NewHeader(options ...HeaderOption) Header
func (*Header) Load ¶
Load retrieves the value associated with a given key from the Header object. Parameters: - key: The name of the header field to retrieve. Returns: - The value associated with the key if found; otherwise, an empty string ("").
func (*Header) Register ¶
Register adds a new header field to the Header object if the key does not already exist. Parameters:
- key: The name of the header field to register.
- d: Optional variadic arguments representing the value(s) to associate with the key. If provided, they are concatenated into a single string using fmt.Sprint.
type HeaderConfig ¶
type HeaderConfig struct {
Nplurals uint
ProjectIDVersion string
ReportMsgidBugsTo string
Language string
LanguageTeam string
LastTranslator string
}
func DefaultHeaderConfig ¶
func DefaultHeaderConfig() HeaderConfig
func HeaderConfigFromOptions ¶
func HeaderConfigFromOptions(options ...HeaderOption) HeaderConfig
func (HeaderConfig) ToHeader ¶
func (cfg HeaderConfig) ToHeader() (h Header)
func (HeaderConfig) ToHeaderWithDefaults ¶
func (cfg HeaderConfig) ToHeaderWithDefaults() (h Header)
type HeaderField ¶
type HeaderField struct {
Key string // The name of the header field.
Value string // The value associated with the header field.
}
HeaderField represents a single key-value pair in a header.
type HeaderOption ¶
type HeaderOption func(*HeaderConfig)
func HeaderWithConfig ¶
func HeaderWithConfig(c HeaderConfig) HeaderOption
func HeaderWithLanguage ¶
func HeaderWithLanguage(lang string) HeaderOption
func HeaderWithLanguageTeam ¶
func HeaderWithLanguageTeam(team string) HeaderOption
func HeaderWithLastTranslator ¶
func HeaderWithLastTranslator(translator string) HeaderOption
func HeaderWithNplurals ¶
func HeaderWithNplurals(n uint) HeaderOption
func HeaderWithProjectIDVersion ¶
func HeaderWithProjectIDVersion(v string) HeaderOption
func HeaderWithReportMsgidBugsTo ¶
func HeaderWithReportMsgidBugsTo(r string) HeaderOption
type MergeConfig ¶
func DefaultMergeConfig ¶
func DefaultMergeConfig(opts ...MergeOption) MergeConfig
func (*MergeConfig) ApplyOption ¶
func (m *MergeConfig) ApplyOption(opts ...MergeOption)
type MergeFunc ¶
MergeFunc defines a function type that takes two Entry objects and returns a merged Entry pointer.
func MergeAndMarkObsoleteIfNotPrioritized ¶
MergeAndMarkObsoleteIfNotPrioritized returns a MergeFunc that merges two entries using SolveMerge. If the UnifiedID of the entry is not found in the priorList, the resulting merged entry is marked as obsolete. This is useful for keeping non-prioritized entries while flagging them as deprecated or no longer in use.
func MergeIfInPriorityList ¶
MergeIfInPriorityList returns a MergeFunc that applies SolveMerge only if the entry's UnifiedID is present in the provided list of priority IDs (priorList). If the UnifiedID is not found in the list, the merge is skipped and nil is returned.
func MergeUsingPriorAsBase ¶
MergeUsingPriorAsBase returns a MergeFunc that prefers using the version of the entry from priorList as the base. If a matching UnifiedID is found in priorList, it merges that entry with 'b'. Otherwise, it merges 'a' and 'b' as usual using SolveMerge.
func MergeUsingPriorityOrFallback ¶
MergeUsingPriorityOrFallback returns a MergeFunc that prioritizes the version from priorList if found, otherwise it falls back to SolveMerge.
type MergeOption ¶
type MergeOption func(mc *MergeConfig)
func MergeWithFuzzyMatch ¶
func MergeWithFuzzyMatch(f bool) MergeOption
func MergeWithKeepPreviousIDs ¶
func MergeWithKeepPreviousIDs(k bool) MergeOption
func MergeWithMergeConfig ¶
func MergeWithMergeConfig(n MergeConfig) MergeOption
func MergeWithSort ¶
func MergeWithSort(s bool) MergeOption
func MergeWithSortMode ¶
func MergeWithSortMode(sm SortMode) MergeOption
type PluralEntries ¶
type PluralEntries []PluralEntry
func (PluralEntries) Equal ¶
func (p PluralEntries) Equal(p2 PluralEntries) bool
func (PluralEntries) IsSorted ¶
func (p PluralEntries) IsSorted() bool
func (PluralEntries) IsSortedFunc ¶
func (p PluralEntries) IsSortedFunc(cmp Cmp[PluralEntry]) bool
func (PluralEntries) Solve ¶
func (p PluralEntries) Solve() PluralEntries
func (PluralEntries) Sort ¶
func (p PluralEntries) Sort() PluralEntries
func (PluralEntries) SortFunc ¶
func (p PluralEntries) SortFunc(cmp Cmp[PluralEntry]) PluralEntries
type PluralEntry ¶
func (PluralEntry) Equal ¶
func (p PluralEntry) Equal(p2 PluralEntry) bool
