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) String() string
- func (e Entries) Validate() error
- type EntriesOrFile
- type Entry
- func (e Entry) Equal(x Entry) bool
- func (e Entry) FullHash() uint32
- 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 HeaderWithCharset(charset string) HeaderOption
- func HeaderWithConfig(c HeaderConfig) HeaderOption
- func HeaderWithLanguage(lang string) HeaderOption
- func HeaderWithLanguageTeam(team string) HeaderOption
- func HeaderWithLastTranslator(translator string) HeaderOption
- func HeaderWithMediaType(t string) HeaderOption
- func HeaderWithMimeVersion(version string) HeaderOption
- func HeaderWithNplurals(n uint) HeaderOption
- func HeaderWithPORevisionDate(r string) HeaderOption
- func HeaderWithPOTCreationDate(c string) HeaderOption
- func HeaderWithPlural(p string) HeaderOption
- func HeaderWithProjectIDVersion(v string) HeaderOption
- func HeaderWithReportMsgidBugsTo(r string) HeaderOption
- func HeaderWithTemplate(t bool) HeaderOption
- func HeaderWithXGenerator(g string) HeaderOption
- func HeaderWtihContentTransferEncoding(c 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
- func (p PluralEntries) String() string
- type PluralEntry
- type SortMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareEntriesFunc ¶
CompareEntriesFunc compares two slices of entries using the given comparison function.
func CompareEntry ¶
CompareEntry compares two entries based on their obsolescence, fuzzy flag, location, and ID (in that order).
func CompareEntryByFile ¶
CompareEntryByFile compares entries by file paths in their locations.
func CompareEntryByFuzzy ¶
CompareEntryByFuzzy compares entries by their fuzzy flag.
func CompareEntryByID ¶
CompareEntryByID compares entries by their unified ID.
func CompareEntryByLine ¶
CompareEntryByLine compares entries by line numbers in their locations.
func CompareEntryByLocation ¶
CompareEntryByLocation compares entries by their location slices.
func CompareEntryByObsolete ¶
CompareEntryByObsolete compares entries by their obsolescence status.
func CompareEntryByStr ¶
CompareEntryByStr compares entries by their translation strings, including plural forms.
func CompareLocation ¶
CompareLocation compares two locations by file path and then by line number.
func CompareLocationByFile ¶
CompareLocationByFile compares two locations by cleaned file path string.
func CompareLocationByLine ¶
CompareLocationByLine compares two locations by line number.
func CompareLocationsFunc ¶
CompareLocationsFunc compares two slices of locations using the given comparison function.
func ComparePluralEntriesFunc ¶
func ComparePluralEntriesFunc(a, b PluralEntries, cmp Cmp[PluralEntry]) int
ComparePluralEntriesFunc compares two plural entry slices using the provided comparison function.
func ComparePluralEntry ¶
func ComparePluralEntry(a, b PluralEntry) int
ComparePluralEntry compares two plural entries by ID and then by translation string.
func ComparePluralEntryByID ¶
func ComparePluralEntryByID(a, b PluralEntry) int
ComparePluralEntryByID compares two plural entries by their numeric IDs.
func ComparePluralEntryByStr ¶
func ComparePluralEntryByStr(a, b PluralEntry) int
ComparePluralEntryByStr compares two plural entries by their translation strings.
func EntryIDMatchRatio ¶
EntryIDMatchRatio returns the average fuzzy match ratio between the identifiers of two entries. It compares the ID, context (if present), and plural ID (if both are plural entries).
func EntryStrMatchRatio ¶
EntryStrMatchRatio returns the average fuzzy match ratio between the translation strings of two entries, including plural forms if applicable.
Types ¶
type Entries ¶
type Entries []Entry
Entries represents a collection of Entry objects.
func Merge ¶
func Merge(def, ref Entries, options ...MergeOption) Entries
Merge merges def and ref using the default merge configuration, optionally modified by MergeOptions.
func MergeWithConfig ¶
func MergeWithConfig(config MergeConfig, def, ref Entries) Entries
MergeWithConfig merges entries from def and ref using the provided MergeConfig.
If FuzzyMatch is enabled, unmatched entries may be matched based on string similarity. If KeepPreviousIDs is set, original IDs are preserved in unmatched entries. If Sort is enabled, the resulting set is sorted using the given SortMode.
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 // List of flags (e.g., "fuzzy").
Comments []string // Translator comments.
ExtractedComments []string // Automatically extracted comments.
Previous []string // Previous msgid or msgstr lines.
Obsolete bool // Indicates whether the entry is obsolete.
ID string // The original string to be translated.
Context string // Context of the string, if any.
Plural string // The plural form of the original string, if applicable.
Plurals PluralEntries // List of plural translations.
Str string // Translated string (singular).
Locations Locations // List of source code references.
}
Entry represents a single translatable message in a PO file.
It may include context, plural forms, translation string(s), comments, flags, 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) Equal ¶
Equal reports whether two entries are semantically equivalent.
It compares ID, context, translation string, flags, and obsolete status.
func (Entry) FullHash ¶ added in v2.5.0
FullHash returns a hash based on the unified ID including context and plural.
WARNING: This is intended for internal use and is not compatible with gettext's hash.
func (Entry) HasContext ¶
HasContext reports whether the entry has a non-empty context.
func (Entry) Hash ¶ added in v2.3.0
Hash returns a hash based on context and ID.
This is useful for identifying entries with or without plural forms.
func (Entry) IsHeader ¶
IsHeader reports whether the entry is a header (i.e., both ID and context are empty).
func (Entry) String ¶
String returns a formatted representation of the entry for debugging or display.
func (Entry) UnifiedID ¶
UnifiedID returns the unique identifier for the entry formatted for MO files.
This includes the context, msgid, and plural (if any), separated by '\x04' and '\x00' as per gettext MO format.
func (Entry) UnifiedStr ¶
UnifiedStr returns the translation string formatted for MO files.
For plural entries, it joins all plural forms using '\x00'. For singular entries, it returns the Str field.
type File ¶
File represents a PO file with a name and a list of entries.
func (File) Load ¶
Load returns the translation string for the entry with the given ID and context. If no such entry exists, it returns an empty string.
func (File) LoadByUnifiedID ¶
LoadByUnifiedID returns the translation string for the entry with the given unified ID. If no such entry exists, it returns an empty string.
type Header ¶
type Header struct {
Template bool
Fields []HeaderField // A slice storing all registered header fields.
}
Header represents a collection of header fields.
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.
func (*Header) Set ¶
Set updates the value of an existing header field or adds a new field if the key does not exist. Parameters: - key: The name of the header field to update or add. - value: The new value to associate with the key.
func (Header) ToConfig ¶ added in v2.6.0
func (h Header) ToConfig() HeaderConfig
type HeaderConfig ¶
type HeaderConfig struct {
Template bool
ProjectIDVersion string
ReportMsgidBugsTo string
POTCreationDate string
PORevisionDate string
LastTranslator string
LanguageTeam string
Language string
MimeVersion string
MediaType string
Charset string
ContentTransferEncoding string
Nplurals uint
Plural string
XGenerator string
}
func DefaultHeaderConfig ¶
func DefaultHeaderConfig(opts ...HeaderOption) HeaderConfig
func DefaultTemplateHeaderConfig ¶ added in v2.6.0
func DefaultTemplateHeaderConfig(opts ...HeaderOption) HeaderConfig
func HeaderConfigFromOptions ¶
func HeaderConfigFromOptions(options ...HeaderOption) HeaderConfig
func (HeaderConfig) String ¶ added in v2.6.0
func (h HeaderConfig) String() string
func (HeaderConfig) ToHeader ¶
func (cfg HeaderConfig) ToHeader() (h Header)
func (HeaderConfig) Validate ¶ added in v2.6.0
func (h HeaderConfig) Validate() []error
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 HeaderWithCharset ¶ added in v2.6.0
func HeaderWithCharset(charset string) HeaderOption
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 HeaderWithMediaType ¶ added in v2.6.0
func HeaderWithMediaType(t string) HeaderOption
func HeaderWithMimeVersion ¶ added in v2.6.0
func HeaderWithMimeVersion(version string) HeaderOption
func HeaderWithNplurals ¶
func HeaderWithNplurals(n uint) HeaderOption
func HeaderWithPORevisionDate ¶ added in v2.6.0
func HeaderWithPORevisionDate(r string) HeaderOption
func HeaderWithPOTCreationDate ¶ added in v2.6.0
func HeaderWithPOTCreationDate(c string) HeaderOption
func HeaderWithPlural ¶ added in v2.6.0
func HeaderWithPlural(p string) HeaderOption
func HeaderWithProjectIDVersion ¶
func HeaderWithProjectIDVersion(v string) HeaderOption
func HeaderWithReportMsgidBugsTo ¶
func HeaderWithReportMsgidBugsTo(r string) HeaderOption
func HeaderWithTemplate ¶ added in v2.6.0
func HeaderWithTemplate(t bool) HeaderOption
func HeaderWithXGenerator ¶ added in v2.6.0
func HeaderWithXGenerator(g string) HeaderOption
func HeaderWtihContentTransferEncoding ¶ added in v2.6.0
func HeaderWtihContentTransferEncoding(c string) HeaderOption
type MergeConfig ¶
type MergeConfig struct {
FuzzyMatch bool // Enables fuzzy matching of entries.
KeepPreviousIDs bool // Retains original IDs on unmatched entries.
Sort bool // Enables sorting after merge.
SortMode SortMode // Sort order to use if sorting is enabled.
}
MergeConfig specifies options for merging entry sets.
func DefaultMergeConfig ¶
func DefaultMergeConfig(opts ...MergeOption) MergeConfig
DefaultMergeConfig returns a MergeConfig with default values, optionally modified by MergeOptions.
func (*MergeConfig) ApplyOption ¶
func (m *MergeConfig) ApplyOption(opts ...MergeOption)
ApplyOption applies a sequence of MergeOptions to the MergeConfig.
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)
MergeOption modifies a MergeConfig.
func MergeWithFuzzyMatch ¶
func MergeWithFuzzyMatch(f bool) MergeOption
MergeWithFuzzyMatch returns a MergeOption that enables or disables fuzzy matching.
func MergeWithKeepPreviousIDs ¶
func MergeWithKeepPreviousIDs(k bool) MergeOption
MergeWithKeepPreviousIDs returns a MergeOption that enables or disables retention of previous IDs.
func MergeWithMergeConfig ¶
func MergeWithMergeConfig(n MergeConfig) MergeOption
MergeWithMergeConfig returns a MergeOption that replaces the current config.
func MergeWithSort ¶
func MergeWithSort(s bool) MergeOption
MergeWithSort returns a MergeOption that enables or disables sorting.
func MergeWithSortMode ¶
func MergeWithSortMode(sm SortMode) MergeOption
MergeWithSortMode returns a MergeOption that sets the SortMode.
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
func (PluralEntries) String ¶ added in v2.6.0
func (p PluralEntries) String() string
type PluralEntry ¶
func (PluralEntry) Equal ¶
func (p PluralEntry) Equal(p2 PluralEntry) bool
func (PluralEntry) String ¶ added in v2.6.0
func (p PluralEntry) String() string
type SortMode ¶
type SortMode int
SortMode defines the mode used to sort PO entries.
func (SortMode) SortMethod ¶
SortMethod returns a sorting function for the given SortMode.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
The compile package contains structures and functions used to compile Mo/Po files with their respective options
|
The compile package contains structures and functions used to compile Mo/Po files with their respective options |
|
The parse package contains structures and functions for parsing Mo/Po files with the respective options.
|
The parse package contains structures and functions for parsing Mo/Po files with the respective options. |
