An easy-to-use localization library for PHP

Retrieves an array of strings in various languages from different sources.

View source code on Github

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:

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

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();