validate

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractICUArguments

func ExtractICUArguments(s string) []string

ExtractICUArguments returns real argument names, including nested/simple ones. Malformed messages return no arguments; validation reports the parse error.

func ExtractPlaceholders

func ExtractPlaceholders(s string) []string

ExtractPlaceholders returns unique placeholder tokens found in s.

func ExtractPlaceholdersFor added in v0.16.0

func ExtractPlaceholdersFor(ctx context.Context, s string, options Options) ([]string, error)

ExtractPlaceholdersFor uses the same syntax policy as validation, including ICU parsing.

func ExtractTags

func ExtractTags(s string) []string

ExtractTags returns the unique normalized HTML-like tags in s.

func HasBalancedBraces

func HasBalancedBraces(s string) bool

HasBalancedBraces is retained for callers that only need a lexical brace check. Actual message validation uses parseICU, including apostrophe quoting.

func LooksLikeICU

func LooksLikeICU(s string) bool

LooksLikeICU reports whether a message contains an ICU formatted argument.

func MarkdownLinkDestinations

func MarkdownLinkDestinations(s string) []string

MarkdownLinkDestinations returns unique Markdown link destinations in s.

Types

type Issue

type Issue struct {
	Code      string   `json:"code"`
	Message   string   `json:"message"`
	Severity  Severity `json:"severity"`
	Locale    string   `json:"locale,omitzero"`
	Namespace string   `json:"namespace,omitzero"`
	Key       string   `json:"key,omitzero"`
}

Issue describes one validation finding.

type MarkdownLink struct {
	Raw         string `json:"raw"`
	Text        string `json:"text"`
	Destination string `json:"destination"`
}

MarkdownLink represents a Markdown inline link.

func ExtractMarkdownLinks(s string) []MarkdownLink

ExtractMarkdownLinks returns Markdown inline links found in s.

type Options added in v0.16.0

type Options struct {
	MessageFormat string
	Printf        bool
}

Options selects message syntax; printf is always explicitly opt-in.

type Pair

type Pair struct {
	Options      Options `json:"-"`
	SourceLocale string  `json:"sourceLocale,omitzero"`
	Locale       string  `json:"locale,omitzero"`
	Namespace    string  `json:"namespace,omitzero"`
	Key          string  `json:"key,omitzero"`
	Source       string  `json:"source"`
	Target       string  `json:"target"`
}

Pair contains a source string and target translation to validate.

type Result

type Result struct {
	OK       bool    `json:"ok"`
	Issues   []Issue `json:"issues,omitzero"`
	Warnings []Issue `json:"warnings,omitzero"`
}

Result contains validation issues and warnings.

type Service

type Service struct{}

Service validates translated strings.

func NewService

func NewService() *Service

NewService creates a translation validation service.

func (*Service) ValidatePair

func (s *Service) ValidatePair(pair Pair) Result

ValidatePair validates a source and target translation pair.

func (*Service) ValidatePairContext added in v0.16.0

func (s *Service) ValidatePairContext(ctx context.Context, pair Pair) Result

ValidatePairContext validates a pair with cancellation-aware ICU parsing.

func (*Service) ValidateStrings

func (s *Service) ValidateStrings(source string, target string) Result

ValidateStrings validates source and target translation strings.

type Severity

type Severity string

Severity classifies a validation issue as an error or warning.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

Validation severities.

type TagToken

type TagToken struct {
	Raw         string `json:"raw"`
	Name        string `json:"name"`
	Closing     bool   `json:"closing,omitzero"`
	SelfClosing bool   `json:"selfClosing,omitzero"`
	Normalized  string `json:"normalized"`
}

TagToken represents an HTML-like tag found in a translation string.

func ExtractTagTokens

func ExtractTagTokens(s string) []TagToken

ExtractTagTokens returns normalized tag tokens found in s.

Jump to

Keyboard shortcuts

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