Skip to content

Installation

Muhammet Şafak edited this page Jun 11, 2026 · 1 revision

Installation

Install initphp/translator with Composer, confirm the requirements, and run a short smoke test before moving on to the Quick Start.

Requirements

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.

Install via Composer

composer require initphp/translator

The 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.

Smoke test

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 Ada

If you see Hello Ada, autoloading, file loading, and interpolation all work.

Supported PHP versions in CI

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.

Where to go next

Clone this wiki locally