git-po-helper is a command-line tool written in Go for checking
conventions for Git localization (l10n) contributions. This project
provides automated checking tools for Git l10n coordinators and
contributors, ensuring that pull requests submitted to
git-l10n/git-po comply with
established contribution conventions.
- Programming Language: Go 1.16+
- CLI Framework: spf13/cobra - For building command-line interfaces
- Configuration Management: spf13/viper - Configuration and flag management
- Logging: sirupsen/logrus - Structured logging
- Other Dependencies:
github.com/gorilla/i18n- Internationalization supportgithub.com/qiniu/iconv- Character encoding conversiongithub.com/mattn/go-isatty- Terminal detectiongithub.com/jiangxin/goconfig- Configuration handling
The project follows a standard Go project structure:
cmd/- CLI subcommand implementations (check-commits, check-po, compare, agent-run, agent-test, msg-cat, msg-select, team, update, version)util/- Core utility functions and business logicdata/- ISO-3166 and ISO-639 language/country code data (generated from CSV)dict/- Spell checking and smudge rules for various languagesgettext/- gettext-related functionalityrepository/- Git repository operations wrapperversion/- Version information managementflag/- Command-line flag handlingcontrib/- Contributing tools and scriptstest/- Integration test suite (using git test-lib framework)
Before compiling git-po-helper, the following dependencies must be
installed:
- Go: Version 1.16 or higher
- git: Git version control system
- gettext: For processing .po files
- iconv: For checking commit log encoding
- gpg: For verifying GPG-signed commits
# Clone the repository
git clone https://github.com/git-l10n/git-po-helper.git
cd git-po-helper
# Build the project
make
# Run tests (including unit tests and integration tests)
make test
# Run unit tests only
make ut
# Run integration tests only
make it
# Run code linting
make lintAfter compilation, copy the binary to a system path:
cp git-po-helper /usr/local/bin/makeormake all- Build thegit-po-helperbinarymake test- Run the complete test suite (including lint, unit tests, and integration tests)make ut- Run unit tests onlymake it- Run integration tests onlymake lint- Run static code analysis (go vet and staticcheck)make clean- Clean build artifacts
The project uses automatically generated version files:
VERSION-FILE- Generated by theVERSION-GENscript- Version information is injected into the binary via
-ldflags
- Go Standard Format: Follow Go's official code formatting standards
- Package Structure:
- The
cmd/package contains all CLI command implementations - The
util/package contains reusable utility functions - Each package has clear responsibility boundaries
- The
- Error Handling: Use custom
commandErrortype to distinguish user errors from system errors - Logging Levels: Support quiet (-q) and verbose (-v) modes, using logrus for structured logging
-
Unit Tests:
- Use Go's standard testing framework
- Test files end with
_test.go - Run command:
make ut
-
Integration Tests:
- Use git test-lib framework (located in
test/lib/) - Test scripts are in the
test/directory - Test cases follow the
t*.shnaming convention - Run command:
make it
- Use git test-lib framework (located in
-
Code Quality Checks:
- Use
go vetfor static analysis - Use
staticcheckfor deeper code inspection - Run command:
make lint
- Use
agent-run- Run agent commands for automation (update-pot, update-po, translate, review, report)agent-test- Test agent commands with multiple runscheck-commits- Check if commits comply with l10n conventionscheck-po- Check syntax of XX.po or XX.pot file (for Git .pot, also checks CamelCase config variables; requires Documentation/config)compare- Show differences between two l10n files (--stat for diff stats, or new/changed entries)msg-cat- Concatenate and merge PO/POT/JSON files (first occurrence of each msgid wins)msg-select- Extract entries from PO/POT file by index rangeteam- Show team leader/member informationupdate- Update XX.po fileversion- Display version information
The project primarily checks the following Git l10n contribution conventions:
- File Location: Only files in the
po/directory are allowed to be modified - Commit Log Format:
- Subject must start with the "l10n:" prefix
- Subject must not contain non-ASCII characters
- Subject length must not exceed 50 characters
- Other lines must not exceed 72 characters
- Must include "Signed-off-by:" signature
- .po File Syntax: Use
msgfmtto verify syntax correctness - Completeness: Ensure all translatable strings are present in po/XX.po
- File Location Cleanup: File location information must be removed before submission
- Spell Checking: Check for common spelling errors (supports multiple languages)
The project includes mechanisms for generating Go code from CSV files:
data/iso-3166.go- Generated fromdata/iso-3166.csvdata/iso-639.go- Generated fromdata/iso-639.csv- Generated using the
go generatecommand
Although the project doesn't have an explicit CONTRIBUTING.md, the following can be inferred from the code structure:
- Commit Standards: Follow the project's commit log format requirements
- Testing Requirements: New features must include corresponding test cases
- Code Review: Automated checks through CI/CD processes (GitHub Actions)
- Backward Compatibility: Maintain compatibility with older versions of gettext
- Specification: Commit messages MUST follow the Conventional Commits Specification.
- Language: Commit messages MUST be written in English.
- Multi-line structure: A good commit message SHOULD contain multiple lines: the first line is the subject, the second line is blank, and the third and subsequent lines contain a detailed description of the change.
- Content focus: The detailed description MUST explain the reasons for the change (why) and include a concise description of what was changed, rather than only describing how the change was implemented (how).
- Inferring reasons: The reasons for the change SHOULD be inferred from the prompts together with the actual code changes.
- Line length: No single line in the commit message SHOULD exceed 72 characters. If a line would be longer, wrap it to the next line without inserting extra blank lines.
- HereDoc usage: When running the
git commitcommand, use a HereDoc to provide the commit message, for example:git commit -F- <<-EOF, and do NOT use multiple-m <message>arguments to build a multi-line commit message, because multiple-m <message>options will insert redundant blank lines into the final commit message.
The project supports configuration through:
- Command-line flags (using Cobra and Viper)
- Environment variables (supported via Viper)
- Configuration files (if Viper configuration files are set up)
- GitHub Actions Integration: Support for running in GitHub Actions environments
- Multi-language Support: Includes spell checking and smudge rules for multiple languages (bg, ca, de, es, fr, it, ko, pt, sv, tr, vi, etc.)
- POT File Handling: Supports automatic download, build, or use of local POT files
- GPG Verification: Optional GPG signature verification feature
This tool is primarily used for:
- Git l10n Coordinators: Automatically check if submitted pull requests comply with conventions
- Git l10n Contributors: Locally check if their contributions meet requirements before submission
- CI/CD Workflows: Integration into automated workflows for continuous checking
- Project Repository: https://github.com/git-l10n/git-po-helper
- Git l10n Repository: https://github.com/git-l10n/git-po
- POT File Source: https://github.com/git-l10n/pot-changes
- Git Project Documentation: https://github.com/git/git/tree/master/po