maatify / php-i18n
Database-driven internationalization library for structured translation keys, exact language scopes, governance, and MySQL persistence.
Requires
- php: >=8.4.27 <8.5.0 || >=8.5.12 <8.6.0
- ext-mbstring: *
- ext-pdo: *
- ext-pdo_mysql: *
- maatify/exceptions: ^1.1
- maatify/php-persistence: >=1.0.0-rc.1 <=1.0.0-rc.1
- maatify/shared-common: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- php-di/php-di: ^7.1
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^12.0
- psr/container: ^1.1 || ^2.0
Suggests
- php-di/php-di: Required only to use the optional PHP-DI integration (Maatify\I18n\Adapter\PhpDi\I18nBindings). The core I18n runtime does not need it.
- psr/container: Required only together with php-di/php-di for the optional PHP-DI integration.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 00:07:27 UTC
README
Maatify I18n
maatify/php-i18n is a governed, database-driven translation layer for PHP: structured keys, exact-scope translation values in MySQL, fail-soft runtime reads, management reads for admin screens, and operational coverage facts. Language identity stays with the Host: I18n stores an exact, nullable language code and never applies a fallback.
Release Candidate artifact 1.0.0-rc.3 was unpublished at preparation. At preparation, Release Candidate 1.0.0-rc.2 was available on Packagist. No Published Stable release or Stable support line existed at preparation. See Installation.
Key Features
- Governed structured keys: keys use
scope.domain.key_part. The defaultSTRICTpolicy requires an active scope, an active domain and an assignment for key creation, key renames and domain reads. See the governance contract. - Exact language scopes: reads and writes address one exact
language_code(orNULL, the unlocalized scope). No fallback, default or wildcard inside I18n; fallback is Host policy. - Fail-soft reads, fail-hard writes: a runtime miss returns
nullor an empty DTO; a write violating governance throws a typed exception. - Synchronous derived state: per-domain, per-language summary and per-key counters are updated in the same transaction and are rebuildable.
- Package-owned persistence: eight core
maa_i18n_*tables; no foreign key to, and no join with, any Host table. - Shared transaction semantics: transactions, ordering and pagination come from
maatify/php-persistence; an outer transaction on the same connection is joined, never committed or rolled back by I18n. - Container-free Core: plain constructor wiring; an optional PHP-DI adapter is available but never required.
Requirements
composer.json is the source of truth for requirements and dependencies; this table reflects it.
| Requirement | Constraint |
|---|---|
| Composer PHP eligibility | >=8.4.27 <8.5.0 || >=8.5.12 <8.6.0 |
| Verified PHP support | Stable PHP 8.4 and 8.5 within the Composer eligibility range |
| Extensions | ext-mbstring, ext-pdo, ext-pdo_mysql |
maatify/exceptions |
^1.1 |
maatify/php-persistence |
^1.0 (minimum 1.0.0) |
maatify/shared-common |
^1.0 |
| Database | MySQL (InnoDB, utf8mb4); MySQL 8.4 is the version exercised by the package verification |
| Optional | php-di/php-di and psr/container only for the optional PHP-DI adapter (suggest) |
Installation
The exact command below resolves once 1.0.0-rc.3 is published on Packagist. Only I18n requires an explicit RC allowance. Composer resolves the Stable Persistence dependency within ^1.0 while keeping minimum-stability: stable. For the version available at preparation, see the 1.0.0-rc.2 installation guide.
composer require maatify/php-i18n:1.0.0-rc.3@RC
For a fresh installation, create the database objects once from schema/schema.i18n.sql. The file begins with DROP TABLE IF EXISTS for the eight tables, so never apply it over existing I18n data. For an existing RC.1 or RC.2 database, follow the RC.3 upgrade procedure.
Quick Usage
$scopes->create(new CreateScopeCommand('web', 'Website')); $domains->create(new CreateDomainCommand('home', 'Home page')); $assignments->assign('web', 'home'); $keyId = $writer->createKey(new CreateKeyCommand('web', 'home', 'title')); $writer->upsertTranslation(new UpsertTranslationCommand( languageCode: 'en', keyId: $keyId, value: 'Welcome', type: null, )); $richKeyId = $writer->createKey(new CreateKeyCommand('web', 'home', 'rich-copy')); $writer->upsertTranslation(new UpsertTranslationCommand( languageCode: 'en', keyId: $richKeyId, value: '<p>Formatted copy</p>', type: 'client.rich-copy', // A token defined by this consumer; I18n assigns it no behavior. )); $reader->getValue('en', 'web', 'home', 'title'); // 'Welcome' $reader->getValue('ar', 'web', 'home', 'title'); // null: exact miss, no fallback $reader->getTranslation('en', 'web', 'home', 'rich-copy'); // value + nullable type
Complete, runnable wiring: examples/01-core-wiring-and-first-translation.php. Walkthroughs: docs/guides/USAGE_GUIDE.md.
Public Runtime API
An overview only. The complete inventory (signatures, DTO fields, exceptions, sort keys) is I18N_PACKAGE_REFERENCE.md.
| Area | Types |
|---|---|
| Runtime reads (fail-soft) | TranslationReadService (getValue(), getTranslation()), TranslationDomainReadService (getDomainValues(), getDomainTranslations()), value-only and typed consumer DTOs |
| Translation writes | TranslationWriteService (keys, translations, language-code re-key) |
| Governance management | I18nScopeManagementService, I18nDomainManagementService, I18nScopeDomainManagementService |
| Optional key preview | TranslationKeyPreviewService and the optional preview schema |
| Management reads | I18nManagementReadService, I18nScopeReadService, I18nDomainReadService with *Criteria inputs and paginated results |
| Operational reads | I18nOperationalReadService (exact-code counts and coverage) |
| Policy and maintenance | I18nGovernancePolicyService, MissingCounterService, I18nStatsRebuilder |
| Inputs and results | *Command intents, *Criteria queries, *DTO results, LanguageCode, I18nPolicyModeEnum |
| Persistence | repository contracts (Repository\*Interface) and their MySQL implementations |
| Optional integration | Adapter\PhpDi\I18nBindings |
Critical Runtime Behavior
- Exact scope:
getValue('ar', ...)readsaronly.nullreads the unlocalized scope only. A miss never retries elsewhere. - Domain visibility: deactivating a scope or domain leaves stored keys and translations intact. Domain reads return an empty result when they see the inactive scope or domain. A single-key exact read can still return a stored translation.
- Empty is a value: the empty string is an authoritative translation, not a miss.
- Type is opaque metadata: any valid non-null string is an exact consumer-defined token. The Package defines no type vocabulary and does not assign behavior, render or sanitize values.
- Codes are not normalized:
'ar'and'AR'are different; non-null codes must satisfy the technical language-code rules. Whether a code is a real language is Host policy. - Derived state: summary tables are maintained inside the write transaction;
I18nStatsRebuilder::fullRebuild()repairs drift. - No caching, no key deletion, no fallback.
Exception and Error Propagation
Every exception defined by the package implements Maatify\I18n\Exception\I18nExceptionInterface. Writes and identity lookups throw typed exceptions. See the exception catalog.
Single-key reads return null for a missing key, a missing exact translation, or an invalid language code. Domain reads return an empty result when there are no matching translations, the language code is invalid, or the governance policy denies the read.
Storage failures propagate to the caller. During a runtime read, a thrown PDOException or other external throwable propagates unchanged. A PDO failure reported without an exception or a hydration failure, such as a stored ID outside PHP's integer range, raises I18nStorageException. See the storage failure contract.
Security and Trust Boundaries
- Query values are bound parameters; table and column identifiers and sort columns come from constants and a fixed sort whitelist, never from input. Command and criteria inputs are validated for emptiness and length before storage is touched.
- Authorization, authentication, rate limiting and who may call management services are Host concerns.
- Translation values are opaque strings: escaping them for HTML, JSON or any other sink is the consumer's job.
- The schema file is destructive on an existing database (see Installation).
- See SECURITY.md for the vulnerability reporting and support policy.
Examples
Maintained examples cover every material capability and run against a disposable MySQL in CI. See the capability map in the Usage Guide and the examples/ directory.
Schema
schema/schema.i18n.sql is the fresh-install schema authority: maa_i18n_scopes, maa_i18n_domains, maa_i18n_domain_scopes, maa_i18n_keys, maa_i18n_translations, maa_i18n_domain_language_summary (derived), maa_i18n_key_stats (derived), and maa_i18n_language_write_locks (internal). Ownership and semantics: Reference section 8.
Documentation
| Document | Role |
|---|---|
| I18N_PACKAGE_REFERENCE.md | the canonical public, runtime and behavioral contract |
| docs/guides/USAGE_GUIDE.md | integration walkthroughs |
| examples/ | maintained, executable examples |
| CHANGELOG.md | exact release targets and recorded publication dates |
| ARCHITECTURE.md | component boundaries |
| BOOK/INDEX.md | conceptual, deep documentation; never overrides the Reference |
| llms.txt | navigation for AI consumers |
| SECURITY.md | vulnerability reporting and support policy |
| CONTRIBUTING.md | contribution boundaries and local verification |
| CODE_OF_CONDUCT.md | community participation expectations |
Quality Status
| Gate | State |
|---|---|
PHPStan level max (src, tests, examples, consumer harness) |
enforced, zero errors, no baseline, no suppressions |
| Unit suite (no Docker) and real-MySQL Integration suite | enforced on PHP 8.4 and 8.5 |
| Dependency compatibility | latest-compatible and lowest-supported resolutions both verified |
| Consumer Verification Harness | repository-path dependency in an external Composer root, production autoload, real MySQL, two clean runs; published RC dist and presentation results is recorded separately |
| Examples | every example smoke-executed |
| Release artifact verification | Archive verification procedure |
| Composer audit and platform requirements | enforced |
| Release artifact | 1.0.0-rc.3 was unpublished at preparation. See CHANGELOG.md |
Development and Testing
Every CI gate invokes a local command from the standalone repository root, so each can be reproduced locally with the same verification contract. Prerequisites: a PHP version listed under Requirements, Composer, jq for composer check:docs, actionlint on PATH for composer check:workflows, and, for the real-MySQL gates, Docker with Compose v2. composer check:audit needs Composer 2.10 or newer (a verification-time capability, not a consumer requirement). The disposable MySQL is defined once in docker/mysql-integration/compose.yaml and driven by scripts/ci/with-mysql.sh; Integration, examples and the consumer harness all reuse it, with run-scoped temporary credentials and teardown.
composer install
composer verify # canonical Package gates on the currently resolved dependencies
| Gate | Local command | CI job (I18n Package CI) |
|---|---|---|
| Composer validation | composer check:composer |
Quality |
| Platform requirements | composer check:platform |
Quality, Dependencies |
| Strict production autoload | composer check:autoload |
Quality |
| PHP compatibility | composer check:php-constraint checks Composer eligibility, and composer check:php-runtime checks a Stable interpreter |
Quality and PHP matrix jobs |
| PHP syntax | composer check:syntax |
Quality |
| PHPStan max | composer analyse |
Quality, Dependencies |
| PHP-FIG PER Coding Style 3.1 | composer check:style |
Quality, Dependencies |
| Whitespace | composer check:whitespace |
Quality |
| Documentation consistency | composer check:docs |
Quality |
| Unit | composer test:unit |
Unit (PHP 8.4, 8.5), Dependencies |
| Real-MySQL Integration | composer test:integration |
Integration (PHP 8.4, 8.5), Dependencies |
| Examples smoke | composer check:examples |
Examples (PHP 8.4, 8.5) |
| Consumer Verification | composer verify:consumer |
Consumer Verification (PHP 8.4, 8.5) |
| Composer audit | composer check:audit |
Audit |
| Workflow lint | composer check:workflows (actionlint over standalone repository workflows; actionlint must already be available on PATH) |
Workflow Lint |
composer verify runs the canonical Package verification gate set on the dependency versions currently installed or resolved, including Style and Workflow Lint. CI runs latest-compatible and lowest-supported dependency resolutions as separate compatibility modes; neither mode is part of composer verify, and composer verify does not run composer update.
The final aggregate job of the workflow is I18n Package CI Gate.
License
This package is proprietary. Obtain written authorization before use by requesting a free license from Maatify support. Include your organization name, if applicable, and a contact email for license administration, security advisories, and critical update notices. See LICENSE.
Author
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries