l10nkeys

package
v0.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 15 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

Overview

Package l10nkeys extracts localization message key usages from Go source (Localizer.T, Localizer.Plural, Localizer.Format, Catalog.T, Catalog.Plural, Catalog.Format), scenes (*.scene.yaml), screens (*.screen.yaml), cutscenes (*.cutscene.yaml), and data tables (registered or Go struct-tagged `table:"...,textkey"`), and compares them against a project's YAML string tables to report used, missing, and unused keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// DataTables, when non-nil, binds YAML file patterns to Go row types for
	// extracting `textkey` columns from data tables. When nil, Scan falls back
	// to Go AST discovery of struct fields tagged `table:"...,textkey"`.
	DataTables *datatable.Registry
	// TableDir, when non-empty, restricts string table discovery to this
	// slash-separated fs.FS-relative directory while still scanning the entire
	// project for code and asset key usages.
	TableDir string
	// IncludeTests controls whether *_test.go files are scanned (default false).
	IncludeTests bool
}

Options configures Scan.

type Report

type Report struct {
	Tables  []TableFile
	Locales []string
	Usages  []Usage
	Used    []UsedKey
	Missing []Usage
	Unused  []UnusedKey
}

Report is the result of Scan.

func Scan

func Scan(fsys fs.FS, opts Options) (*Report, error)

Scan walks fsys, loads every YAML localization string table, extracts key usages from Go source, scenes, screens, cutscenes, and data tables, and computes used, missing, and unused keys.

type TableFile

type TableFile struct {
	Path   string
	Locale string
	Table  *l10n.StringTable
	Data   []byte
}

TableFile describes one discovered YAML l10n string table.

type UnusedKey

type UnusedKey struct {
	Key   string   `json:"key"`
	Files []string `json:"files"`
}

UnusedKey describes a key defined in string tables that no scanned file uses.

type Usage

type Usage struct {
	Key    string    `json:"key"`
	File   string    `json:"file"`
	Line   int       `json:"line"`
	Column int       `json:"column,omitempty"`
	Kind   UsageKind `json:"kind"`
	Plural bool      `json:"plural,omitempty"`
	Detail string    `json:"detail,omitempty"`
}

Usage is one occurrence of a localization key in Go source or an asset file.

func ScanGoFiles

func ScanGoFiles(fsys fs.FS, files []string) ([]Usage, error)

ScanGoFiles parses the given Go files in fsys and returns all extracted localization key usages sorted by file, line, column, and key.

func ScanSceneFile

func ScanSceneFile(file string, data []byte) []Usage

ScanSceneFile extracts localization key properties from component maps in a *.scene.yaml file (including nested children and instance overrides).

func (Usage) Location

func (u Usage) Location() string

Location returns "file:line" when Line > 0 or "file" otherwise.

type UsageKind

type UsageKind string

UsageKind classifies where a localization key reference was found.

const (
	KindGo        UsageKind = "go"
	KindScreen    UsageKind = "screen"
	KindCutscene  UsageKind = "cutscene"
	KindScene     UsageKind = "scene"
	KindDataTable UsageKind = "datatable"
)

type UsedKey

type UsedKey struct {
	Key    string  `json:"key"`
	Usages []Usage `json:"usages"`
}

UsedKey groups all references to one localization key.

Jump to

Keyboard shortcuts

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