phpnomad / translate
2.0.0
2026-03-31 11:27 UTC
Requires (Dev)
- mockery/mockery: ^1.5
- phpnomad/tests: ^0.1.0 || ^0.3.0
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2026-04-15 00:34:09 UTC
README
phpnomad/translate is the abstract translation contract PHPNomad applications use to localize strings. It defines a TranslationStrategy interface with methods for singular and plural translation, each accepting an optional disambiguation context, plus a few small supporting interfaces for text domain and language signals. Domain and locale resolution lives inside the concrete strategy, so application code can call translate() without knowing which backend is wired in behind it.
Installation
composer require phpnomad/translate
Overview
TranslationStrategydefinestranslate()andtranslatePlural(). Both accept an optional disambiguation context (for example, distinguishing a noun from a verb with the same spelling).HasTextDomainandHasLanguageare thin interfaces for strategies that need a text domain or a language code from their environment.HeaderLanguageProviderreadsHTTP_ACCEPT_LANGUAGEand returns a two-character language code, or null when no header is present.- Concrete backends live in integration packages.
phpnomad/symfony-translation-integrationwires the strategy to Symfony Translation, andphpnomad/gettext-integrationwires it to gettext. - When no translation exists for a given string, the contract is to return the original text unchanged, so missing translations never break call sites.
Documentation
Full documentation lives at phpnomad.com.
License
MIT. See LICENSE.txt.