-
-
Notifications
You must be signed in to change notification settings - Fork 2
Installation
Install initphp/translator with Composer, confirm the requirements, and run a
short smoke test before moving on to the Quick Start.
| PHP |
>=8.1 (tested on 8.1, 8.2, 8.3, 8.4) |
| Extensions | None beyond the PHP core |
| Runtime dependencies | None |
Development tools (PHPUnit, PHPStan, PHP-CS-Fixer) live under require-dev and
are not installed when you depend on the package from another project.
composer require initphp/translatorThe classes are autoloaded under the InitPHP\Translator namespace via PSR-4:
{
"autoload": {
"psr-4": {
"InitPHP\\Translator\\": "src/"
}
}
}The package ships two public types plus one exception:
| Type | Purpose |
|---|---|
Translator |
The default concrete implementation (final). |
TranslatorInterface |
The contract — type-hint this in your services. |
TranslatorException |
Thrown on misconfiguration. |
Drop this into a script and run it from the CLI. It creates a tiny language file in a temporary directory, then loads and reads it — exercising the full path from disk to interpolated output:
<?php
require __DIR__ . '/vendor/autoload.php';
use InitPHP\Translator\Translator;
// 1. Create a throwaway language pack.
$dir = sys_get_temp_dir() . '/translator-smoke';
@mkdir($dir);
file_put_contents($dir . '/en.php', "<?php return ['hello' => 'Hello {name}'];");
// 2. Configure the translator and read a key.
$lang = new Translator();
$lang->setDir($dir)->setDefault('en');
echo $lang->translate('hello', null, ['name' => 'Ada']); // Hello AdaIf you see Hello Ada, autoloading, file loading, and interpolation all work.
Every change runs the test matrix against PHP 8.1, 8.2, 8.3 and 8.4 (plus a
lowest-dependency run on 8.1). If you find a regression on a supported version,
please file an issue and
include the version reported by php -v.
- Take the five-minute tour in Quick Start.
- Decide on a layout: File Mode or Directory Mode.
- Learn how a key resolves in Keys & Fallback.
- Upgrading from 0.2? See Migration (0.x → 1.0).
initphp/translator · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Usage
Reference
Practical Guides
Migration & Help