config

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides project configuration types and helpers for working with lokit.yaml and PO/POT files.

Package config — lokit.yaml configuration file support.

When a lokit.yaml file exists in the project root, lokit uses it as the sole source of truth for translation targets. No auto-detection is performed — every target must be explicitly declared.

Index

Constants

View Source
const LokitFileName = "lokit.yaml"

LokitFileName is the default config file name.

View Source
const TargetTypeAndroid = "android"

TargetTypeAndroid is used for Android strings.xml translation projects.

View Source
const TargetTypeDesktop = "desktop"

TargetTypeDesktop is used for freedesktop .desktop single-file translations.

View Source
const TargetTypeFlutter = "flutter"

TargetTypeFlutter is used for Flutter ARB (Application Resource Bundle) files.

View Source
const TargetTypeGettext = "gettext"

TargetTypeGettext is used for gettext PO projects (shell, python, C source code).

View Source
const TargetTypeI18Next = "i18next"

TargetTypeI18Next is used for flat JSON key-value translation projects.

View Source
const TargetTypeJSKV = "js-kv"

TargetTypeJSKV is used for JS assignment key-value translation files.

View Source
const TargetTypeMarkdown = "markdown"

TargetTypeMarkdown is used for Markdown document translation.

View Source
const TargetTypePo4a = "po4a"

TargetTypePo4a is used for po4a documentation projects.

View Source
const TargetTypePolkit = "polkit"

TargetTypePolkit is used for polkit .policy single-file translations.

View Source
const TargetTypeProperties = "properties"

TargetTypeProperties is used for Java .properties translation files.

View Source
const TargetTypeVueI18n = "vue-i18n"

TargetTypeVueI18n is used for nested JSON translation projects.

View Source
const TargetTypeYAML = "yaml"

TargetTypeYAML is used for YAML translation files (nested, flat, Rails i18n style).

Variables

This section is empty.

Functions

func DetectLanguagesNested added in v0.3.0

func DetectLanguagesNested(poDir string) []string

