PHP code example of celema / verba

1. Go to this page and download the library: Download celema/verba 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/ */

    

celema / verba example snippets


__('Save');                                      // simple
__n('one file', '%d files', $count);             // plural
__p('button', 'Open');                           // context
__np('inventory', 'one file', '%d files', $count);
__d('shop', 'Checkout');                         // explicit domain
__dn('shop', 'one order', '%d orders', $count);
__dp('shop', 'button', 'Open');                  // domain + context
__dnp('shop', 'inventory', 'one item', '%d items', $count);

__('Hello :name', ['name' => $user->name]);
__('Found %d results', $count);

use Celema\Verba\Translator;
use Celema\Verba\Verba;

$translator = new Translator('de', [
    'app' => __DIR__ . '/i18n',       // application strings, searched first
    'cosray' => $cosrayDir . '/i18n', // framework strings
]);

Verba::activate($translator);         // wire the global functions
// ... handle the request ...
Verba::deactivate();                  // reset (matters for long-running workers)

$translator = new Translator('es', $domains, ['en', 'de']); // es → en → de → id



declare(strict_types=1);

return [
    'messages' => [
        'Save' => 'Speichern',
        'one file' => ['%d Datei', '%d Dateien'], // plural forms
        'Not translated yet' => null,             // falls back to the id
    ],
    'contexts' => [
        'menu' => ['Open' => 'Öffnen'],
        'state' => ['Open' => 'Offen'],
    ],
    'obsolete' => [
        'Old string' => 'Alter String', // parked by sync, never loaded
    ],
    'obsolete_contexts' => [
        'menu' => ['Old command' => 'Alter Befehl'],
    ],
];

use Celema\Verba\Tool\Domain;
use Celema\Verba\Tool\JavascriptScanner;
use Celema\Verba\Tool\PhpScanner;

$domain = new Domain(
    name: 'app',
    dir: __DIR__ . '/i18n',
    locales: ['en', 'de'],
    scanners: [
        new PhpScanner([__DIR__ . '/src', __DIR__ . '/views']),
        new JavascriptScanner([__DIR__ . '/ui/src']),
    ],
    default: true, // also receives bare __()/__n()/__p()/__np() calls
);

<script id="verba-catalog" type="application/json">
	<?= json_encode($translator->exportMany(['app']), JSON_HEX_TAG) 

use Celema\Verba\Command\StatusCommand;
use Celema\Verba\Command\SyncCommand;

$runner->add([new SyncCommand([$domain]), new StatusCommand([$domain])]);