PHP code example of rougin / transcribe

1. Go to this page and download the library: Download rougin/transcribe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rougin / transcribe example snippets

 php
// locales/fil_PH.php

$texts = array();

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

return $texts;
 php
// index.php

use Rougin\Transcribe\Source\FileSource;

// ...

$source = new FileSource;

// Add the directory to the source ----
$source->addPath(__DIR__ . '/locales');
// ------------------------------------
 php
// index.php

use Rougin\Transcribe\Locale;

// ...

/** @var \Rougin\Transcribe\Source\FileSource */
$source = /** ... */;

$locale = new Locale($source);

echo $locale->get('fil_PH.name');
 bash
$ php index.php
pangalan
 php
// index.php

$locale->setDefault('fil_PH');

// No need to specify "fil_PH" ---
echo $locale->get('name');
// -------------------------------
 php
// index.php

use Rougin\Transcribe\Source\PdoSource;

// ...

// Create a PDO instance -----------------
$dsn = 'mysql:host=localhost;dbname=demo';

$pdo = new PDO($dsn, 'root', /** ... */);
// ---------------------------------------

$source = new PdoSource($pdo);

// ...
 php
// index.php

// ...

echo $locale->get('fil_PH.name');
 bash
$ php index.php
pangalan
 php
namespace Rougin\Transcribe\Source;

interface SourceInterface
{
    /**
     * Returns an array of words.
     *
     * @return array<string, array<string, string>>
     */
    public function words();
}
 php
return array(
    'fil_PH' => array(
        'language' => 'linguahe',
        'name' => 'pangalan',
        'school' => 'paaralan',
    ),
);