state

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentVersion   = 1
	DefaultStatePath = ".i18n-mcp/state.json"
)

State file constants.

Variables

This section is empty.

Functions

func EntryKey

func EntryKey(locale string, namespace string, key string) string

EntryKey returns the stable map key for a state entry.

func SourceHash

func SourceHash(value string) string

SourceHash returns a stable hash for source text.

func TargetHash

func TargetHash(value string) string

TargetHash returns a stable hash for translated target text.

Types

type Entry

type Entry struct {
	Locale             string    `json:"locale"`
	Namespace          string    `json:"namespace"`
	Key                string    `json:"key"`
	SourceHash         string    `json:"sourceHash"`
	TranslatedFromHash string    `json:"translatedFromHash"`
	TargetHash         string    `json:"targetHash,omitzero"`
	Status             Status    `json:"status"`
	Reviewed           bool      `json:"reviewed,omitzero"`
	UpdatedAt          time.Time `json:"updatedAt"`
	UpdatedBy          string    `json:"updatedBy,omitzero"`
}

Entry records translation state for one locale key.

type File

type File struct {
	Version      int              `json:"version"`
	SourceLocale string           `json:"sourceLocale"`
	Entries      map[string]Entry `json:"entries"`
	UpdatedAt    time.Time        `json:"updatedAt"`
}

File is the persisted translation state file.

func EmptyFile

func EmptyFile() File

EmptyFile returns an empty initialized state file.

func NewFile

func NewFile(sourceLocale string, now time.Time) File

NewFile creates an initialized state file.

func (*File) Normalize

func (f *File) Normalize()

Normalize fills missing state file defaults.

type RebuildOptions

type RebuildOptions struct {
	Apply bool `json:"apply"`
}

RebuildOptions configures state rebuild behavior.

type RebuildResult

type RebuildResult struct {
	DryRun            bool             `json:"dryRun"`
	Applied           bool             `json:"applied"`
	StatePath         string           `json:"statePath"`
	SourceLocale      string           `json:"sourceLocale"`
	Entries           int              `json:"entries"`
	Created           int              `json:"created"`
	Updated           int              `json:"updated"`
	Skipped           int              `json:"skipped"`
	Assumptions       []string         `json:"assumptions"`
	InventoryWarnings []locale.Warning `json:"inventoryWarnings,omitzero"`
	PreviewState      File             `json:"previewState"`
}

RebuildResult describes the result of rebuilding state.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages translation state files.

func NewService

func NewService(store *Store, locales *locale.Service) *Service

NewService creates a state service.

func (*Service) Load

func (s *Service) Load(ctx context.Context) (File, error)

Load loads the current translation state file.

func (*Service) Rebuild

func (s *Service) Rebuild(ctx context.Context, opts RebuildOptions) (RebuildResult, error)

Rebuild recreates translation state from current locale files.

func (*Service) Save

func (s *Service) Save(ctx context.Context, file File) error

Save persists the translation state file.

type Status

type Status string

Status records translation state for a tracked key.

const (
	StatusCurrent Status = "current"
	StatusMissing Status = "missing"
	StatusStale   Status = "stale"
	StatusExtra   Status = "extra"
	StatusInvalid Status = "invalid"
	StatusUnknown Status = "unknown"
)

Translation state statuses.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes the translation state file.

func NewStore

func NewStore(guard *fsutil.Guard) *Store

NewStore creates a Store at the default state path.

func NewStoreAt

func NewStoreAt(guard *fsutil.Guard, path string) *Store

NewStoreAt creates a Store at path.

func (*Store) Load

func (s *Store) Load(ctx context.Context) (File, error)

Load reads the state file from disk.

func (*Store) Path

func (s *Store) Path() string

Path returns the configured state file path.

func (*Store) Save

func (s *Store) Save(ctx context.Context, file File) error

Save writes the state file to disk.

Jump to

Keyboard shortcuts

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