3.3 KiB
Generated
3.3 KiB
Generated
AGENTS.md - gotext Project Guidelines
This document is the source of truth for the gotext project's architecture, conventions, and development workflows. All contributors — human or AI agent — must adhere to these guidelines.
Agent-specific configuration files (e.g., GEMINI.md, CLAUDE.md) should reference this document rather than duplicating its content.
Project Overview
gotext is a GNU Gettext implementation for Go (Golang). It provides a thread-safe, hierarchical translation system that supports PO/MO files, plural forms, and context-aware translations.
Core Architecture
The project follows a hierarchical structure for managing translations:
- Global Package API (
gotext.go): Provides convenient, global functions (e.g.,Get,GetD,GetN) that rely on a sharedglobalConfig. - Locales (
locale.go): Represent a specific language (e.g., "en_US", "es_ES"). ALocalecontainer manages multipleDomains. - Domains (
domain.go): The core translation engine for a specific set of messages. It handles:- Message retrieval (with support for plural forms and
msgctxt). - Header parsing (including plural-form rules).
- Thread-safety via
sync.RWMutex.
- Message retrieval (with support for plural forms and
- Translators (
translator.go): An interface for translation sources.- PO (
po.go): Parsers for human-readable Gettext Portable Object files. - MO (
mo.go): Parsers for binary Gettext Machine Object files.
- PO (
- Plural Forms (
plurals/): A dedicated package for compiling and evaluating GNU Gettext plural form expressions.
CLI Tools
- xgotext (
cli/xgotext/): A tool to scan Go source files, extract translatable strings (matchingGet,GetD, etc.), and generate/update PO files.
Key Files & Symbols
gotext.go:Configure,Get,GetD,GetN.locale.go:Locale,NewLocale,AddDomain.domain.go:Domain,Get,GetN,parseHeaders.translator.go:Translatorinterface.plurals/compiler.go:Compilefunction for plural expressions.
Development Workflows
Branching & PRs
- Feature Branches: All development MUST happen in dedicated feature branches (e.g.,
feature/description-of-change,fix/bug-description,refactor/topic). - Target Branch: All Pull Requests MUST be made against the
masterbranch. - Review Requirement: No direct commits to
masterare allowed. All changes must be reviewed via a PR. - GitHub Integration: If the
ghCLI tool is installed and authenticated, it should be used for managing Pull Requests, Issues, and Reviews. Otherwise, these tasks must be performed manually through the GitHub web interface.
Coding Standards
- Idiomatic Go: Follow standard Go conventions (
gofmt,go vet). - Thread Safety: Ensure all shared state (like in
Domain) is protected by appropriate synchronization primitives. - Testing:
- Every new feature or bug fix must include corresponding tests.
- Use the
fixtures/directory for sample PO/MO files. - Run
go test ./...to ensure no regressions.
Pre-Submit Checklist
Before submitting a Pull Request, verify:
- All existing tests pass:
go test ./... - Code passes static analysis:
go vet ./... - Code is properly formatted:
gofmt - New features or bug fixes include corresponding tests.
- Commit messages are clear and descriptive.