DetectLanguagesNested finds languages from nested structure (po/lang/*.po).

Types

type ExtractConfig added in v0.9.2

type ExtractConfig struct {
	// Source is the extraction source path or path pattern.
	Source string `yaml:"source,omitempty"`
	// IDField is the field name used as stable item identifier.
	IDField string `yaml:"id_field,omitempty"`
	// Fields lists translatable fields to extract.
	Fields []string `yaml:"fields,omitempty"`
}

ExtractConfig defines structured extraction settings for matrix-like targets.

type LokitFile added in v0.2.0

type LokitFile struct {
	// Languages is the default language list for all targets (can be overridden per target).
	Languages []string `yaml:"languages,omitempty"`
	// SourceLang is the source language code (default "en").
	SourceLang string `yaml:"source_lang,omitempty"`
	// Provider configures default AI provider/model for translate command.
	Provider *ProviderConfig `yaml:"provider,omitempty"`
	// Targets is the list of translation targets.
	Targets []Target `yaml:"targets"`
}

LokitFile is the top-level lokit.yaml structure.

func LoadLokitFile added in v0.2.0

func LoadLokitFile(rootDir string) (*LokitFile, error)

LoadLokitFile loads and validates lokit.yaml from the given directory. Returns nil if no lokit.yaml exists.

func (*LokitFile) AllLanguages added in v0.2.0

func (lf *LokitFile) AllLanguages(projectRoot string) []string

AllLanguages returns the deduplicated union of all target languages.

func (*LokitFile) Resolve added in v0.2.0

func (lf *LokitFile) Resolve(projectRoot string) ([]ResolvedTarget, error)

Resolve converts a LokitFile into a list of ResolvedTargets with absolute paths. It also auto-detects languages from existing files if not specified.

type POStructure

type POStructure string

POStructure indicates how PO files are organized.

const (
	// POStructureFlat: po/en.po, po/ru.po, po/de.po
	POStructureFlat POStructure = "flat"
	// POStructureNested: po/en/*.po, po/ru/*.po, po/de/*.po
	POStructureNested POStructure = "nested"
	// POStructurePo4a: po4a.cfg + po/lang/*.po (for documentation)
	POStructurePo4a POStructure = "po4a"
	// POStructureUnknown: could not determine
	POStructureUnknown POStructure = "unknown"
)

type Project

type Project struct {
	// Root is the absolute path to the project (or target) root directory.
	// Used as the base for computing relative source-file paths in POT
	// references. If empty, the current working directory is used.
	Root string
	// Name is the project/package name.
	Name string
	// Version from debian/changelog or fallback.
	Version string
	// PODir is the directory containing .po files (primary, usually code).
	PODir string
	// POTFile is the path to the .pot template file.
	POTFile string
	// SourceDirs are directories to scan for translatable source files.
	SourceDirs []string
	// Keywords are xgettext keyword functions (e.g. "_", "N_", "gettext").
	// If empty, default keywords are used.
	Keywords []string
	// Languages detected from existing .po files.
	Languages []string
	// BugsEmail for POT header.
	BugsEmail string
	// CopyrightHolder for POT header.
	CopyrightHolder string
	// POStructure indicates how PO files are organized.
	POStructure POStructure
	// Type indicates what kind of translatable content exists.
	Type ProjectType
	// Po4aConfig is the path to po4a.cfg if found.
	Po4aConfig string
	// ManpagesDir is the directory containing manpages if found.
	ManpagesDir string
	// DocsDir is the directory containing documentation if found.
	DocsDir string

	// I18NextDir is the directory containing flat JSON translation files.
	// Typically "public/translations" relative to project root.
	I18NextDir string
	// SourceLang is the source language code (default "en").
	SourceLang string
	// I18NextPathPattern optionally overrides the language file
	// layout relative to I18NextDir. It must contain "{lang}".
	I18NextPathPattern string
	// contains filtered or unexported fields
}

Project holds project configuration used as an internal bridge structure.

func (*Project) I18NextPath

func (p *Project) I18NextPath(lang string) string

I18NextPath returns the path to the i18next JSON file for a given language.

func (*Project) POPath

func (p *Project) POPath(lang string) string

POPath returns the resolved path to the .po file for a given language. Works for flat, nested, and po4a structures.

func (*Project) POTPathResolved

func (p *Project) POTPathResolved() string

POTPathResolved returns the resolved path to the .pot template file. For po4a projects, it searches the pot/ directory.

type ProjectType

type ProjectType string

ProjectType indicates what kind of translatable content exists.

const (
	ProjectTypeI18Next ProjectType = "i18next" // flat JSON translations
)

type ProviderConfig added in v0.8.0

type ProviderConfig struct {
	// ID is the provider identifier.
	ID string `yaml:"id"`
	// Model is the model name.
	Model string `yaml:"model"`
	// BaseURL is an optional custom endpoint URL.
	BaseURL string `yaml:"base_url,omitempty"`
	// Prompt is an optional global prompt override.
	Prompt string `yaml:"prompt,omitempty"`
	// Settings contains optional model-specific settings.
	Settings ProviderSettings `yaml:"settings,omitempty"`
}

ProviderConfig defines default provider settings for translation.

type ProviderSettings added in v0.8.0

type ProviderSettings struct {
	// Temperature controls randomness (0..2).
	Temperature *float64 `yaml:"temperature,omitempty"`
}

ProviderSettings contains optional model-specific tuning values.

type ResolvedTarget added in v0.2.0

type ResolvedTarget struct {
	Target    Target
	AbsRoot   string
	Languages []string
}

ResolvedTarget holds a fully resolved target with absolute paths.

func (*ResolvedTarget) AbsPODir added in v0.2.0

func (rt *ResolvedTarget) AbsPODir() string

AbsPODir returns the absolute PO directory for a gettext target.

func (*ResolvedTarget) AbsPOTFile added in v0.2.0

func (rt *ResolvedTarget) AbsPOTFile() string

AbsPOTFile returns the absolute POT file path for a gettext target.

func (*ResolvedTarget) AbsPo4aConfig added in v0.2.0

func (rt *ResolvedTarget) AbsPo4aConfig() string

AbsPo4aConfig returns the absolute po4a.cfg path for a po4a target.

func (*ResolvedTarget) AbsResDir added in v0.3.0

func (rt *ResolvedTarget) AbsResDir() string

AbsResDir returns the absolute Android res/ directory for android targets.

func (*ResolvedTarget) AbsTranslationsDir added in v0.2.0

func (rt *ResolvedTarget) AbsTranslationsDir() string

AbsTranslationsDir returns the absolute translations directory for file-based targets.

func (*ResolvedTarget) DocsPOPath added in v0.2.0

func (rt *ResolvedTarget) DocsPOPath(lang string) string

DocsPOPath returns the .po file path for a language in a po4a target.

func (*ResolvedTarget) ExistingSourcePath added in v0.8.0

func (rt *ResolvedTarget) ExistingSourcePath() string

ExistingSourcePath returns the first existing source-language path.

func (*ResolvedTarget) ExistingTranslationPath added in v0.8.0

func (rt *ResolvedTarget) ExistingTranslationPath(lang string) string

ExistingTranslationPath returns the first existing path for a language.

func (*ResolvedTarget) POPath added in v0.2.0

func (rt *ResolvedTarget) POPath(lang string) string

POPath returns the .po file path for a language in a gettext target.

func (*ResolvedTarget) SourcePath added in v0.8.0

func (rt *ResolvedTarget) SourcePath() string

SourcePath returns the preferred source-language path.

func (*ResolvedTarget) SourcePathCandidates added in v0.8.0

func (rt *ResolvedTarget) SourcePathCandidates() []string

SourcePathCandidates returns source-language path candidates.

func (*ResolvedTarget) TranslationPath added in v0.8.0

func (rt *ResolvedTarget) TranslationPath(lang string) string

TranslationPath returns the primary absolute path for a language.

func (*ResolvedTarget) TranslationPathCandidates added in v0.8.0

func (rt *ResolvedTarget) TranslationPathCandidates(lang string) []string

TranslationPathCandidates returns absolute path candidates for a language.

type Surface added in v0.9.2

type Surface struct {
	Name string `yaml:"name,omitempty"`

	Format     string `yaml:"format,omitempty"`
	Type       string `yaml:"-"`
	Root       string `yaml:"root,omitempty"`
	Dir        string `yaml:"dir,omitempty"`
	Pattern    string `yaml:"pattern,omitempty"`
	Source     string `yaml:"source,omitempty"`
	TargetPath string `yaml:"target,omitempty"`

	POT      string   `yaml:"pot,omitempty"`
	Sources  []string `yaml:"sources,omitempty"`
	Keywords []string `yaml:"keywords,omitempty"`

	Config string `yaml:"config,omitempty"`

	Languages  []string `yaml:"languages,omitempty"`
	SourceLang string   `yaml:"source_lang,omitempty"`
	Prompt     string   `yaml:"prompt,omitempty"`

	LockedKeys     []string `yaml:"locked_keys,omitempty"`
	IgnoredKeys    []string `yaml:"ignored_keys,omitempty"`
	LockedPatterns []string `yaml:"locked_patterns,omitempty"`

	Extract *ExtractConfig `yaml:"extract,omitempty"`
}

Surface describes one translation surface inside a multi-surface target.

type Target added in v0.2.0

type Target struct {
	// Name is a human-readable label shown in status/logs.
	Name string `yaml:"name"`
	// Format: "gettext", "po4a", "i18next", "vue-i18n", "android", "yaml",
	// "markdown", "properties", "flutter", "js-kv", "desktop", "polkit".
	Format string `yaml:"format"`
	// Type is an internal normalized format field.
	Type string `yaml:"-"`
	// Root is the working directory relative to lokit.yaml (default ".").
	Root string `yaml:"root,omitempty"`
	// Dir is the unified directory option for targets that need a base directory.
	Dir string `yaml:"dir,omitempty"`
	// Pattern is an optional file path template (relative to Dir) for
	// file-per-language targets. It must include "{lang}", e.g.:
	// - "{lang}.json"
	// - "{lang}/common.json"
	// - "locale_{lang}.properties"
	Pattern string `yaml:"pattern,omitempty"`
	// Source is the source file path template relative to Root.
	Source string `yaml:"source,omitempty"`
	// TargetPath is the target file path template relative to Root.
	TargetPath string `yaml:"target,omitempty"`

	// POT is the POT template file name relative to Dir.
	POT string `yaml:"pot,omitempty"`
	// Sources are source files/globs to scan for translatable strings.
	Sources []string `yaml:"sources,omitempty"`
	// Keywords are xgettext keyword options (default "_,N_,gettext,eval_gettext").
	Keywords []string `yaml:"keywords,omitempty"`
	// SourceLang overrides the source language for xgettext.
	SourceLang string `yaml:"source_lang,omitempty"`

	// Config is the path to po4a.cfg relative to Root.
	Config string `yaml:"config,omitempty"`

	// Languages overrides the global language list for this target.
	Languages []string `yaml:"languages,omitempty"`
	// Prompt overrides the system prompt for this target.
	Prompt string `yaml:"prompt,omitempty"`

	// LockedKeys lists keys whose existing translations must not be overwritten.
	// Locked keys are skipped during translation even with --retranslate.
	// Use --force to override locked keys.
	LockedKeys []string `yaml:"locked_keys,omitempty"`
	// IgnoredKeys lists keys that are completely excluded from translation.
	// Ignored keys are never sent to the AI provider.
	IgnoredKeys []string `yaml:"ignored_keys,omitempty"`
	// LockedPatterns lists regex patterns; keys matching any pattern are treated as locked.
	LockedPatterns []string `yaml:"locked_patterns,omitempty"`

	// Surfaces defines multiple translation surfaces under one logical target.
	Surfaces []Surface `yaml:"surfaces,omitempty"`

	Extract *ExtractConfig `yaml:"extract,omitempty"`
}

Target describes a single translation unit.

Jump to

Keyboard shortcuts

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