Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.43 KB

File metadata and controls

47 lines (35 loc) · 1.43 KB

InitPHP Translator — Documentation

InitPHP Translator turns plain PHP language files into a small, dependency-free translation API. You point it at a directory, choose a layout, set a default language, and read keys with translate() — with nested keys, {name} placeholders and automatic fallback to the default language.

Contents

Guide What it covers
Getting started Install, configure, and read your first translation.
File mode One .php file per language.
Directory mode One directory of files per language, addressed as file.key.
Key resolution & fallback The exact order in which a key is resolved.
Placeholders Interpolating {name} markers from a context map.
API reference Every public method, its signature and behaviour.
Exceptions What is thrown, when, and how to handle it.

At a glance

require 'vendor/autoload.php';

use InitPHP\Translator\Translator;

$lang = new Translator();
$lang->setDir(__DIR__ . '/languages/')
    ->setDefault('en');

$lang->change('tr');

echo $lang->translate('welcome', null, ['user' => 'Ada']);
<?php
// languages/tr.php
return [
    'welcome' => 'Hoşgeldin {user}',
];

Requirements

  • PHP 8.1 or newer
  • No runtime dependencies