How youniwemi/translation-checker works
Project type and purpose
• This is a PHP command-line package (CLI tool) whose purpose is to parse PO/MO translation files, enforce French typography rules and glossary consistency, and optionally fix issues.
• It is not a web app or microservices system, but a standalone developer tool integrated via Composer and run in pipelines or manually.
File structure
• bin/check-french: the entrypoint script for the CLI.
• src/FrenchGuidelinesChecker.php: core service implementing parsing, checking, and fixing.
• docs/french-rules.md & docs/fr-glossary.csv: data sources for typography rules and glossary.
• composer.json, phpunit.xml, phpstan.neon, .php-cs-fixer.dist.php: configuration for dependencies, tests, static analysis, and style.
• .github/workflows/php.yml: CI pipeline definition.
README for additional insights
• Lists dependencies: gettext/gettext for PO/MO parsing/generation.
• Describes features (typography rules, translation consistency).
• Highlights CLI options (--fix, --quiet, --no-warnings).
Main components and interactions
a. Components:
• CLI Entrypoint (bin/check-french)
• FrenchGuidelinesChecker service
• Parser module (uses gettext library)
• Typography Rules Engine (reads rules from docs/french-rules.md)
• Glossary Checker Engine (reads terms from docs/fr-glossary.csv)
• Fixer module (applies corrections back to files)
• Output/Reporter (console output of errors & warnings)
• Configuration & Dependency Manager (Composer)
• CI Pipeline (GitHub Actions)
b. Relationships / Data flow:
1. User or CI invokes bin/check-french with file path(s).
2. Entrypoint loads Composer autoloader and instantiates FrenchGuidelinesChecker.
3. Checker loads the PO/MO file via the Parser module (external gettext/gettext lib).
4. Checker invokes Typography Rules Engine and Glossary Checker Engine in sequence (or in parallel), both feeding off the loaded translation data and external rule/glossary files.
5. Engines produce a list of errors and warnings.
6. If --fix is set, Fixer applies corrections to the in-memory model and writes back to file via the Parser module’s writer.
7. Reporter outputs results to STDOUT according to CLI flags.
c. Architectural patterns & design principles:
• Single responsibility: separate modules for parsing, rules checking, fixing, and reporting.
• Plug-in-style engine: new rule sets or glossaries can be added by dropping new config/data files and extending the engine.
• Dependency injection via Composer autoloader.
d. Key technologies & libraries:
• PHP 8+
• gettext/gettext for PO/MO handling
• Composer (dependency management)
• PHPUnit for tests, PHPStan for static analysis, PHP-CS-Fixer for style
• GitHub Actions for CI
Detailed element checklist
• Entry point (CLI script)
• Autoloader / Dependency manager (Composer)
• External library (gettext/gettext)
• Parser component
• Typography Rules Engine
• Glossary Checker Engine
• Fixer component (conditional path)
• Reporter / Output
• Data sources (docs/french-rules.md, docs/fr-glossary.csv)
• CI pipeline (GitHub Actions workflow)