Çoklu dil kullanan web sitesinde birden fazla dil ve kullanım kolaylığı sunuyor.

v1.1.0 2021-09-27 07:37 UTC

This package is auto-updated.

Last update: 2021-12-27 08:07:22 UTC


PHP Translation

It is a php package that enables multi-language capability very easily. Also, the package accepts formats as array, json and Database.


    composer require ahmetbarut/translation




The directory structure of the language files should be as follows and it should return an array. The location of the directory is not important, but the content is!

  • lang
    • en
      • menu.php / menu.json
    • tr
      • menu.php / menu.json
    • de
      • menu.php / menu.json

Content of PHP File

    return [
    'home' => 'Home',

Content of Json File

        "home": "Home",
        "deneme": "TEST"

Content Of Database Table

You can change the table name as you wish. If the table name is different, you must give the table name to the $table parameter in the constructor of the Translation class.

CREATE TABLE translation (
    id serial PRIMARY KEY,
    key varchar (255),
    value VARCHAR (255),
    language VARCHAR(255)

Use Of

Array Or Json

use ahmetbarut\Translation\Translation;

require "./vendor/autoload.php";

$translation = new Translation(__DIR__ . '/lang', 'array');


The trans function accepts a string and the first word before the period represents the file, and the word after the period is the key to the requested value.

The setLocale method also belongs to the Translation class.


use ahmetbarut\Translation\Translation;

require "./vendor/autoload.php";

try {
    $connect = new PDO('pgsql:host=localhost;dbname=translation;', 'ahmetbarut', "");
}catch (PDOException $th){

$translation = new Translation( format: 'db', connect: $connect, table: 'translation_words');


The trans function does not expect . in this case.