This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

An easy-to-use localization library for PHP.

v0.3.1 2016-09-11 09:32 UTC

This package is auto-updated.

Last update: 2021-07-04 03:36:57 UTC


Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Transcribe is an easy-to-use localization library for PHP. The localization source can be file-based (similar to Laravel's Localization) or from a database connection.


Install Transcribe through Composer:

$ composer require rougin/transcribe

Basic Usage

Load a list of texts from a directory


$texts = array();

$texts['language'] = 'linguahe';
$texts['name'] = 'pangalan';
$texts['school'] = 'paaralan';

return $texts;
use Rougin\Transcribe\Source\DirectorySource;
use Rougin\Transcribe\Transcribe;

$source = new DirectorySource(__DIR__ . '/locales');

$transcribe = new Transcribe($source);

Load a list of texts from a database

The contents of the words table:

language text translation
fil_PH name pangalan
fil_PH school paaralan
use Rougin\Transcribe\Source\DirectorySource;
use Rougin\Transcribe\Transcribe;

$pdo = new PDO('mysql:host=localhost;dbname=demo', 'root', '');

$table = array('name' => 'words');

$table['language'] = 'language';
$table['text'] = 'text';
$table['translation'] = 'translation';

$source = new DatabaseSource($pdo, $table);

$transcribe = new Transcribe($source);

Must-have properties of $table

  • name - name of the database table
  • language - language name based from a locale (e.g en_GB)
  • text - a keyword or a text to be translated
  • translation - translation from the based language

Load list of texts from different sources

use Rougin\Transcribe\Source\DatabaseSource;
use Rougin\Transcribe\Source\DirectorySource;
use Rougin\Transcribe\Source\SourceCollection;
use Rougin\Transcribe\Transcribe;

$collection = new SourceCollection;

// "$database" is a DatabaseSource instance
// while "$directory" is a DirectorySource.

$transcribe = new Transcribe($collection);

Getting a text from the vocabulary

// Returns all stored texts
$texts = $transcribe->all();

// Returns translation of 'name' in 'fil_PH' group (e.g "pangalan")
$text = $transcribe->get('');

Adding new source

Just implement it to a SourceInterface.

namespace Rougin\Transcribe\Source;

interface SourceInterface
     * Returns an array of words.
     * @return array
    public function words();


Please see CHANGELOG for more information what has changed recently.


$ composer test



The MIT License (MIT). Please see LICENSE for more information.