PHP code example of saeven / zf2-circlical-trans

1. Go to this page and download the library: Download saeven/zf2-circlical-trans 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/ */

    

saeven / zf2-circlical-trans example snippets


public function onBootstrap(MvcEvent $e)
{

    $translator = $e->getApplication()->getServiceManager()->get('translator');
    $translator
        ->setLocale( 'fr_CA' )
        ->setFallbackLocale( 'en_US' );
}

'translator' => [
    
    'translation_file_patterns' => [
        [
            'locale'        => 'en_US',
            'type'          => 'gettext',
            'base_dir'      => __DIR__ . '/../language',
            'pattern'       => '%s/LC_MESSAGES/default.mo',
            'text_domain'   => 'default',
        ],
        [
            'locale'        => 'en_US',
            'type'          => 'gettext',
            'base_dir'      => __DIR__ . '/../language',
            'pattern'       => '%s/LC_MESSAGES/errors.mo',
            'text_domain'   => 'errors',
        ],
    ],
],

/** @var Laminas\I18n\Translator\Translator $tr */
$tr = $sm->get('translator');

$tr->translate( 'Home' );
$tr->translate( 'Sorry', 'errors' );


$num = 422;
sprintf( $tr->translatePlural( "There is one bird", "There are %d birds", 422 ), $num );
sprintf( $tr->translatePlural( "There is one bird", "There are %d birds", 422, 'errors' ), $num );