Skip to content

This library permits you to easily create translations for PHP scripts and apps.

License

Notifications You must be signed in to change notification settings

DamienVauchel/php-translator

Repository files navigation

Simple and light PHP translator

Codacy Badge

This library permits you to easily create translations for PHP scripts and apps.

Prerequisites

  • PHP >= 7.3

Install

You can install the package with git clone and composer install in the directory.

Or you can directly use composer :

composer require scoobydam/php-translator

Use

This library is an easy-to-use and light one.

use ScoobyTranslator\Translator\Translator;

$translator = new Translator(__DIR__ . '/translations', 'fr');
$translator->translate('key_to_translate');

This example will search for a fr.php file in the dir you passed the path in the first parameter.
This file might be like following

<?php
// __DIR__/translations/fr.php

$translations = [
    'general' => [
        'key' => 'value',
    ],
];

It needs to define the $translations variable and at least the general context key.

Full documentation

To know all what you can do, you can find full documentation here.

Contributions

You can send PRs if you want to :)

Just, please, follow these conventions.