# youniwemi/translation-checker architecture

> Architecture diagram of the GitHub repository youniwemi/translation-checker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/youniwemi/translation-checker
- Repository: https://github.com/youniwemi/translation-checker

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Execution
    subgraph "CLI Execution"
        direction TB
        EP["CLI Entrypoint\nbin/check-french"]:::app
        COMPL["Composer Autoloader"]:::external
        CORE["FrenchGuidelinesChecker"]:::core
        PARSER["Parser Module"]:::external
        RuleEngine["Typography Rules Engine"]:::engine
        GlossaryEngine["Glossary Checker Engine"]:::engine
        Fixer["Fixer Module"]:::core
        Reporter["Output/Reporter"]:::core
        ruleFile["french-rules.md"]:::config
        glossaryFile["fr-glossary.csv"]:::config

        EP --> COMPL
        COMPL --> CORE
        CORE --> PARSER
        CORE --> RuleEngine
        CORE --> GlossaryEngine
        RuleEngine -->|"reads"| ruleFile
        GlossaryEngine -->|"reads"| glossaryFile
        CORE --> Reporter
        CORE --> Fixer
        Fixer -->|"writes"| PARSER
    end

    %% Configuration & Tests
    subgraph "Configuration & Tests"
        direction TB
        ComposerJSON["composer.json"]:::config
        PHPUnitConfig["phpunit.xml"]:::config
        PHPStanConfig["phpstan.neon"]:::config
        CSFixerConfig[".php-cs-fixer.dist.php"]:::config
        Tests["FrenchGuidelinesCheckerTest.php"]:::test
        ComposerJSON --> Tests
        ComposerJSON --> PHPUnitConfig
        ComposerJSON --> PHPStanConfig
        ComposerJSON --> CSFixerConfig
    end

    %% CI Pipeline
    subgraph "CI Pipeline"
        direction TB
        CI["GitHub Actions\n(.github/workflows/php.yml)"]:::ci
        CI --> ComposerJSON
        CI --> PHPUnitConfig
        CI --> PHPStanConfig
        CI --> CSFixerConfig
        CI --> Tests
    end

    %% Click Events
    click EP "https://github.com/youniwemi/translation-checker/tree/main/bin/check-french"
    click CORE "https://github.com/youniwemi/translation-checker/blob/main/src/FrenchGuidelinesChecker.php"
    click ComposerJSON "https://github.com/youniwemi/translation-checker/blob/main/composer.json"
    click ruleFile "https://github.com/youniwemi/translation-checker/blob/main/docs/french-rules.md"
    click glossaryFile "https://github.com/youniwemi/translation-checker/blob/main/docs/fr-glossary.csv"
    click Fixer "https://github.com/youniwemi/translation-checker/blob/main/src/FrenchGuidelinesChecker.php"
    click Reporter "https://github.com/youniwemi/translation-checker/blob/main/src/FrenchGuidelinesChecker.php"
    click CI "https://github.com/youniwemi/translation-checker/blob/main/.github/workflows/php.yml"
    click Tests "https://github.com/youniwemi/translation-checker/blob/main/tests/FrenchGuidelinesCheckerTest.php"
    click CSFixerConfig "https://github.com/youniwemi/translation-checker/blob/main/.php-cs-fixer.dist.php"
    click PHPStanConfig "https://github.com/youniwemi/translation-checker/blob/main/phpstan.neon"
    click PHPUnitConfig "https://github.com/youniwemi/translation-checker/blob/main/phpunit.xml"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:1px
    classDef engine fill:#bbf,stroke:#333,stroke-width:1px
    classDef external fill:#bfb,stroke:#333,stroke-width:1px
    classDef config fill:#ffb,stroke:#333,stroke-width:1px
    classDef test fill:#fb8,stroke:#333,stroke-width:1px
    classDef ci fill:#fbf,stroke:#333,stroke-width:1px
    classDef app fill:#afd,stroke:#333,stroke-width:1px
```
